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; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 36 | import android.compat.Compatibility; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 37 | import android.compat.annotation.ChangeId; |
| 38 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 44 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 45 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.net.Uri; |
| 48 | import android.os.AsyncResult; |
| 49 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 50 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.Bundle; |
| 52 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 53 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.Looper; |
| 55 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 57 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 58 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 59 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 60 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 61 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 62 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 63 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 64 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 66 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 67 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 68 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 69 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 70 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 71 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 72 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 74 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 75 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 76 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 77 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 78 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 79 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 80 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 81 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 82 | import android.telephony.CellIdentityCdma; |
| 83 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 85 | import android.telephony.CellInfoGsm; |
| 86 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 87 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 89 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 90 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 91 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 92 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 93 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 94 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 95 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 97 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 98 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 102 | import android.telephony.SignalStrengthUpdateRequest; |
| 103 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 106 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 108 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 109 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 110 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 111 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 112 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 114 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 115 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 116 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 117 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 118 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 119 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 120 | import android.telephony.gba.GbaAuthRequest; |
| 121 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 122 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 125 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 126 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 133 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 135 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 139 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 140 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 143 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 144 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 145 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 146 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 147 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 191 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 207 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 208 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 209 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 210 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 211 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 212 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 213 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 214 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 217 | import com.android.services.telephony.TelecomAccountRegistry; |
| 218 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 219 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 220 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 222 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.IOException; |
| 224 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 225 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 228 | import java.util.Collection; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 229 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 230 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 231 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 232 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 233 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 234 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 235 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 236 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 237 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 238 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 239 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Implementation of the ITelephony interface. |
| 243 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 244 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 246 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 247 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 248 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 249 | |
| 250 | // Message codes used with mMainThreadHandler |
| 251 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 252 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 253 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 254 | private static final int CMD_OPEN_CHANNEL = 9; |
| 255 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 256 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 257 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 258 | private static final int CMD_NV_READ_ITEM = 13; |
| 259 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 260 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 261 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 262 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 263 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 265 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 266 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 267 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 268 | private static final int CMD_SEND_ENVELOPE = 25; |
| 269 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 270 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 271 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 272 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 273 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 274 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 275 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 276 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 277 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 278 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 279 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 280 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 281 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 282 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 283 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 284 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 285 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 286 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 287 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 288 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 289 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 290 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 291 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 292 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 293 | private static final int CMD_SWITCH_SLOTS = 50; |
| 294 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 295 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 296 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 297 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 298 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 299 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 300 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 301 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 302 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 303 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 304 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 305 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 306 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 307 | private static final int CMD_MODEM_REBOOT = 64; |
| 308 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 309 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 310 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 311 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 312 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 314 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 315 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 316 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 317 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 318 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 319 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 320 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 321 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 322 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 323 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 324 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 325 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 326 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 327 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 328 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 329 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 330 | private static final int CMD_GET_CALL_WAITING = 87; |
| 331 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 332 | private static final int CMD_SET_CALL_WAITING = 89; |
| 333 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 334 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 335 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 336 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 337 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 338 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 339 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 341 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 342 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 343 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 344 | private static final int CMD_SET_SIM_POWER = 101; |
| 345 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 347 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 348 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 349 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 350 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 351 | 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] | 352 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 353 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 354 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 355 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 356 | private static final int CMD_ENABLE_VONR = 113; |
| 357 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 358 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 359 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 361 | // Parameters of select command. |
| 362 | private static final int SELECT_COMMAND = 0xA4; |
| 363 | private static final int SELECT_P1 = 0x04; |
| 364 | private static final int SELECT_P2 = 0; |
| 365 | private static final int SELECT_P3 = 0x10; |
| 366 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | /** The singleton instance. */ |
| 368 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 369 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 371 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 373 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 374 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 376 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 378 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 380 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 381 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 383 | /** User Activity */ |
| 384 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 385 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 386 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 387 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 388 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 389 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 390 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 391 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 392 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 393 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 394 | // String to store multi SIM allowed |
| 395 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 396 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 397 | // The AID of ISD-R. |
| 398 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 399 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 400 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 401 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 402 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 403 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 404 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 405 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 406 | 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] | 407 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 408 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 409 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 410 | */ |
| 411 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 412 | "reset_network_erase_modem_config_enabled"; |
| 413 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 414 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 415 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 416 | /** |
| 417 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 418 | * one ICCID active at the same time. |
| 419 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 420 | * |
| 421 | * @hide |
| 422 | */ |
| 423 | @ChangeId |
| 424 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 425 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 426 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 427 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 428 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 429 | * operation fails. |
| 430 | */ |
| 431 | @ChangeId |
| 432 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 433 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 434 | |
| 435 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 436 | * A request object to use for transmitting data to an ICC. |
| 437 | */ |
| 438 | private static final class IccAPDUArgument { |
| 439 | public int channel, cla, command, p1, p2, p3; |
| 440 | public String data; |
| 441 | |
| 442 | public IccAPDUArgument(int channel, int cla, int command, |
| 443 | int p1, int p2, int p3, String data) { |
| 444 | this.channel = channel; |
| 445 | this.cla = cla; |
| 446 | this.command = command; |
| 447 | this.p1 = p1; |
| 448 | this.p2 = p2; |
| 449 | this.p3 = p3; |
| 450 | this.data = data; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 455 | * A request object to use for transmitting data to an ICC. |
| 456 | */ |
| 457 | private static final class ManualNetworkSelectionArgument { |
| 458 | public OperatorInfo operatorInfo; |
| 459 | public boolean persistSelection; |
| 460 | |
| 461 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 462 | this.operatorInfo = operatorInfo; |
| 463 | this.persistSelection = persistSelection; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 468 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 469 | * request after sending. The main thread will notify the request when it is complete. |
| 470 | */ |
| 471 | private static final class MainThreadRequest { |
| 472 | /** The argument to use for the request */ |
| 473 | public Object argument; |
| 474 | /** The result of the request that is run on the main thread */ |
| 475 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 476 | // The subscriber id that this request applies to. Defaults to |
| 477 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 478 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 480 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 481 | public Phone phone; |
| 482 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 483 | public WorkSource workSource; |
| 484 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | public MainThreadRequest(Object argument) { |
| 486 | this.argument = argument; |
| 487 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 488 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 489 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 490 | this.argument = argument; |
| 491 | if (phone != null) { |
| 492 | this.phone = phone; |
| 493 | } |
| 494 | this.workSource = workSource; |
| 495 | } |
| 496 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 497 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 498 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 499 | if (subId != null) { |
| 500 | this.subId = subId; |
| 501 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 502 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 506 | private static final class IncomingThirdPartyCallArgs { |
| 507 | public final ComponentName component; |
| 508 | public final String callId; |
| 509 | public final String callerDisplayName; |
| 510 | |
| 511 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 512 | String callerDisplayName) { |
| 513 | this.component = component; |
| 514 | this.callId = callId; |
| 515 | this.callerDisplayName = callerDisplayName; |
| 516 | } |
| 517 | } |
| 518 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | /** |
| 520 | * A handler that processes messages on the main thread in the phone process. Since many |
| 521 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 522 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 523 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 524 | * on, which will be notified when the operation completes and will contain the result of the |
| 525 | * request. |
| 526 | * |
| 527 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 528 | * note that request.result must be set to something non-null for the calling thread to |
| 529 | * unblock. |
| 530 | */ |
| 531 | private final class MainThreadHandler extends Handler { |
| 532 | @Override |
| 533 | public void handleMessage(Message msg) { |
| 534 | MainThreadRequest request; |
| 535 | Message onCompleted; |
| 536 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 537 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 539 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | |
| 541 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | case CMD_HANDLE_USSD_REQUEST: { |
| 543 | request = (MainThreadRequest) msg.obj; |
| 544 | final Phone phone = getPhoneFromRequest(request); |
| 545 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 546 | String ussdRequest = ussdObject.first; |
| 547 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 548 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | if (!isUssdApiAllowed(request.subId)) { |
| 550 | // Carrier does not support use of this API, return failure. |
| 551 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 552 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 553 | Bundle returnData = new Bundle(); |
| 554 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 555 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 556 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | request.result = true; |
| 558 | notifyRequester(request); |
| 559 | return; |
| 560 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 561 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | try { |
| 563 | request.result = phone != null |
| 564 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 565 | } catch (CallStateException cse) { |
| 566 | request.result = false; |
| 567 | } |
| 568 | // Wake up the requesting thread |
| 569 | notifyRequester(request); |
| 570 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 573 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 575 | final Phone phone = getPhoneFromRequest(request); |
| 576 | request.result = phone != null ? |
| 577 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 578 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 579 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 587 | uiccPort = getUiccPortFromRequest(request); |
| 588 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 589 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 590 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 594 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 595 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 597 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 599 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | break; |
| 601 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | ar = (AsyncResult) msg.obj; |
| 604 | request = (MainThreadRequest) ar.userObj; |
| 605 | if (ar.exception == null && ar.result != null) { |
| 606 | request.result = ar.result; |
| 607 | } else { |
| 608 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 609 | if (ar.result == null) { |
| 610 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 611 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 613 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } else { |
| 615 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 616 | } |
| 617 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 622 | request = (MainThreadRequest) msg.obj; |
| 623 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | uiccPort = getUiccPortFromRequest(request); |
| 625 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 627 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 631 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 632 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 634 | iccArgument.p3, iccArgument.data, onCompleted); |
| 635 | } |
| 636 | break; |
| 637 | |
| 638 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 639 | ar = (AsyncResult) msg.obj; |
| 640 | request = (MainThreadRequest) ar.userObj; |
| 641 | if (ar.exception == null && ar.result != null) { |
| 642 | request.result = ar.result; |
| 643 | } else { |
| 644 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 645 | if (ar.result == null) { |
| 646 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 647 | } else if (ar.exception instanceof CommandException) { |
| 648 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 649 | ar.exception); |
| 650 | } else { |
| 651 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 652 | } |
| 653 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | break; |
| 656 | |
| 657 | case CMD_EXCHANGE_SIM_IO: |
| 658 | request = (MainThreadRequest) msg.obj; |
| 659 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 660 | uiccPort = getUiccPortFromRequest(request); |
| 661 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | loge("iccExchangeSimIO: No UICC"); |
| 663 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 664 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | } else { |
| 666 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 667 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 668 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 670 | iccArgument.data, onCompleted); |
| 671 | } |
| 672 | break; |
| 673 | |
| 674 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 675 | ar = (AsyncResult) msg.obj; |
| 676 | request = (MainThreadRequest) ar.userObj; |
| 677 | if (ar.exception == null && ar.result != null) { |
| 678 | request.result = ar.result; |
| 679 | } else { |
| 680 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 681 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 682 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | break; |
| 684 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 685 | case CMD_SEND_ENVELOPE: |
| 686 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 687 | uiccPort = getUiccPortFromRequest(request); |
| 688 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 689 | loge("sendEnvelopeWithStatus: No UICC"); |
| 690 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 691 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 692 | } else { |
| 693 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 694 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 695 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 696 | break; |
| 697 | |
| 698 | case EVENT_SEND_ENVELOPE_DONE: |
| 699 | ar = (AsyncResult) msg.obj; |
| 700 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 701 | if (ar.exception == null && ar.result != null) { |
| 702 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 703 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 704 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 705 | if (ar.result == null) { |
| 706 | loge("sendEnvelopeWithStatus: Empty response"); |
| 707 | } else if (ar.exception instanceof CommandException) { |
| 708 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 709 | ar.exception); |
| 710 | } else { |
| 711 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 712 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 713 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 715 | break; |
| 716 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | case CMD_OPEN_CHANNEL: |
| 718 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 719 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 720 | IccLogicalChannelRequest openChannelRequest = |
| 721 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 722 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 724 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 725 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | } else { |
| 728 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 729 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 730 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 732 | break; |
| 733 | |
| 734 | case EVENT_OPEN_CHANNEL_DONE: |
| 735 | ar = (AsyncResult) msg.obj; |
| 736 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 737 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | int[] result = (int[]) ar.result; |
| 740 | int channelId = result[0]; |
| 741 | byte[] selectResponse = null; |
| 742 | if (result.length > 1) { |
| 743 | selectResponse = new byte[result.length - 1]; |
| 744 | for (int i = 1; i < result.length; ++i) { |
| 745 | selectResponse[i - 1] = (byte) result[i]; |
| 746 | } |
| 747 | } |
| 748 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 749 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 750 | |
| 751 | uiccPort = getUiccPortFromRequest(request); |
| 752 | IccLogicalChannelRequest channelRequest = |
| 753 | (IccLogicalChannelRequest) request.argument; |
| 754 | channelRequest.channel = channelId; |
| 755 | uiccPort.onLogicalChannelOpened(channelRequest); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 757 | if (ar.result == null) { |
| 758 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 759 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 760 | if (ar.exception != null) { |
| 761 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 762 | } |
| 763 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 764 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 765 | if (ar.exception instanceof CommandException) { |
| 766 | CommandException.Error error = |
| 767 | ((CommandException) (ar.exception)).getCommandError(); |
| 768 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 769 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 770 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 771 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 775 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 776 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 777 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 778 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case CMD_CLOSE_CHANNEL: |
| 782 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 783 | uiccPort = getUiccPortFromRequest(request); |
| 784 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 785 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 786 | throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | } else { |
| 788 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 789 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 791 | break; |
| 792 | |
| 793 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 794 | ar = (AsyncResult) msg.obj; |
| 795 | request = (MainThreadRequest) ar.userObj; |
| 796 | if (ar.exception == null) { |
| 797 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 798 | uiccPort = getUiccPortFromRequest(request); |
| 799 | final int channelId = (Integer) request.argument; |
| 800 | uiccPort.onLogicalChannelClosed(channelId); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 801 | } else { |
| 802 | request.result = false; |
| 803 | if (ar.exception instanceof CommandException) { |
| 804 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 805 | CommandException.Error error = |
| 806 | ((CommandException) (ar.exception)).getCommandError(); |
| 807 | // before this feature is enabled, this API should only return false if |
| 808 | // the operation fails instead of throwing runtime exception for |
| 809 | // backward-compatibility. |
| 810 | if (Compatibility.isChangeEnabled( |
| 811 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE) |
| 812 | && error == CommandException.Error.INVALID_ARGUMENTS) { |
| 813 | throw new IllegalArgumentException( |
| 814 | "iccCloseLogicalChannel: invalid argument "); |
| 815 | } |
| 816 | } else { |
| 817 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 818 | } |
| 819 | if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) { |
| 820 | throw new IllegalStateException( |
| 821 | "exception from modem to close iccLogical Channel"); |
| 822 | } |
| 823 | } |
| 824 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 825 | break; |
| 826 | |
| 827 | case CMD_NV_READ_ITEM: |
| 828 | request = (MainThreadRequest) msg.obj; |
| 829 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 830 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 831 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | ar = (AsyncResult) msg.obj; |
| 836 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 837 | if (ar.exception == null && ar.result != null) { |
| 838 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 839 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 840 | request.result = ""; |
| 841 | if (ar.result == null) { |
| 842 | loge("nvReadItem: Empty response"); |
| 843 | } else if (ar.exception instanceof CommandException) { |
| 844 | loge("nvReadItem: CommandException: " + |
| 845 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 846 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 847 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } |
| 849 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 850 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | break; |
| 852 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 853 | case CMD_NV_WRITE_ITEM: |
| 854 | request = (MainThreadRequest) msg.obj; |
| 855 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 856 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 857 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 858 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 859 | break; |
| 860 | |
| 861 | case EVENT_NV_WRITE_ITEM_DONE: |
| 862 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 863 | break; |
| 864 | |
| 865 | case CMD_NV_WRITE_CDMA_PRL: |
| 866 | request = (MainThreadRequest) msg.obj; |
| 867 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 868 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 872 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 873 | break; |
| 874 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 875 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 876 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 877 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 878 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 879 | break; |
| 880 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 881 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 882 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 883 | break; |
| 884 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 885 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 886 | request = (MainThreadRequest) msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 888 | request); |
| 889 | Phone phone = getPhoneFromRequest(request); |
| 890 | if (phone != null) { |
| 891 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 892 | } else { |
| 893 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 894 | request.result = false; |
| 895 | notifyRequester(request); |
| 896 | } |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 901 | ar = (AsyncResult) msg.obj; |
| 902 | request = (MainThreadRequest) ar.userObj; |
| 903 | if (ar.exception == null && ar.result != null) { |
| 904 | request.result = ar.result; |
| 905 | } else { |
| 906 | // request.result must be set to something non-null |
| 907 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 908 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 909 | request.result = ar.result; |
| 910 | } else { |
| 911 | request.result = false; |
| 912 | } |
| 913 | if (ar.result == null) { |
| 914 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 915 | } else if (ar.exception instanceof CommandException) { |
| 916 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 917 | + ar.exception); |
| 918 | } else { |
| 919 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 920 | } |
| 921 | } |
| 922 | notifyRequester(request); |
| 923 | break; |
| 924 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 925 | case CMD_IS_VONR_ENABLED: { |
| 926 | request = (MainThreadRequest) msg.obj; |
| 927 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 928 | request); |
| 929 | Phone phone = getPhoneFromRequest(request); |
| 930 | if (phone != null) { |
| 931 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 932 | } else { |
| 933 | loge("isVoNrEnabled: No phone object"); |
| 934 | request.result = false; |
| 935 | notifyRequester(request); |
| 936 | } |
| 937 | break; |
| 938 | } |
| 939 | |
| 940 | case EVENT_IS_VONR_ENABLED_DONE: |
| 941 | ar = (AsyncResult) msg.obj; |
| 942 | request = (MainThreadRequest) ar.userObj; |
| 943 | if (ar.exception == null && ar.result != null) { |
| 944 | request.result = ar.result; |
| 945 | } else { |
| 946 | // request.result must be set to something non-null |
| 947 | // for the calling thread to unblock |
| 948 | if (ar.result != null) { |
| 949 | request.result = ar.result; |
| 950 | } else { |
| 951 | request.result = false; |
| 952 | } |
| 953 | if (ar.result == null) { |
| 954 | loge("isVoNrEnabled: Empty response"); |
| 955 | } else if (ar.exception instanceof CommandException) { |
| 956 | loge("isVoNrEnabled: CommandException: " |
| 957 | + ar.exception); |
| 958 | } else { |
| 959 | loge("isVoNrEnabled: Unknown exception"); |
| 960 | } |
| 961 | } |
| 962 | notifyRequester(request); |
| 963 | break; |
| 964 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 965 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 968 | Phone phone = getPhoneFromRequest(request); |
| 969 | if (phone != null) { |
| 970 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 971 | request.workSource); |
| 972 | } else { |
| 973 | loge("enableNrDualConnectivity: No phone object"); |
| 974 | request.result = |
| 975 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 976 | notifyRequester(request); |
| 977 | } |
| 978 | break; |
| 979 | } |
| 980 | |
| 981 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 982 | ar = (AsyncResult) msg.obj; |
| 983 | request = (MainThreadRequest) ar.userObj; |
| 984 | if (ar.exception == null) { |
| 985 | request.result = |
| 986 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 987 | } else { |
| 988 | request.result = |
| 989 | TelephonyManager |
| 990 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 991 | if (ar.exception instanceof CommandException) { |
| 992 | CommandException.Error error = |
| 993 | ((CommandException) (ar.exception)).getCommandError(); |
| 994 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 995 | request.result = |
| 996 | TelephonyManager |
| 997 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 998 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 999 | request.result = |
| 1000 | TelephonyManager |
| 1001 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1002 | } |
| 1003 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1004 | + ar.exception); |
| 1005 | } else { |
| 1006 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1007 | } |
| 1008 | } |
| 1009 | notifyRequester(request); |
| 1010 | break; |
| 1011 | } |
| 1012 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1013 | case CMD_ENABLE_VONR: { |
| 1014 | request = (MainThreadRequest) msg.obj; |
| 1015 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1016 | Phone phone = getPhoneFromRequest(request); |
| 1017 | if (phone != null) { |
| 1018 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1019 | request.workSource); |
| 1020 | } else { |
| 1021 | loge("setVoNrEnabled: No phone object"); |
| 1022 | request.result = |
| 1023 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1024 | notifyRequester(request); |
| 1025 | } |
| 1026 | break; |
| 1027 | } |
| 1028 | |
| 1029 | case EVENT_ENABLE_VONR_DONE: { |
| 1030 | ar = (AsyncResult) msg.obj; |
| 1031 | request = (MainThreadRequest) ar.userObj; |
| 1032 | if (ar.exception == null) { |
| 1033 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1034 | } else { |
| 1035 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1036 | if (ar.exception instanceof CommandException) { |
| 1037 | CommandException.Error error = |
| 1038 | ((CommandException) (ar.exception)).getCommandError(); |
| 1039 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1040 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1041 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1042 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1043 | } else { |
| 1044 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1045 | } |
| 1046 | loge("setVoNrEnabled" + ": CommandException: " |
| 1047 | + ar.exception); |
| 1048 | } else { |
| 1049 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1050 | } |
| 1051 | } |
| 1052 | notifyRequester(request); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1056 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1057 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1058 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1059 | request); |
| 1060 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1061 | break; |
| 1062 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1063 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1064 | ar = (AsyncResult) msg.obj; |
| 1065 | request = (MainThreadRequest) ar.userObj; |
| 1066 | if (ar.exception == null && ar.result != null) { |
| 1067 | request.result = ar.result; // Integer |
| 1068 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1069 | // request.result must be set to something non-null |
| 1070 | // for the calling thread to unblock |
| 1071 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1072 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1073 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1074 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1075 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1076 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1077 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1078 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1079 | } |
| 1080 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1081 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1082 | break; |
| 1083 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1084 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1085 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1086 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1087 | request); |
| 1088 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1089 | (Pair<Integer, Long>) request.argument; |
| 1090 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1091 | reasonWithNetworkTypes.first, |
| 1092 | reasonWithNetworkTypes.second, |
| 1093 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1094 | break; |
| 1095 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1096 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1097 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1098 | break; |
| 1099 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1100 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1101 | request = (MainThreadRequest)msg.obj; |
| 1102 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1103 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1104 | break; |
| 1105 | |
| 1106 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1107 | ar = (AsyncResult)msg.obj; |
| 1108 | request = (MainThreadRequest)ar.userObj; |
| 1109 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1110 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1111 | break; |
| 1112 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1113 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1114 | request = (MainThreadRequest) msg.obj; |
| 1115 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1116 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1117 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1118 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1119 | break; |
| 1120 | |
| 1121 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1122 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1123 | break; |
| 1124 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1125 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1126 | request = (MainThreadRequest) msg.obj; |
| 1127 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1128 | request); |
| 1129 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1130 | break; |
| 1131 | |
| 1132 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1133 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1134 | break; |
| 1135 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1136 | case CMD_PERFORM_NETWORK_SCAN: |
| 1137 | request = (MainThreadRequest) msg.obj; |
| 1138 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1139 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1140 | break; |
| 1141 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1142 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1143 | request = (MainThreadRequest) msg.obj; |
| 1144 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1145 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1146 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1147 | request.argument; |
| 1148 | int callForwardingReason = args.first; |
| 1149 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1150 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1151 | } |
| 1152 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1153 | ar = (AsyncResult) msg.obj; |
| 1154 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1155 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1156 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1157 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1161 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1162 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1163 | // any service for voice call. |
| 1164 | if ((callForwardInfo.serviceClass |
| 1165 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1166 | callForwardingInfo = new CallForwardingInfo( |
| 1167 | callForwardInfo.status |
| 1168 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1169 | callForwardInfo.reason, |
| 1170 | callForwardInfo.number, |
| 1171 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1172 | break; |
| 1173 | } |
| 1174 | } |
| 1175 | // Didn't find a call forward info for voice call. |
| 1176 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1177 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1178 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1180 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1181 | } else { |
| 1182 | if (ar.result == null) { |
| 1183 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1184 | } |
| 1185 | if (ar.exception != null) { |
| 1186 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1187 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1188 | int errorCode = TelephonyManager |
| 1189 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | if (ar.exception instanceof CommandException) { |
| 1191 | CommandException.Error error = |
| 1192 | ((CommandException) (ar.exception)).getCommandError(); |
| 1193 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1194 | errorCode = TelephonyManager |
| 1195 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1196 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1197 | errorCode = TelephonyManager |
| 1198 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1199 | } |
| 1200 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | request = (MainThreadRequest) msg.obj; |
| 1208 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1212 | request.argument).first; |
| 1213 | request.phone.setCallForwardingOption( |
| 1214 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1215 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | callForwardingInfoToSet.getReason(), |
| 1218 | callForwardingInfoToSet.getNumber(), |
| 1219 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1220 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1221 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | ar = (AsyncResult) msg.obj; |
| 1225 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | Consumer<Integer> callback = |
| 1227 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1228 | request.argument).second; |
| 1229 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1231 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1232 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | if (ar.exception instanceof CommandException) { |
| 1234 | CommandException.Error error = |
| 1235 | ((CommandException) (ar.exception)).getCommandError(); |
| 1236 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1237 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1238 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1239 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1240 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1241 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | callback.accept(errorCode); |
| 1245 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | request = (MainThreadRequest) msg.obj; |
| 1253 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1254 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1255 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | ar = (AsyncResult) msg.obj; |
| 1260 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1263 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1264 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | // Service Class is a bit mask per 3gpp 27.007. |
| 1266 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1267 | if (callForwardResults.length > 1 |
| 1268 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1270 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1272 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | } |
| 1276 | } else { |
| 1277 | if (ar.result == null) { |
| 1278 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1279 | } |
| 1280 | if (ar.exception != null) { |
| 1281 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1282 | } |
| 1283 | if (ar.exception instanceof CommandException) { |
| 1284 | CommandException.Error error = |
| 1285 | ((CommandException) (ar.exception)).getCommandError(); |
| 1286 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1287 | callForwardingStatus = |
| 1288 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1289 | } |
| 1290 | } |
| 1291 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1293 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | request = (MainThreadRequest) msg.obj; |
| 1298 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1300 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | ar = (AsyncResult) msg.obj; |
| 1306 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1308 | Consumer<Integer> callback = |
| 1309 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1310 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | if (ar.exception instanceof CommandException) { |
| 1313 | CommandException.Error error = |
| 1314 | ((CommandException) (ar.exception)).getCommandError(); |
| 1315 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1316 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1317 | } else { |
| 1318 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1319 | } |
| 1320 | } else { |
| 1321 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1322 | } |
| 1323 | } else { |
| 1324 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1325 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1326 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1329 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1330 | ar = (AsyncResult) msg.obj; |
| 1331 | request = (MainThreadRequest) ar.userObj; |
| 1332 | CellNetworkScanResult cellScanResult; |
| 1333 | if (ar.exception == null && ar.result != null) { |
| 1334 | cellScanResult = new CellNetworkScanResult( |
| 1335 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1336 | (List<OperatorInfo>) ar.result); |
| 1337 | } else { |
| 1338 | if (ar.result == null) { |
| 1339 | loge("getCellNetworkScanResults: Empty response"); |
| 1340 | } |
| 1341 | if (ar.exception != null) { |
| 1342 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1343 | } |
| 1344 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1345 | if (ar.exception instanceof CommandException) { |
| 1346 | CommandException.Error error = |
| 1347 | ((CommandException) (ar.exception)).getCommandError(); |
| 1348 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1349 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1350 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1351 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1352 | } |
| 1353 | } |
| 1354 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1355 | } |
| 1356 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1357 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1358 | break; |
| 1359 | |
| 1360 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1361 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1362 | ManualNetworkSelectionArgument selArg = |
| 1363 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1364 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1365 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1366 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1367 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1368 | break; |
| 1369 | |
| 1370 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1371 | ar = (AsyncResult) msg.obj; |
| 1372 | request = (MainThreadRequest) ar.userObj; |
| 1373 | if (ar.exception == null) { |
| 1374 | request.result = true; |
| 1375 | } else { |
| 1376 | request.result = false; |
| 1377 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1378 | } |
| 1379 | notifyRequester(request); |
| 1380 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1383 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1384 | request = (MainThreadRequest) msg.obj; |
| 1385 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1386 | if (defaultPhone != null) { |
| 1387 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1388 | } else { |
| 1389 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1390 | Bundle bundle = new Bundle(); |
| 1391 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1392 | new ModemActivityInfo(0, 0, 0, |
| 1393 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1394 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1395 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1398 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1401 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1402 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1403 | ModemActivityInfo ret = null; |
| 1404 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1405 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1406 | // Update the last modem activity info and the result of the request. |
| 1407 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1408 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1409 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1410 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1411 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1412 | .getTransmitTimeMillis(); |
| 1413 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1414 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1415 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1416 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1417 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1418 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1419 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1420 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1421 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1422 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1423 | info.getReceiveTimeMillis() |
| 1424 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1425 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1426 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1427 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1428 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1429 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1430 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1431 | } else { |
| 1432 | if (ar.result == null) { |
| 1433 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1434 | error = TelephonyManager.ModemActivityInfoException |
| 1435 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1436 | } else if (ar.exception instanceof CommandException) { |
| 1437 | loge("queryModemActivityInfo: CommandException: " + |
| 1438 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1439 | error = TelephonyManager.ModemActivityInfoException |
| 1440 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1441 | } else { |
| 1442 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1443 | error = TelephonyManager.ModemActivityInfoException |
| 1444 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1445 | } |
| 1446 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1447 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1448 | if (ret != null) { |
| 1449 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1450 | } else { |
| 1451 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1452 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1453 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1454 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1455 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1456 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1457 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1458 | case CMD_SET_ALLOWED_CARRIERS: |
| 1459 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1460 | CarrierRestrictionRules argument = |
| 1461 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1462 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1463 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1464 | break; |
| 1465 | |
| 1466 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1467 | ar = (AsyncResult) msg.obj; |
| 1468 | request = (MainThreadRequest) ar.userObj; |
| 1469 | if (ar.exception == null && ar.result != null) { |
| 1470 | request.result = ar.result; |
| 1471 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1472 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1473 | if (ar.exception instanceof CommandException) { |
| 1474 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1475 | CommandException.Error error = |
| 1476 | ((CommandException) (ar.exception)).getCommandError(); |
| 1477 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1478 | request.result = |
| 1479 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1480 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | loge("setAllowedCarriers: Unknown exception"); |
| 1483 | } |
| 1484 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1485 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1486 | break; |
| 1487 | |
| 1488 | case CMD_GET_ALLOWED_CARRIERS: |
| 1489 | request = (MainThreadRequest) msg.obj; |
| 1490 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1491 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | |
| 1494 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1495 | ar = (AsyncResult) msg.obj; |
| 1496 | request = (MainThreadRequest) ar.userObj; |
| 1497 | if (ar.exception == null && ar.result != null) { |
| 1498 | request.result = ar.result; |
| 1499 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1500 | request.result = new IllegalStateException( |
| 1501 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1502 | if (ar.result == null) { |
| 1503 | loge("getAllowedCarriers: Empty response"); |
| 1504 | } else if (ar.exception instanceof CommandException) { |
| 1505 | loge("getAllowedCarriers: CommandException: " + |
| 1506 | ar.exception); |
| 1507 | } else { |
| 1508 | loge("getAllowedCarriers: Unknown exception"); |
| 1509 | } |
| 1510 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1511 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1512 | break; |
| 1513 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1514 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1515 | ar = (AsyncResult) msg.obj; |
| 1516 | request = (MainThreadRequest) ar.userObj; |
| 1517 | if (ar.exception == null && ar.result != null) { |
| 1518 | request.result = ar.result; |
| 1519 | } else { |
| 1520 | request.result = new IllegalArgumentException( |
| 1521 | "Failed to retrieve Forbidden Plmns"); |
| 1522 | if (ar.result == null) { |
| 1523 | loge("getForbiddenPlmns: Empty response"); |
| 1524 | } else { |
| 1525 | loge("getForbiddenPlmns: Unknown exception"); |
| 1526 | } |
| 1527 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1528 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1529 | break; |
| 1530 | |
| 1531 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1532 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1533 | uiccPort = getUiccPortFromRequest(request); |
| 1534 | if (uiccPort == null) { |
| 1535 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1536 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1537 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1538 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1539 | break; |
| 1540 | } |
| 1541 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1542 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1543 | if (uiccApp == null) { |
| 1544 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1545 | + appType); |
| 1546 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1547 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1548 | break; |
| 1549 | } else { |
| 1550 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1551 | + " specified type -- " + appType); |
| 1552 | } |
| 1553 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1554 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1555 | onCompleted); |
| 1556 | break; |
| 1557 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1558 | case CMD_SWITCH_SLOTS: |
| 1559 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1560 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1561 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1562 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1563 | break; |
| 1564 | |
| 1565 | case EVENT_SWITCH_SLOTS_DONE: |
| 1566 | ar = (AsyncResult) msg.obj; |
| 1567 | request = (MainThreadRequest) ar.userObj; |
| 1568 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1569 | notifyRequester(request); |
| 1570 | break; |
| 1571 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1572 | request = (MainThreadRequest) msg.obj; |
| 1573 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1574 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1575 | break; |
| 1576 | |
| 1577 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1578 | ar = (AsyncResult) msg.obj; |
| 1579 | request = (MainThreadRequest) ar.userObj; |
| 1580 | if (ar.exception != null) { |
| 1581 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1582 | } else { |
| 1583 | int mode = ((int[]) ar.result)[0]; |
| 1584 | if (mode == 0) { |
| 1585 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1586 | } else { |
| 1587 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1588 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1589 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1590 | notifyRequester(request); |
| 1591 | break; |
| 1592 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1593 | request = (MainThreadRequest) msg.obj; |
| 1594 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1595 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1596 | break; |
| 1597 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1598 | ar = (AsyncResult) msg.obj; |
| 1599 | request = (MainThreadRequest) ar.userObj; |
| 1600 | if (ar.exception != null) { |
| 1601 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1602 | } else { |
| 1603 | request.result = ((int[]) ar.result)[0]; |
| 1604 | } |
| 1605 | notifyRequester(request); |
| 1606 | break; |
| 1607 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1608 | request = (MainThreadRequest) msg.obj; |
| 1609 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1610 | int mode = (int) request.argument; |
| 1611 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1612 | break; |
| 1613 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1614 | ar = (AsyncResult) msg.obj; |
| 1615 | request = (MainThreadRequest) ar.userObj; |
| 1616 | request.result = ar.exception == null; |
| 1617 | notifyRequester(request); |
| 1618 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1619 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1620 | request = (MainThreadRequest) msg.obj; |
| 1621 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1622 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1623 | break; |
| 1624 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1625 | ar = (AsyncResult) msg.obj; |
| 1626 | request = (MainThreadRequest) ar.userObj; |
| 1627 | if (ar.exception != null) { |
| 1628 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1629 | } else { |
| 1630 | request.result = ((int[]) ar.result)[0]; |
| 1631 | } |
| 1632 | notifyRequester(request); |
| 1633 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1634 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1635 | request = (MainThreadRequest) msg.obj; |
| 1636 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1637 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1638 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1639 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | break; |
| 1641 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1642 | ar = (AsyncResult) msg.obj; |
| 1643 | request = (MainThreadRequest) ar.userObj; |
| 1644 | request.result = ar.exception == null; |
| 1645 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1646 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1647 | case CMD_GET_ALL_CELL_INFO: |
| 1648 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1649 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1650 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1651 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1652 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1653 | ar = (AsyncResult) msg.obj; |
| 1654 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1655 | // If a timeout occurs, the response will be null |
| 1656 | request.result = (ar.exception == null && ar.result != null) |
| 1657 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | synchronized (request) { |
| 1659 | request.notifyAll(); |
| 1660 | } |
| 1661 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1662 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1663 | request = (MainThreadRequest) msg.obj; |
| 1664 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1665 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1666 | break; |
| 1667 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1668 | ar = (AsyncResult) msg.obj; |
| 1669 | request = (MainThreadRequest) ar.userObj; |
| 1670 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1671 | try { |
| 1672 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1673 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1674 | cb.onError( |
| 1675 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1676 | ar.exception.getClass().getName(), |
| 1677 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1678 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1679 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1680 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1681 | } else { |
| 1682 | // use the result as returned |
| 1683 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1684 | } |
| 1685 | } catch (RemoteException re) { |
| 1686 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1687 | } |
| 1688 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1689 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1690 | request = (MainThreadRequest) msg.obj; |
| 1691 | WorkSource ws = (WorkSource) request.argument; |
| 1692 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1693 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1694 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1695 | } |
| 1696 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1697 | ar = (AsyncResult) msg.obj; |
| 1698 | request = (MainThreadRequest) ar.userObj; |
| 1699 | if (ar.exception == null) { |
| 1700 | request.result = ar.result; |
| 1701 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1702 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1703 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1704 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | synchronized (request) { |
| 1708 | request.notifyAll(); |
| 1709 | } |
| 1710 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1711 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1712 | case CMD_MODEM_REBOOT: |
| 1713 | request = (MainThreadRequest) msg.obj; |
| 1714 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1715 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1716 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1717 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1718 | handleNullReturnEvent(msg, "rebootModem"); |
| 1719 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1720 | case CMD_REQUEST_ENABLE_MODEM: |
| 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | boolean enable = (boolean) request.argument; |
| 1723 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1724 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1725 | PhoneConfigurationManager.getInstance() |
| 1726 | .enablePhone(request.phone, enable, onCompleted); |
| 1727 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1728 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1729 | ar = (AsyncResult) msg.obj; |
| 1730 | request = (MainThreadRequest) ar.userObj; |
| 1731 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1732 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1733 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1734 | if ((boolean) request.result) { |
| 1735 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1736 | updateModemStateMetrics(); |
| 1737 | } else { |
| 1738 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1739 | + ar.exception); |
| 1740 | } |
| 1741 | notifyRequester(request); |
| 1742 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1743 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1744 | case CMD_GET_MODEM_STATUS: |
| 1745 | request = (MainThreadRequest) msg.obj; |
| 1746 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1747 | PhoneConfigurationManager.getInstance() |
| 1748 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1749 | break; |
| 1750 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1751 | ar = (AsyncResult) msg.obj; |
| 1752 | request = (MainThreadRequest) ar.userObj; |
| 1753 | int id = request.phone.getPhoneId(); |
| 1754 | if (ar.exception == null && ar.result != null) { |
| 1755 | request.result = ar.result; |
| 1756 | //update the cache as modem status has changed |
| 1757 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1758 | (boolean) request.result); |
| 1759 | } else { |
| 1760 | // Return true if modem status cannot be retrieved. For most cases, |
| 1761 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1762 | // and disable modem are not supported. Modem is always on. |
| 1763 | // TODO: this should be fixed in R to support a third |
| 1764 | // status UNKNOWN b/131631629 |
| 1765 | request.result = true; |
| 1766 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1767 | + ar.exception); |
| 1768 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1769 | notifyRequester(request); |
| 1770 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1771 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1772 | request = (MainThreadRequest) msg.obj; |
| 1773 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1774 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1775 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1776 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1777 | break; |
| 1778 | } |
| 1779 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1780 | ar = (AsyncResult) msg.obj; |
| 1781 | request = (MainThreadRequest) ar.userObj; |
| 1782 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1783 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1784 | args.second.accept(ar.exception == null); |
| 1785 | notifyRequester(request); |
| 1786 | break; |
| 1787 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1788 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1789 | request = (MainThreadRequest) msg.obj; |
| 1790 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1791 | Phone phone = getPhoneFromRequest(request); |
| 1792 | if (phone != null) { |
| 1793 | phone.getSystemSelectionChannels(onCompleted); |
| 1794 | } else { |
| 1795 | loge("getSystemSelectionChannels: No phone object"); |
| 1796 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1797 | notifyRequester(request); |
| 1798 | } |
| 1799 | break; |
| 1800 | } |
| 1801 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1802 | ar = (AsyncResult) msg.obj; |
| 1803 | request = (MainThreadRequest) ar.userObj; |
| 1804 | if (ar.exception == null && ar.result != null) { |
| 1805 | request.result = ar.result; |
| 1806 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1807 | request.result = new IllegalStateException( |
| 1808 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1809 | if (ar.result == null) { |
| 1810 | loge("getSystemSelectionChannels: Empty response"); |
| 1811 | } else { |
| 1812 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1813 | } |
| 1814 | } |
| 1815 | notifyRequester(request); |
| 1816 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1817 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1818 | ar = (AsyncResult) msg.obj; |
| 1819 | request = (MainThreadRequest) ar.userObj; |
| 1820 | if (ar.exception == null && ar.result != null) { |
| 1821 | request.result = ar.result; |
| 1822 | } else { |
| 1823 | request.result = -1; |
| 1824 | loge("Failed to set Forbidden Plmns"); |
| 1825 | if (ar.result == null) { |
| 1826 | loge("setForbidenPlmns: Empty response"); |
| 1827 | } else if (ar.exception != null) { |
| 1828 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1829 | request.result = -1; |
| 1830 | } else { |
| 1831 | loge("setForbiddenPlmns: Unknown exception"); |
| 1832 | } |
| 1833 | } |
| 1834 | notifyRequester(request); |
| 1835 | break; |
| 1836 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1837 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1838 | uiccPort = getUiccPortFromRequest(request); |
| 1839 | if (uiccPort == null) { |
| 1840 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1841 | request.result = -1; |
| 1842 | notifyRequester(request); |
| 1843 | break; |
| 1844 | } |
| 1845 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1846 | (Pair<Integer, List<String>>) request.argument; |
| 1847 | appType = setFplmnsArgs.first; |
| 1848 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1849 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1850 | if (uiccApp == null) { |
| 1851 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1852 | request.result = -1; |
| 1853 | loge("Failed to get UICC App"); |
| 1854 | notifyRequester(request); |
| 1855 | } else { |
| 1856 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1857 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1858 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1859 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1860 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1861 | case CMD_ERASE_MODEM_CONFIG: |
| 1862 | request = (MainThreadRequest) msg.obj; |
| 1863 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1864 | defaultPhone.eraseModemConfig(onCompleted); |
| 1865 | break; |
| 1866 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1867 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1868 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1869 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1870 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1871 | request = (MainThreadRequest) msg.obj; |
| 1872 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1873 | notifyRequester(request); |
| 1874 | break; |
| 1875 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1876 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1877 | request = (MainThreadRequest) msg.obj; |
| 1878 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1879 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1880 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1881 | changed.first, changed.second, onCompleted); |
| 1882 | break; |
| 1883 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1884 | ar = (AsyncResult) msg.obj; |
| 1885 | request = (MainThreadRequest) ar.userObj; |
| 1886 | if (ar.exception == null) { |
| 1887 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1888 | // If the operation is successful, update the PIN storage |
| 1889 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1890 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1891 | UiccController.getInstance().getPinStorage() |
| 1892 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1893 | } else { |
| 1894 | request.result = msg.arg1; |
| 1895 | } |
| 1896 | notifyRequester(request); |
| 1897 | break; |
| 1898 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1899 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1900 | request = (MainThreadRequest) msg.obj; |
| 1901 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1902 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1903 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1904 | enabled.first, enabled.second, onCompleted); |
| 1905 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1906 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1907 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1908 | ar = (AsyncResult) msg.obj; |
| 1909 | request = (MainThreadRequest) ar.userObj; |
| 1910 | if (ar.exception == null) { |
| 1911 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1912 | // If the operation is successful, update the PIN storage |
| 1913 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1914 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1915 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1916 | UiccController.getInstance().getPinStorage() |
| 1917 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1918 | } else { |
| 1919 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1920 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1921 | } else { |
| 1922 | request.result = msg.arg1; |
| 1923 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1924 | |
| 1925 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1926 | notifyRequester(request); |
| 1927 | break; |
| 1928 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1929 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1930 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1931 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1932 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1933 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1934 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1935 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1936 | |
| 1937 | case CMD_SET_DATA_THROTTLING: { |
| 1938 | request = (MainThreadRequest) msg.obj; |
| 1939 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1940 | DataThrottlingRequest dataThrottlingRequest = |
| 1941 | (DataThrottlingRequest) request.argument; |
| 1942 | Phone phone = getPhoneFromRequest(request); |
| 1943 | if (phone != null) { |
| 1944 | phone.setDataThrottling(onCompleted, |
| 1945 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1946 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1947 | } else { |
| 1948 | loge("setDataThrottling: No phone object"); |
| 1949 | request.result = |
| 1950 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1951 | notifyRequester(request); |
| 1952 | } |
| 1953 | |
| 1954 | break; |
| 1955 | } |
| 1956 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1957 | ar = (AsyncResult) msg.obj; |
| 1958 | request = (MainThreadRequest) ar.userObj; |
| 1959 | |
| 1960 | if (ar.exception == null) { |
| 1961 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1962 | } else if (ar.exception instanceof CommandException) { |
| 1963 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1964 | CommandException.Error error = |
| 1965 | ((CommandException) (ar.exception)).getCommandError(); |
| 1966 | |
| 1967 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1968 | request.result = TelephonyManager |
| 1969 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1970 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1971 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1972 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1973 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1974 | } else { |
| 1975 | request.result = |
| 1976 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1977 | } |
| 1978 | } else { |
| 1979 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1980 | } |
| 1981 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1982 | notifyRequester(request); |
| 1983 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1984 | |
| 1985 | case CMD_SET_SIM_POWER: { |
| 1986 | request = (MainThreadRequest) msg.obj; |
| 1987 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | int stateToSet = |
| 1990 | ((Pair<Integer, IIntegerConsumer>) |
| 1991 | request.argument).first; |
| 1992 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1993 | break; |
| 1994 | } |
| 1995 | case EVENT_SET_SIM_POWER_DONE: { |
| 1996 | ar = (AsyncResult) msg.obj; |
| 1997 | request = (MainThreadRequest) ar.userObj; |
| 1998 | IIntegerConsumer callback = |
| 1999 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2000 | if (ar.exception != null) { |
| 2001 | loge("setSimPower exception: " + ar.exception); |
| 2002 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2003 | .RESULT_ERROR_UNKNOWN; |
| 2004 | if (ar.exception instanceof CommandException) { |
| 2005 | CommandException.Error error = |
| 2006 | ((CommandException) (ar.exception)).getCommandError(); |
| 2007 | if (error == CommandException.Error.SIM_ERR) { |
| 2008 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2009 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2010 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2011 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2012 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2013 | } else { |
| 2014 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2015 | } |
| 2016 | } |
| 2017 | try { |
| 2018 | callback.accept(errorCode); |
| 2019 | } catch (RemoteException e) { |
| 2020 | // Ignore if the remote process is no longer available to call back. |
| 2021 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2022 | } |
| 2023 | } else { |
| 2024 | try { |
| 2025 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2026 | } catch (RemoteException e) { |
| 2027 | // Ignore if the remote process is no longer available to call back. |
| 2028 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2029 | } |
| 2030 | } |
| 2031 | break; |
| 2032 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2033 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2034 | request = (MainThreadRequest) msg.obj; |
| 2035 | |
| 2036 | final Phone phone = getPhoneFromRequest(request); |
| 2037 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2038 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2039 | notifyRequester(request); |
| 2040 | break; |
| 2041 | } |
| 2042 | |
| 2043 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2044 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2045 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2046 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2047 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2048 | request.subId, pair.first /*callingUid*/, |
| 2049 | pair.second /*request*/, onCompleted); |
| 2050 | break; |
| 2051 | } |
| 2052 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2053 | ar = (AsyncResult) msg.obj; |
| 2054 | request = (MainThreadRequest) ar.userObj; |
| 2055 | // request.result will be the exception of ar if present, true otherwise. |
| 2056 | // Be cautious not to leave result null which will wait() forever |
| 2057 | request.result = ar.exception != null ? ar.exception : true; |
| 2058 | notifyRequester(request); |
| 2059 | break; |
| 2060 | } |
| 2061 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2062 | request = (MainThreadRequest) msg.obj; |
| 2063 | |
| 2064 | Phone phone = getPhoneFromRequest(request); |
| 2065 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2066 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2067 | notifyRequester(request); |
| 2068 | break; |
| 2069 | } |
| 2070 | |
| 2071 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2072 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2073 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2074 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2075 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2076 | request.subId, pair.first /*callingUid*/, |
| 2077 | pair.second /*request*/, onCompleted); |
| 2078 | break; |
| 2079 | } |
| 2080 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2081 | ar = (AsyncResult) msg.obj; |
| 2082 | request = (MainThreadRequest) ar.userObj; |
| 2083 | request.result = ar.exception != null ? ar.exception : true; |
| 2084 | notifyRequester(request); |
| 2085 | break; |
| 2086 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2087 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2088 | case CMD_GET_SLICING_CONFIG: { |
| 2089 | request = (MainThreadRequest) msg.obj; |
| 2090 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2091 | request.phone.getSlicingConfig(onCompleted); |
| 2092 | break; |
| 2093 | } |
| 2094 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2095 | ar = (AsyncResult) msg.obj; |
| 2096 | request = (MainThreadRequest) ar.userObj; |
| 2097 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2098 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2099 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2100 | Bundle bundle = new Bundle(); |
| 2101 | int resultCode = 0; |
| 2102 | if (ar.exception != null) { |
| 2103 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2104 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2105 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2106 | } else if (ar.result == null) { |
| 2107 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2108 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2109 | } else { |
| 2110 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2111 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2112 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2116 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2117 | } |
| 2118 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2119 | result.send(resultCode, bundle); |
| 2120 | notifyRequester(request); |
| 2121 | break; |
| 2122 | } |
| 2123 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2124 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2125 | request = (MainThreadRequest) msg.obj; |
| 2126 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2127 | UiccController.getInstance().getPinStorage() |
| 2128 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2129 | notifyRequester(request); |
| 2130 | break; |
| 2131 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | default: |
| 2133 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2134 | break; |
| 2135 | } |
| 2136 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2137 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2138 | private void notifyRequester(MainThreadRequest request) { |
| 2139 | synchronized (request) { |
| 2140 | request.notifyAll(); |
| 2141 | } |
| 2142 | } |
| 2143 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2144 | private void handleNullReturnEvent(Message msg, String command) { |
| 2145 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2146 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2147 | if (ar.exception == null) { |
| 2148 | request.result = true; |
| 2149 | } else { |
| 2150 | request.result = false; |
| 2151 | if (ar.exception instanceof CommandException) { |
| 2152 | loge(command + ": CommandException: " + ar.exception); |
| 2153 | } else { |
| 2154 | loge(command + ": Unknown exception"); |
| 2155 | } |
| 2156 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2157 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /** |
| 2162 | * Posts the specified command to be executed on the main thread, |
| 2163 | * waits for the request to complete, and returns the result. |
| 2164 | * @see #sendRequestAsync |
| 2165 | */ |
| 2166 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2167 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2168 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | /** |
| 2172 | * Posts the specified command to be executed on the main thread, |
| 2173 | * waits for the request to complete, and returns the result. |
| 2174 | * @see #sendRequestAsync |
| 2175 | */ |
| 2176 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2177 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2178 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
| 2181 | /** |
| 2182 | * Posts the specified command to be executed on the main thread, |
| 2183 | * waits for the request to complete, and returns the result. |
| 2184 | * @see #sendRequestAsync |
| 2185 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2186 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2187 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2188 | } |
| 2189 | |
| 2190 | /** |
| 2191 | * Posts the specified command to be executed on the main thread, |
| 2192 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2193 | * if not timeout or null otherwise. |
| 2194 | * @see #sendRequestAsync |
| 2195 | */ |
| 2196 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2197 | long timeoutInMs) { |
| 2198 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * Posts the specified command to be executed on the main thread, |
| 2203 | * waits for the request to complete, and returns the result. |
| 2204 | * @see #sendRequestAsync |
| 2205 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2206 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2207 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | /** |
| 2211 | * Posts the specified command to be executed on the main thread, |
| 2212 | * waits for the request to complete, and returns the result. |
| 2213 | * @see #sendRequestAsync |
| 2214 | */ |
| 2215 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2216 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2217 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2221 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2222 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2223 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2224 | * @see #sendRequestAsync |
| 2225 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2226 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2227 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2229 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2230 | } |
| 2231 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2232 | MainThreadRequest request = null; |
| 2233 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2234 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2235 | } else if (phone != null) { |
| 2236 | request = new MainThreadRequest(argument, phone, workSource); |
| 2237 | } else { |
| 2238 | request = new MainThreadRequest(argument, subId, workSource); |
| 2239 | } |
| 2240 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2242 | msg.sendToTarget(); |
| 2243 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2244 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2246 | if (timeoutInMs >= 0) { |
| 2247 | // Wait for at least timeoutInMs before returning null request result |
| 2248 | long now = SystemClock.elapsedRealtime(); |
| 2249 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2250 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2251 | try { |
| 2252 | request.wait(deadline - now); |
| 2253 | } catch (InterruptedException e) { |
| 2254 | // Do nothing, go back and check if request is completed or timeout |
| 2255 | } finally { |
| 2256 | now = SystemClock.elapsedRealtime(); |
| 2257 | } |
| 2258 | } |
| 2259 | } else { |
| 2260 | // Wait for the request to complete |
| 2261 | while (request.result == null) { |
| 2262 | try { |
| 2263 | request.wait(); |
| 2264 | } catch (InterruptedException e) { |
| 2265 | // Do nothing, go back and wait until the request is complete |
| 2266 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2270 | if (request.result == null) { |
| 2271 | Log.wtf(LOG_TAG, |
| 2272 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2273 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | return request.result; |
| 2275 | } |
| 2276 | |
| 2277 | /** |
| 2278 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2279 | * Posts the specified command to be executed on the main thread, and |
| 2280 | * returns immediately. |
| 2281 | * @see #sendRequest |
| 2282 | */ |
| 2283 | private void sendRequestAsync(int command) { |
| 2284 | mMainThreadHandler.sendEmptyMessage(command); |
| 2285 | } |
| 2286 | |
| 2287 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2288 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2289 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2290 | */ |
| 2291 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2292 | sendRequestAsync(command, argument, null, null); |
| 2293 | } |
| 2294 | |
| 2295 | /** |
| 2296 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2297 | * @see {@link #sendRequest(int,Object)} |
| 2298 | */ |
| 2299 | private void sendRequestAsync( |
| 2300 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2301 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2302 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2303 | msg.sendToTarget(); |
| 2304 | } |
| 2305 | |
| 2306 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2308 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2309 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2310 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | synchronized (PhoneInterfaceManager.class) { |
| 2312 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2313 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | } else { |
| 2315 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2316 | } |
| 2317 | return sInstance; |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2322 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2324 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2325 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2326 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2328 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2330 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2331 | mTelephonySharedPreferences = |
| 2332 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2333 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2334 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2335 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2336 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2337 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | publish(); |
| 2339 | } |
| 2340 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2341 | private Phone getDefaultPhone() { |
| 2342 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2343 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2344 | } |
| 2345 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2346 | private void publish() { |
| 2347 | if (DBG) log("publish: " + this); |
| 2348 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2349 | TelephonyFrameworkInitializer |
| 2350 | .getTelephonyServiceManager() |
| 2351 | .getTelephonyServiceRegisterer() |
| 2352 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2355 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2356 | if (request.phone != null) { |
| 2357 | return request.phone; |
| 2358 | } else { |
| 2359 | return getPhoneFromSubId(request.subId); |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | private Phone getPhoneFromSubId(int subId) { |
| 2364 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2365 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2366 | } |
| 2367 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2368 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2369 | Phone phone = getPhoneFromRequest(request); |
| 2370 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2371 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2372 | } |
| 2373 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2374 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2375 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2376 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2377 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2379 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2380 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2381 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2382 | } |
| 2383 | |
| 2384 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2385 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2386 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2389 | private boolean isImsAvailableOnDevice() { |
| 2390 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2391 | if (pm == null) { |
| 2392 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2393 | // so do not throw error and allow. |
| 2394 | return true; |
| 2395 | } |
| 2396 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2397 | } |
| 2398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2399 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2400 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2403 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | if (DBG) log("dial: " + number); |
| 2405 | // No permission check needed here: This is just a wrapper around the |
| 2406 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2407 | // the UI before it does anything. |
| 2408 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2409 | final long identity = Binder.clearCallingIdentity(); |
| 2410 | try { |
| 2411 | String url = createTelUrl(number); |
| 2412 | if (url == null) { |
| 2413 | return; |
| 2414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2417 | PhoneConstants.State state = mCM.getState(subId); |
| 2418 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2419 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2420 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2421 | mApp.startActivity(intent); |
| 2422 | } |
| 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2429 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2432 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2433 | if (DBG) log("call: " + number); |
| 2434 | |
| 2435 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2436 | // need to do a permission check since we're calling startActivity() |
| 2437 | // from the context of the phone app. |
| 2438 | enforceCallPermission(); |
| 2439 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2440 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | != AppOpsManager.MODE_ALLOWED) { |
| 2442 | return; |
| 2443 | } |
| 2444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2445 | final long identity = Binder.clearCallingIdentity(); |
| 2446 | try { |
| 2447 | String url = createTelUrl(number); |
| 2448 | if (url == null) { |
| 2449 | return; |
| 2450 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2451 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 | boolean isValid = false; |
| 2453 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2454 | if (slist != null) { |
| 2455 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2456 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2457 | isValid = true; |
| 2458 | break; |
| 2459 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2460 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2461 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | if (!isValid) { |
| 2463 | return; |
| 2464 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2467 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2468 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2469 | mApp.startActivity(intent); |
| 2470 | } finally { |
| 2471 | Binder.restoreCallingIdentity(identity); |
| 2472 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2475 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2476 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2477 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2478 | } |
| 2479 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2480 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2481 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2482 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2483 | } |
| 2484 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2485 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2487 | |
| 2488 | final long identity = Binder.clearCallingIdentity(); |
| 2489 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2490 | Phone phone = getPhone(subId); |
| 2491 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | checkSimPin.start(); |
| 2493 | return checkSimPin.unlockSim(null, pin); |
| 2494 | } finally { |
| 2495 | Binder.restoreCallingIdentity(identity); |
| 2496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2499 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2501 | |
| 2502 | final long identity = Binder.clearCallingIdentity(); |
| 2503 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2504 | Phone phone = getPhone(subId); |
| 2505 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | checkSimPuk.start(); |
| 2507 | return checkSimPuk.unlockSim(puk, pin); |
| 2508 | } finally { |
| 2509 | Binder.restoreCallingIdentity(identity); |
| 2510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2514 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2515 | * a synchronous one. |
| 2516 | */ |
| 2517 | private static class UnlockSim extends Thread { |
| 2518 | |
| 2519 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2520 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | |
| 2522 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2523 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2524 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | |
| 2526 | // For replies from SimCard interface |
| 2527 | private Handler mHandler; |
| 2528 | |
| 2529 | // For async handler to identify request type |
| 2530 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2531 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2532 | UnlockSim(int phoneId, IccCard simCard) { |
| 2533 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | mSimCard = simCard; |
| 2535 | } |
| 2536 | |
| 2537 | @Override |
| 2538 | public void run() { |
| 2539 | Looper.prepare(); |
| 2540 | synchronized (UnlockSim.this) { |
| 2541 | mHandler = new Handler() { |
| 2542 | @Override |
| 2543 | public void handleMessage(Message msg) { |
| 2544 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2545 | switch (msg.what) { |
| 2546 | case SUPPLY_PIN_COMPLETE: |
| 2547 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2548 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2549 | mRetryCount = msg.arg1; |
| 2550 | if (ar.exception != null) { |
| 2551 | if (ar.exception instanceof CommandException && |
| 2552 | ((CommandException)(ar.exception)).getCommandError() |
| 2553 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2554 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2555 | } //When UiccCardApp dispose,handle message and return exception |
| 2556 | else if (ar.exception instanceof CommandException && |
| 2557 | ((CommandException) (ar.exception)).getCommandError() |
| 2558 | == CommandException.Error.ABORTED) { |
| 2559 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2560 | } else { |
| 2561 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2562 | } |
| 2563 | } else { |
| 2564 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2565 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | mDone = true; |
| 2567 | UnlockSim.this.notifyAll(); |
| 2568 | } |
| 2569 | break; |
| 2570 | } |
| 2571 | } |
| 2572 | }; |
| 2573 | UnlockSim.this.notifyAll(); |
| 2574 | } |
| 2575 | Looper.loop(); |
| 2576 | } |
| 2577 | |
| 2578 | /* |
| 2579 | * Use PIN or PUK to unlock SIM card |
| 2580 | * |
| 2581 | * If PUK is null, unlock SIM card with PIN |
| 2582 | * |
| 2583 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2584 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2585 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | |
| 2587 | while (mHandler == null) { |
| 2588 | try { |
| 2589 | wait(); |
| 2590 | } catch (InterruptedException e) { |
| 2591 | Thread.currentThread().interrupt(); |
| 2592 | } |
| 2593 | } |
| 2594 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2595 | |
| 2596 | if (puk == null) { |
| 2597 | mSimCard.supplyPin(pin, callback); |
| 2598 | } else { |
| 2599 | mSimCard.supplyPuk(puk, pin, callback); |
| 2600 | } |
| 2601 | |
| 2602 | while (!mDone) { |
| 2603 | try { |
| 2604 | Log.d(LOG_TAG, "wait for done"); |
| 2605 | wait(); |
| 2606 | } catch (InterruptedException e) { |
| 2607 | // Restore the interrupted status |
| 2608 | Thread.currentThread().interrupt(); |
| 2609 | } |
| 2610 | } |
| 2611 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2612 | int[] resultArray = new int[2]; |
| 2613 | resultArray[0] = mResult; |
| 2614 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2615 | |
| 2616 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2617 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2620 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | } |
| 2622 | } |
| 2623 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2624 | /** |
| 2625 | * This method has been removed due to privacy and stability concerns. |
| 2626 | */ |
| 2627 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2629 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2630 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2633 | @Override |
| 2634 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2635 | mApp.getSystemService(AppOpsManager.class) |
| 2636 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2637 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2638 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2639 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2640 | // Callers targeting S have no business invoking this method. |
| 2641 | return; |
| 2642 | } |
| 2643 | |
| 2644 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2645 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2646 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2647 | .setCallingPackage(callingPackage) |
| 2648 | .setCallingFeatureId(null) |
| 2649 | .setCallingPid(Binder.getCallingPid()) |
| 2650 | .setCallingUid(Binder.getCallingUid()) |
| 2651 | .setMethod("updateServiceLocation") |
| 2652 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2653 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2654 | .build()); |
| 2655 | // Apps that lack location permission have no business calling this method; |
| 2656 | // however, because no permission was declared in the public API, denials must |
| 2657 | // all be "soft". |
| 2658 | switch (locationResult) { |
| 2659 | case DENIED_HARD: /* fall through */ |
| 2660 | case DENIED_SOFT: |
| 2661 | return; |
| 2662 | } |
| 2663 | |
| 2664 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2667 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2669 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2670 | } |
| 2671 | } finally { |
| 2672 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2673 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2676 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2677 | @Override |
| 2678 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2679 | return isRadioOnWithFeature(callingPackage, null); |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | @Override |
| 2684 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2685 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2686 | callingFeatureId); |
| 2687 | } |
| 2688 | |
| 2689 | @Deprecated |
| 2690 | @Override |
| 2691 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2692 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2695 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2696 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2697 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2698 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2699 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2700 | return false; |
| 2701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | |
| 2703 | final long identity = Binder.clearCallingIdentity(); |
| 2704 | try { |
| 2705 | return isRadioOnForSubscriber(subId); |
| 2706 | } finally { |
| 2707 | Binder.restoreCallingIdentity(identity); |
| 2708 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
| 2714 | final Phone phone = getPhone(subId); |
| 2715 | if (phone != null) { |
| 2716 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2717 | } else { |
| 2718 | return false; |
| 2719 | } |
| 2720 | } finally { |
| 2721 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2722 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2726 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2728 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2729 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2731 | |
| 2732 | final long identity = Binder.clearCallingIdentity(); |
| 2733 | try { |
| 2734 | final Phone phone = getPhone(subId); |
| 2735 | if (phone != null) { |
| 2736 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2737 | } |
| 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2740 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2744 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2747 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2748 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
| 2752 | final Phone phone = getPhone(subId); |
| 2753 | if (phone == null) { |
| 2754 | return false; |
| 2755 | } |
| 2756 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2757 | toggleRadioOnOffForSubscriber(subId); |
| 2758 | } |
| 2759 | return true; |
| 2760 | } finally { |
| 2761 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2762 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2763 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2764 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2765 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2766 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2767 | /* |
| 2768 | * If any of the Radios are available, it will need to be |
| 2769 | * shutdown. So return true if any Radio is available. |
| 2770 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2771 | final long identity = Binder.clearCallingIdentity(); |
| 2772 | try { |
| 2773 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2774 | Phone phone = PhoneFactory.getPhone(i); |
| 2775 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2776 | } |
| 2777 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2778 | return false; |
| 2779 | } finally { |
| 2780 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2781 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2784 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2785 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | enforceModifyPermission(); |
| 2787 | |
| 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2791 | logv("Shutting down Phone " + i); |
| 2792 | shutdownRadioUsingPhoneId(i); |
| 2793 | } |
| 2794 | } finally { |
| 2795 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2800 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2801 | if (phone != null && phone.isRadioAvailable()) { |
| 2802 | phone.shutdownRadio(); |
| 2803 | } |
| 2804 | } |
| 2805 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2806 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2807 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | |
| 2809 | final long identity = Binder.clearCallingIdentity(); |
| 2810 | try { |
| 2811 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2812 | if (defaultPhone != null) { |
| 2813 | defaultPhone.setRadioPower(turnOn); |
| 2814 | return true; |
| 2815 | } else { |
| 2816 | loge("There's no default phone."); |
| 2817 | return false; |
| 2818 | } |
| 2819 | } finally { |
| 2820 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2821 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2824 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2825 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | |
| 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
| 2829 | final Phone phone = getPhone(subId); |
| 2830 | if (phone != null) { |
| 2831 | phone.setRadioPower(turnOn); |
| 2832 | return true; |
| 2833 | } else { |
| 2834 | return false; |
| 2835 | } |
| 2836 | } finally { |
| 2837 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2838 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2841 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2842 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2843 | public boolean enableDataConnectivity() { |
| 2844 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | |
| 2846 | final long identity = Binder.clearCallingIdentity(); |
| 2847 | try { |
| 2848 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2849 | final Phone phone = getPhone(subId); |
| 2850 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2851 | if (phone.isUsingNewDataStack()) { |
| 2852 | phone.getDataSettingsManager().setDataEnabled( |
| 2853 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2854 | } else { |
| 2855 | phone.getDataEnabledSettings().setDataEnabled( |
| 2856 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2857 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | return true; |
| 2859 | } else { |
| 2860 | return false; |
| 2861 | } |
| 2862 | } finally { |
| 2863 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2864 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2865 | } |
| 2866 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2867 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2868 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2869 | public boolean disableDataConnectivity() { |
| 2870 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | |
| 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2875 | final Phone phone = getPhone(subId); |
| 2876 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2877 | if (phone.isUsingNewDataStack()) { |
| 2878 | phone.getDataSettingsManager().setDataEnabled( |
| 2879 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2880 | } else { |
| 2881 | phone.getDataEnabledSettings().setDataEnabled( |
| 2882 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2883 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | return true; |
| 2885 | } else { |
| 2886 | return false; |
| 2887 | } |
| 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2890 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2893 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2894 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | final long identity = Binder.clearCallingIdentity(); |
| 2896 | try { |
| 2897 | final Phone phone = getPhone(subId); |
| 2898 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2899 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | } else { |
| 2901 | return false; |
| 2902 | } |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2909 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2912 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | enforceCallPermission(); |
| 2914 | |
| 2915 | final long identity = Binder.clearCallingIdentity(); |
| 2916 | try { |
| 2917 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2918 | return; |
| 2919 | } |
| 2920 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2921 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2922 | } finally { |
| 2923 | Binder.restoreCallingIdentity(identity); |
| 2924 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2925 | }; |
| 2926 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2927 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
| 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2933 | return false; |
| 2934 | } |
| 2935 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2939 | } |
| 2940 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2941 | /** |
| 2942 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2943 | * tag on getCallState Binder call. |
| 2944 | */ |
| 2945 | @Deprecated |
| 2946 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2948 | if (CompatChanges.isChangeEnabled( |
| 2949 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2950 | Binder.getCallingUid())) { |
| 2951 | // Do not allow this API to be called on API version 31+, it should only be |
| 2952 | // called on old apps using this Binder call directly. |
| 2953 | throw new SecurityException("This method can only be used for applications " |
| 2954 | + "targeting API version 30 or less."); |
| 2955 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2958 | Phone phone = getPhone(getDefaultSubscription()); |
| 2959 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2960 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
| 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | @Override |
| 2967 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2968 | if (CompatChanges.isChangeEnabled( |
| 2969 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2970 | Binder.getCallingUid())) { |
| 2971 | // Check READ_PHONE_STATE for API version 31+ |
| 2972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2973 | featureId, "getCallStateForSubscription")) { |
| 2974 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2975 | + "targeting API level 31+."); |
| 2976 | } |
| 2977 | } |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2982 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2986 | } |
| 2987 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2988 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2989 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2990 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2991 | } |
| 2992 | |
| 2993 | @Override |
| 2994 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2997 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 2999 | if (phone.isUsingNewDataStack()) { |
| 3000 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3003 | } else { |
| 3004 | return PhoneConstantConversions.convertDataState( |
| 3005 | PhoneConstants.DataState.DISCONNECTED); |
| 3006 | } |
| 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3009 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3012 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3013 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3014 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3015 | } |
| 3016 | |
| 3017 | @Override |
| 3018 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3021 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | if (phone != null) { |
| 3023 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 3024 | } else { |
| 3025 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3026 | } |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3033 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3034 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3035 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3036 | |
| 3037 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3038 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3039 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3040 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3041 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3042 | .setCallingPid(Binder.getCallingPid()) |
| 3043 | .setCallingUid(Binder.getCallingUid()) |
| 3044 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3045 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3046 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3047 | .build()); |
| 3048 | switch (locationResult) { |
| 3049 | case DENIED_HARD: |
| 3050 | throw new SecurityException("Not allowed to access cell location"); |
| 3051 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3052 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3053 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3056 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3057 | final long identity = Binder.clearCallingIdentity(); |
| 3058 | try { |
| 3059 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3060 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3061 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | } finally { |
| 3063 | Binder.restoreCallingIdentity(identity); |
| 3064 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3068 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3069 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3070 | // registered cell info, so return a NULL country instead. |
| 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3073 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3074 | // Get default phone in this case. |
| 3075 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3076 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3077 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3079 | if (phone == null) return ""; |
| 3080 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3081 | if (sst == null) return ""; |
| 3082 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3083 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3084 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3085 | } finally { |
| 3086 | Binder.restoreCallingIdentity(identity); |
| 3087 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3090 | /** |
| 3091 | * This method was removed due to potential issues caused by performing partial |
| 3092 | * updates of service state, and lack of a credible use case. |
| 3093 | * |
| 3094 | * This has the ability to break the telephony implementation by disabling notification of |
| 3095 | * changes in device connectivity. DO NOT USE THIS! |
| 3096 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3097 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | public void enableLocationUpdates() { |
| 3099 | mApp.enforceCallingOrSelfPermission( |
| 3100 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3103 | /** |
| 3104 | * This method was removed due to potential issues caused by performing partial |
| 3105 | * updates of service state, and lack of a credible use case. |
| 3106 | * |
| 3107 | * This has the ability to break the telephony implementation by disabling notification of |
| 3108 | * changes in device connectivity. DO NOT USE THIS! |
| 3109 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | @Override |
| 3111 | public void disableLocationUpdates() { |
| 3112 | mApp.enforceCallingOrSelfPermission( |
| 3113 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | @Override |
| 3117 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3118 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3119 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3120 | try { |
| 3121 | mApp.getSystemService(AppOpsManager.class) |
| 3122 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3123 | } catch (SecurityException e) { |
| 3124 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3125 | throw e; |
| 3126 | } |
| 3127 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3128 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3129 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3130 | throw new SecurityException( |
| 3131 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3132 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3133 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3134 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3135 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3136 | return null; |
| 3137 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3138 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3139 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3140 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3141 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3142 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3144 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3145 | for (CellInfo ci : info) { |
| 3146 | if (ci instanceof CellInfoGsm) { |
| 3147 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3148 | } else if (ci instanceof CellInfoWcdma) { |
| 3149 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3151 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3152 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3155 | private List<CellInfo> getCachedCellInfo() { |
| 3156 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3157 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3158 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3159 | if (info != null) cellInfos.addAll(info); |
| 3160 | } |
| 3161 | return cellInfos; |
| 3162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3163 | |
| 3164 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3165 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3166 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3167 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3168 | |
| 3169 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3170 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3171 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3172 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3173 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3174 | .setCallingPid(Binder.getCallingPid()) |
| 3175 | .setCallingUid(Binder.getCallingUid()) |
| 3176 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3177 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3178 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3179 | .build()); |
| 3180 | switch (locationResult) { |
| 3181 | case DENIED_HARD: |
| 3182 | throw new SecurityException("Not allowed to access cell info"); |
| 3183 | case DENIED_SOFT: |
| 3184 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3187 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3188 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3189 | return getCachedCellInfo(); |
| 3190 | } |
| 3191 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3192 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3193 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3197 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3198 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3199 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | if (info != null) cellInfos.addAll(info); |
| 3201 | } |
| 3202 | return cellInfos; |
| 3203 | } finally { |
| 3204 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | } |
| 3206 | } |
| 3207 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3208 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3209 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3210 | String callingFeatureId) { |
| 3211 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3212 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3216 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3217 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3218 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3219 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3222 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3223 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3224 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3225 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3226 | |
| 3227 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3228 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3229 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3230 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3231 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3232 | .setCallingPid(Binder.getCallingPid()) |
| 3233 | .setCallingUid(Binder.getCallingUid()) |
| 3234 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3235 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3236 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3237 | .build()); |
| 3238 | switch (locationResult) { |
| 3239 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3240 | if (TelephonyPermissions |
| 3241 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3242 | // Safetynet logging for b/154934934 |
| 3243 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3244 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3245 | throw new SecurityException("Not allowed to access cell info"); |
| 3246 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3247 | if (TelephonyPermissions |
| 3248 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3249 | // Safetynet logging for b/154934934 |
| 3250 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3251 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3252 | try { |
| 3253 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3254 | } catch (RemoteException re) { |
| 3255 | // Drop without consequences |
| 3256 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3257 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3260 | |
| 3261 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3262 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3263 | |
| 3264 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3265 | } |
| 3266 | |
| 3267 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3268 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3269 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3270 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | |
| 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3274 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3275 | } finally { |
| 3276 | Binder.restoreCallingIdentity(identity); |
| 3277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | } |
| 3279 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3280 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3281 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3282 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3283 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3284 | return null; |
| 3285 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3286 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3287 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3288 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3289 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3290 | return null; |
| 3291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | |
| 3293 | final long identity = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | return phone.getImei(); |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
| 3298 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3302 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3303 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3304 | String tac = null; |
| 3305 | if (phone != null) { |
| 3306 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3307 | try { |
| 3308 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3309 | } catch (IndexOutOfBoundsException e) { |
| 3310 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3311 | return null; |
| 3312 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3313 | } |
| 3314 | return tac; |
| 3315 | } |
| 3316 | |
| 3317 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3318 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3319 | try { |
| 3320 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3321 | } catch (SecurityException se) { |
| 3322 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3323 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3324 | + Binder.getCallingUid()); |
| 3325 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3326 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3327 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3328 | return null; |
| 3329 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3330 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3331 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3332 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3333 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3334 | return null; |
| 3335 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | |
| 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | return phone.getMeid(); |
| 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3343 | } |
| 3344 | |
| 3345 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3346 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3347 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3348 | String manufacturerCode = null; |
| 3349 | if (phone != null) { |
| 3350 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3351 | try { |
| 3352 | manufacturerCode = |
| 3353 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3354 | } catch (IndexOutOfBoundsException e) { |
| 3355 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3356 | return null; |
| 3357 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3358 | } |
| 3359 | return manufacturerCode; |
| 3360 | } |
| 3361 | |
| 3362 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3363 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3364 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3365 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3366 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3367 | return null; |
| 3368 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3369 | int subId = phone.getSubId(); |
| 3370 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3371 | mApp, subId, callingPackage, callingFeatureId, |
| 3372 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3373 | return null; |
| 3374 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3375 | |
| 3376 | final long identity = Binder.clearCallingIdentity(); |
| 3377 | try { |
| 3378 | return phone.getDeviceSvn(); |
| 3379 | } finally { |
| 3380 | Binder.restoreCallingIdentity(identity); |
| 3381 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3384 | @Override |
| 3385 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | final long identity = Binder.clearCallingIdentity(); |
| 3387 | try { |
| 3388 | final Phone phone = getPhone(subId); |
| 3389 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3390 | } finally { |
| 3391 | Binder.restoreCallingIdentity(identity); |
| 3392 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | @Override |
| 3396 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | final long identity = Binder.clearCallingIdentity(); |
| 3398 | try { |
| 3399 | final Phone phone = getPhone(subId); |
| 3400 | return phone == null ? null : phone.getCarrierName(); |
| 3401 | } finally { |
| 3402 | Binder.restoreCallingIdentity(identity); |
| 3403 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3404 | } |
| 3405 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3406 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3407 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | final Phone phone = getPhone(subId); |
| 3411 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3412 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
| 3416 | } |
| 3417 | |
| 3418 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3419 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3420 | final long identity = Binder.clearCallingIdentity(); |
| 3421 | try { |
| 3422 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3423 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
| 3427 | } |
| 3428 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3429 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3430 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3431 | if (!isSubscriptionMccMnc) { |
| 3432 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3433 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3434 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3435 | if (phone == null) { |
| 3436 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3437 | } |
| 3438 | final long identity = Binder.clearCallingIdentity(); |
| 3439 | try { |
| 3440 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3441 | } finally { |
| 3442 | Binder.restoreCallingIdentity(identity); |
| 3443 | } |
| 3444 | } |
| 3445 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3446 | // |
| 3447 | // Internal helper methods. |
| 3448 | // |
| 3449 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3450 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3451 | * Make sure the caller is the calling package itself |
| 3452 | * |
| 3453 | * @throws SecurityException if the caller is not the calling package |
| 3454 | */ |
| 3455 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3456 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3457 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3458 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3459 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3460 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3461 | } catch (PackageManager.NameNotFoundException e) { |
| 3462 | // packageUid is -1 |
| 3463 | } |
| 3464 | if (packageUid != callingUid) { |
| 3465 | throw new SecurityException(message + ": Package " + callingPackage |
| 3466 | + " does not belong to " + callingUid); |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3471 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3472 | * |
| 3473 | * @throws SecurityException if the caller does not have the required permission |
| 3474 | */ |
| 3475 | private void enforceModifyPermission() { |
| 3476 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3477 | } |
| 3478 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3479 | private void enforceActiveEmergencySessionPermission() { |
| 3480 | mApp.enforceCallingOrSelfPermission( |
| 3481 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3482 | } |
| 3483 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | /** |
| 3485 | * Make sure the caller has the CALL_PHONE permission. |
| 3486 | * |
| 3487 | * @throws SecurityException if the caller does not have the required permission |
| 3488 | */ |
| 3489 | private void enforceCallPermission() { |
| 3490 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3491 | } |
| 3492 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3493 | private void enforceSettingsPermission() { |
| 3494 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3497 | private void enforceRebootPermission() { |
| 3498 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3499 | } |
| 3500 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3501 | private String createTelUrl(String number) { |
| 3502 | if (TextUtils.isEmpty(number)) { |
| 3503 | return null; |
| 3504 | } |
| 3505 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3506 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3509 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3510 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3511 | } |
| 3512 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3513 | private static void logv(String msg) { |
| 3514 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3515 | } |
| 3516 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3517 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3518 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3519 | } |
| 3520 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3521 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3522 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3523 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
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 |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3527 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | final long identity = Binder.clearCallingIdentity(); |
| 3529 | try { |
| 3530 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3531 | if (phone == null) { |
| 3532 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3533 | } else { |
| 3534 | return phone.getPhoneType(); |
| 3535 | } |
| 3536 | } finally { |
| 3537 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * Returns the CDMA ERI icon index to display |
| 3543 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3544 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3545 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3546 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3547 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3550 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3551 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3552 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3553 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3554 | mApp, subId, callingPackage, callingFeatureId, |
| 3555 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3556 | return -1; |
| 3557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3558 | |
| 3559 | final long identity = Binder.clearCallingIdentity(); |
| 3560 | try { |
| 3561 | final Phone phone = getPhone(subId); |
| 3562 | if (phone != null) { |
| 3563 | return phone.getCdmaEriIconIndex(); |
| 3564 | } else { |
| 3565 | return -1; |
| 3566 | } |
| 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3570 | } |
| 3571 | |
| 3572 | /** |
| 3573 | * Returns the CDMA ERI icon mode, |
| 3574 | * 0 - ON |
| 3575 | * 1 - FLASHING |
| 3576 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3577 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3578 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3579 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3580 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3581 | } |
| 3582 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3583 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3584 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3585 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3586 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3587 | mApp, subId, callingPackage, callingFeatureId, |
| 3588 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3589 | return -1; |
| 3590 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3591 | |
| 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | final Phone phone = getPhone(subId); |
| 3595 | if (phone != null) { |
| 3596 | return phone.getCdmaEriIconMode(); |
| 3597 | } else { |
| 3598 | return -1; |
| 3599 | } |
| 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3602 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | /** |
| 3606 | * Returns the CDMA ERI text, |
| 3607 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3608 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3609 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3610 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3611 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3614 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3615 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3616 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3617 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3618 | mApp, subId, callingPackage, callingFeatureId, |
| 3619 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3620 | return null; |
| 3621 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3622 | |
| 3623 | final long identity = Binder.clearCallingIdentity(); |
| 3624 | try { |
| 3625 | final Phone phone = getPhone(subId); |
| 3626 | if (phone != null) { |
| 3627 | return phone.getCdmaEriText(); |
| 3628 | } else { |
| 3629 | return null; |
| 3630 | } |
| 3631 | } finally { |
| 3632 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3637 | * Returns the CDMA MDN. |
| 3638 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3639 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3640 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3642 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3643 | |
| 3644 | final long identity = Binder.clearCallingIdentity(); |
| 3645 | try { |
| 3646 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3647 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | return phone.getLine1Number(); |
| 3649 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3650 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | return null; |
| 3652 | } |
| 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * Returns the CDMA MIN. |
| 3660 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3661 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3662 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3664 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | |
| 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | final Phone phone = getPhone(subId); |
| 3669 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3670 | return phone.getCdmaMin(); |
| 3671 | } else { |
| 3672 | return null; |
| 3673 | } |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3676 | } |
| 3677 | } |
| 3678 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3679 | @Override |
| 3680 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3681 | INumberVerificationCallback callback, String callingPackage) { |
| 3682 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3683 | != PERMISSION_GRANTED) { |
| 3684 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3685 | } |
| 3686 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3687 | |
| 3688 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3689 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3690 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3691 | + "calling package: " + callingPackage |
| 3692 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | if (range == null) { |
| 3696 | throw new NullPointerException("Range must be non-null"); |
| 3697 | } |
| 3698 | |
| 3699 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3700 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3701 | |
| 3702 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3703 | } |
| 3704 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3705 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3706 | * Returns true if CDMA provisioning needs to run. |
| 3707 | */ |
| 3708 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3709 | final long identity = Binder.clearCallingIdentity(); |
| 3710 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | } finally { |
| 3713 | Binder.restoreCallingIdentity(identity); |
| 3714 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3718 | * Sets the voice mail number of a given subId. |
| 3719 | */ |
| 3720 | @Override |
| 3721 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3722 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3723 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3724 | |
| 3725 | final long identity = Binder.clearCallingIdentity(); |
| 3726 | try { |
| 3727 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3728 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3729 | return success; |
| 3730 | } finally { |
| 3731 | Binder.restoreCallingIdentity(identity); |
| 3732 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3733 | } |
| 3734 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3735 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3736 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3737 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3738 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3739 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3740 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3741 | throw new SecurityException("caller must be system dialer"); |
| 3742 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3743 | |
| 3744 | final long identity = Binder.clearCallingIdentity(); |
| 3745 | try { |
| 3746 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3747 | if (phoneAccountHandle == null) { |
| 3748 | return null; |
| 3749 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3750 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3751 | } finally { |
| 3752 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3753 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3757 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3758 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3759 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3761 | mApp, subId, callingPackage, callingFeatureId, |
| 3762 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3763 | return null; |
| 3764 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3766 | final long identity = Binder.clearCallingIdentity(); |
| 3767 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3768 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3775 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3776 | VisualVoicemailSmsFilterSettings settings) { |
| 3777 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | |
| 3779 | final long identity = Binder.clearCallingIdentity(); |
| 3780 | try { |
| 3781 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3782 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3783 | } finally { |
| 3784 | Binder.restoreCallingIdentity(identity); |
| 3785 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3789 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3790 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | |
| 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3795 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | } finally { |
| 3797 | Binder.restoreCallingIdentity(identity); |
| 3798 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3802 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3803 | String callingPackage, int subId) { |
| 3804 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | |
| 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3809 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
| 3812 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3816 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3817 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3818 | |
| 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3822 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
| 3825 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3829 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3830 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3831 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3832 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3833 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3834 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3835 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3836 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3837 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3838 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3839 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3840 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3841 | * Sets the voice activation state of a given subId. |
| 3842 | */ |
| 3843 | @Override |
| 3844 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3846 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3847 | |
| 3848 | final long identity = Binder.clearCallingIdentity(); |
| 3849 | try { |
| 3850 | final Phone phone = getPhone(subId); |
| 3851 | if (phone != null) { |
| 3852 | phone.setVoiceActivationState(activationState); |
| 3853 | } else { |
| 3854 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3855 | } |
| 3856 | } finally { |
| 3857 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3858 | } |
| 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * Sets the data activation state of a given subId. |
| 3863 | */ |
| 3864 | @Override |
| 3865 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3867 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3868 | |
| 3869 | final long identity = Binder.clearCallingIdentity(); |
| 3870 | try { |
| 3871 | final Phone phone = getPhone(subId); |
| 3872 | if (phone != null) { |
| 3873 | phone.setDataActivationState(activationState); |
| 3874 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3875 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | } |
| 3877 | } finally { |
| 3878 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | /** |
| 3883 | * Returns the voice activation state of a given subId. |
| 3884 | */ |
| 3885 | @Override |
| 3886 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3887 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3888 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3889 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3890 | final long identity = Binder.clearCallingIdentity(); |
| 3891 | try { |
| 3892 | if (phone != null) { |
| 3893 | return phone.getVoiceActivationState(); |
| 3894 | } else { |
| 3895 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3896 | } |
| 3897 | } finally { |
| 3898 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3899 | } |
| 3900 | } |
| 3901 | |
| 3902 | /** |
| 3903 | * Returns the data activation state of a given subId. |
| 3904 | */ |
| 3905 | @Override |
| 3906 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3909 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3910 | final long identity = Binder.clearCallingIdentity(); |
| 3911 | try { |
| 3912 | if (phone != null) { |
| 3913 | return phone.getDataActivationState(); |
| 3914 | } else { |
| 3915 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3916 | } |
| 3917 | } finally { |
| 3918 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3919 | } |
| 3920 | } |
| 3921 | |
| 3922 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3923 | * Returns the unread count of voicemails for a subId |
| 3924 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3925 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3926 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3927 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3928 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3929 | mApp, subId, callingPackage, callingFeatureId, |
| 3930 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3931 | return 0; |
| 3932 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | final Phone phone = getPhone(subId); |
| 3936 | if (phone != null) { |
| 3937 | return phone.getVoiceMessageCount(); |
| 3938 | } else { |
| 3939 | return 0; |
| 3940 | } |
| 3941 | } finally { |
| 3942 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3943 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3947 | * returns true, if the device is in a state where both voice and data |
| 3948 | * are supported simultaneously. This can change based on location or network condition. |
| 3949 | */ |
| 3950 | @Override |
| 3951 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | final Phone phone = getPhone(subId); |
| 3955 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(identity); |
| 3958 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3962 | * Send the dialer code if called from the current default dialer or the caller has |
| 3963 | * carrier privilege. |
| 3964 | * @param inputCode The dialer code to send |
| 3965 | */ |
| 3966 | @Override |
| 3967 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3968 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3969 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3970 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3971 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3972 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3973 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3974 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3975 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | |
| 3977 | final long identity = Binder.clearCallingIdentity(); |
| 3978 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3979 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3980 | } finally { |
| 3981 | Binder.restoreCallingIdentity(identity); |
| 3982 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3983 | } |
| 3984 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3985 | @Override |
| 3986 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3987 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3988 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3989 | mApp, subId, "getNetworkSelectionMode"); |
| 3990 | final long identity = Binder.clearCallingIdentity(); |
| 3991 | try { |
| 3992 | if (!isActiveSubscription(subId)) { |
| 3993 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3994 | } |
| 3995 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3996 | } finally { |
| 3997 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3998 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3999 | } |
| 4000 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4002 | public boolean isInEmergencySmsMode() { |
| 4003 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4007 | if (phone.isInEmergencySmsMode()) { |
| 4008 | return true; |
| 4009 | } |
| 4010 | } |
| 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | return false; |
| 4015 | } |
| 4016 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4017 | /** |
| 4018 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4019 | * @param subId The subscription to use to check the configuration. |
| 4020 | * @param c The callback that will be used to send the result. |
| 4021 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4022 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4023 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4024 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4025 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4026 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4027 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4028 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4029 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4030 | "IMS not available on device."); |
| 4031 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | final long token = Binder.clearCallingIdentity(); |
| 4033 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4034 | int slotId = getSlotIndexOrException(subId); |
| 4035 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4036 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4037 | } catch (ImsException e) { |
| 4038 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(token); |
| 4041 | } |
| 4042 | } |
| 4043 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4044 | /** |
| 4045 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4046 | * @param subId The subscription to use to check the configuration. |
| 4047 | * @param c The callback that will be used to send the result. |
| 4048 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4050 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4051 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4052 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4053 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4054 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4055 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4056 | final long token = Binder.clearCallingIdentity(); |
| 4057 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4058 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4059 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4060 | } catch (ImsException e) { |
| 4061 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4062 | + "is inactive, ignoring unregister."); |
| 4063 | // If the subscription is no longer active, just return, since the callback |
| 4064 | // will already have been removed internally. |
| 4065 | } finally { |
| 4066 | Binder.restoreCallingIdentity(token); |
| 4067 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | } |
| 4069 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4070 | /** |
| 4071 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4072 | */ |
| 4073 | @Override |
| 4074 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4075 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4076 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4077 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4078 | "IMS not available on device."); |
| 4079 | } |
| 4080 | final long token = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | Phone phone = getPhone(subId); |
| 4083 | if (phone == null) { |
| 4084 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4085 | + subId + "'"); |
| 4086 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4087 | } |
| 4088 | phone.getImsRegistrationState(regState -> { |
| 4089 | try { |
| 4090 | consumer.accept((regState == null) |
| 4091 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4092 | } catch (RemoteException e) { |
| 4093 | // Ignore if the remote process is no longer available to call back. |
| 4094 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4095 | } |
| 4096 | }); |
| 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(token); |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | /** |
| 4103 | * Get the transport type for the IMS service registration state. |
| 4104 | */ |
| 4105 | @Override |
| 4106 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4107 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4108 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4109 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4110 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4111 | "IMS not available on device."); |
| 4112 | } |
| 4113 | final long token = Binder.clearCallingIdentity(); |
| 4114 | try { |
| 4115 | Phone phone = getPhone(subId); |
| 4116 | if (phone == null) { |
| 4117 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4118 | + subId + "'"); |
| 4119 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4120 | } |
| 4121 | phone.getImsRegistrationTech(regTech -> { |
| 4122 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4123 | int regTechConverted = (regTech == null) |
| 4124 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4125 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4126 | regTechConverted); |
| 4127 | try { |
| 4128 | consumer.accept(regTechConverted); |
| 4129 | } catch (RemoteException e) { |
| 4130 | // Ignore if the remote process is no longer available to call back. |
| 4131 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4132 | } |
| 4133 | }); |
| 4134 | } finally { |
| 4135 | Binder.restoreCallingIdentity(token); |
| 4136 | } |
| 4137 | } |
| 4138 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4139 | /** |
| 4140 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4141 | * @param subId The subscription to use to check the configuration. |
| 4142 | * @param c The callback that will be used to send the result. |
| 4143 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4144 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4145 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4146 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4147 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4148 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4149 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4150 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4151 | "IMS not available on device."); |
| 4152 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4153 | final long token = Binder.clearCallingIdentity(); |
| 4154 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4155 | int slotId = getSlotIndexOrException(subId); |
| 4156 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4157 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4158 | } catch (ImsException e) { |
| 4159 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | } finally { |
| 4161 | Binder.restoreCallingIdentity(token); |
| 4162 | } |
| 4163 | } |
| 4164 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4165 | /** |
| 4166 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4167 | * @param subId The subscription to use to check the configuration. |
| 4168 | * @param c The callback that will be used to send the result. |
| 4169 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4170 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4171 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4172 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4173 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4174 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4175 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4176 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4177 | |
| 4178 | final long token = Binder.clearCallingIdentity(); |
| 4179 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4180 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4181 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4182 | } catch (ImsException e) { |
| 4183 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4184 | + "is inactive, ignoring unregister."); |
| 4185 | // If the subscription is no longer active, just return, since the callback |
| 4186 | // will already have been removed internally. |
| 4187 | } finally { |
| 4188 | Binder.restoreCallingIdentity(token); |
| 4189 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4193 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4194 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | final long token = Binder.clearCallingIdentity(); |
| 4196 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4197 | int slotId = getSlotIndexOrException(subId); |
| 4198 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4199 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4200 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4202 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4203 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4204 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4205 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4206 | } finally { |
| 4207 | Binder.restoreCallingIdentity(token); |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4212 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4213 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | final long token = Binder.clearCallingIdentity(); |
| 4215 | try { |
| 4216 | Phone phone = getPhone(subId); |
| 4217 | if (phone == null) return false; |
| 4218 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4219 | } catch (com.android.ims.ImsException e) { |
| 4220 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4221 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(token); |
| 4224 | } |
| 4225 | } |
| 4226 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4227 | /** |
| 4228 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4229 | * subscription. |
| 4230 | * @param subId The subscription to use to check the configuration. |
| 4231 | * @param callback The callback that will be used to send the result. |
| 4232 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4233 | * @param transportType The transport type of the MmTelFeature capability. |
| 4234 | */ |
| 4235 | @Override |
| 4236 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4237 | int transportType) { |
| 4238 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4239 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4240 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4241 | "IMS not available on device."); |
| 4242 | } |
| 4243 | final long token = Binder.clearCallingIdentity(); |
| 4244 | try { |
| 4245 | int slotId = getSlotIndex(subId); |
| 4246 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4247 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4248 | + subId + "'"); |
| 4249 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4250 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4251 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4252 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4253 | transportType, aBoolean -> { |
| 4254 | try { |
| 4255 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4256 | } catch (RemoteException e) { |
| 4257 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4258 | + "running. Ignore"); |
| 4259 | } |
| 4260 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4261 | } catch (ImsException e) { |
| 4262 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(token); |
| 4265 | } |
| 4266 | } |
| 4267 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4268 | /** |
| 4269 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4270 | * @param subId The subscription to use to check the configuration. |
| 4271 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4272 | @Override |
| 4273 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4274 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4275 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4276 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4277 | final long token = Binder.clearCallingIdentity(); |
| 4278 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4279 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4280 | // 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] | 4281 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4282 | } catch (ImsException e) { |
| 4283 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4284 | } finally { |
| 4285 | Binder.restoreCallingIdentity(token); |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4290 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4292 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4293 | final long identity = Binder.clearCallingIdentity(); |
| 4294 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4295 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4296 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4297 | // 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] | 4298 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
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 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4306 | /** |
| 4307 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4308 | * @param subId The subscription to use to check the configuration. |
| 4309 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4310 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4311 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4312 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4313 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4314 | final long identity = Binder.clearCallingIdentity(); |
| 4315 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4316 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4317 | // 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] | 4318 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4319 | } catch (ImsException e) { |
| 4320 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4321 | } finally { |
| 4322 | Binder.restoreCallingIdentity(identity); |
| 4323 | } |
| 4324 | } |
| 4325 | |
| 4326 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4327 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4329 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4330 | final long identity = Binder.clearCallingIdentity(); |
| 4331 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4332 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4333 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4334 | // 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] | 4335 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4336 | } catch (ImsException e) { |
| 4337 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
| 4340 | } |
| 4341 | } |
| 4342 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4343 | /** |
| 4344 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4345 | * @param subId The subscription to use to check the configuration. |
| 4346 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4347 | @Override |
| 4348 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4349 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4350 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4353 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4354 | // 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] | 4355 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4356 | } catch (ImsException e) { |
| 4357 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4364 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4366 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4367 | final long identity = Binder.clearCallingIdentity(); |
| 4368 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4369 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4370 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4371 | // 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] | 4372 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4373 | } catch (ImsException e) { |
| 4374 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
| 4378 | } |
| 4379 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4380 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4381 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4382 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4383 | * @param subId The subscription to use to check the configuration. |
| 4384 | */ |
| 4385 | @Override |
| 4386 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4387 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4388 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4391 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4392 | // 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] | 4393 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4394 | } catch (ImsException e) { |
| 4395 | throw new ServiceSpecificException(e.getCode()); |
| 4396 | } finally { |
| 4397 | Binder.restoreCallingIdentity(identity); |
| 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | /** |
| 4402 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4403 | * Requires MODIFY_PHONE_STATE permission. |
| 4404 | * @param subId The subscription to use to check the configuration. |
| 4405 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4406 | * false otherwise |
| 4407 | */ |
| 4408 | @Override |
| 4409 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4411 | "setCrossSimCallingEnabled"); |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4414 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4415 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4416 | // 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] | 4417 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4418 | } catch (ImsException e) { |
| 4419 | throw new ServiceSpecificException(e.getCode()); |
| 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
| 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4426 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4427 | * @param subId The subscription to use to check the configuration. |
| 4428 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4429 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4430 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4431 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4432 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4433 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4434 | final long identity = Binder.clearCallingIdentity(); |
| 4435 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4436 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4437 | // 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] | 4438 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4439 | } catch (ImsException e) { |
| 4440 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4447 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4449 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4450 | final long identity = Binder.clearCallingIdentity(); |
| 4451 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4452 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4453 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4454 | // 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] | 4455 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4456 | } catch (ImsException e) { |
| 4457 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | @Override |
| 4464 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4466 | "setVoWiFiNonPersistent"); |
| 4467 | final long identity = Binder.clearCallingIdentity(); |
| 4468 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4469 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4470 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4471 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4472 | } catch (ImsException e) { |
| 4473 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4474 | } finally { |
| 4475 | Binder.restoreCallingIdentity(identity); |
| 4476 | } |
| 4477 | } |
| 4478 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4479 | /** |
| 4480 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4481 | * @param subId The subscription to use to check the configuration. |
| 4482 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4483 | @Override |
| 4484 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4485 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4486 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4487 | final long identity = Binder.clearCallingIdentity(); |
| 4488 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4489 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4490 | // 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] | 4491 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4492 | } catch (ImsException e) { |
| 4493 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4494 | } finally { |
| 4495 | Binder.restoreCallingIdentity(identity); |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | @Override |
| 4500 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4502 | "setVoWiFiModeSetting"); |
| 4503 | final long identity = Binder.clearCallingIdentity(); |
| 4504 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4505 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4506 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4507 | // 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] | 4508 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4509 | } catch (ImsException e) { |
| 4510 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | @Override |
| 4517 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4518 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4519 | final long identity = Binder.clearCallingIdentity(); |
| 4520 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4521 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4522 | // 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] | 4523 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4524 | } catch (ImsException e) { |
| 4525 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4526 | } finally { |
| 4527 | Binder.restoreCallingIdentity(identity); |
| 4528 | } |
| 4529 | } |
| 4530 | |
| 4531 | @Override |
| 4532 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4533 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4534 | "setVoWiFiRoamingModeSetting"); |
| 4535 | final long identity = Binder.clearCallingIdentity(); |
| 4536 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4537 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4538 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4539 | // 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] | 4540 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4541 | } catch (ImsException e) { |
| 4542 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(identity); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | @Override |
| 4549 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4551 | "setRttCapabilityEnabled"); |
| 4552 | final long identity = Binder.clearCallingIdentity(); |
| 4553 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4554 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4555 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4556 | // 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] | 4557 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4558 | } catch (ImsException e) { |
| 4559 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(identity); |
| 4562 | } |
| 4563 | } |
| 4564 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4565 | /** |
| 4566 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4567 | * @param subId The subscription to use to check the configuration. |
| 4568 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4569 | @Override |
| 4570 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4571 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4572 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4573 | final long identity = Binder.clearCallingIdentity(); |
| 4574 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4575 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4576 | // 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] | 4577 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4578 | } catch (ImsException e) { |
| 4579 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4580 | } finally { |
| 4581 | Binder.restoreCallingIdentity(identity); |
| 4582 | } |
| 4583 | } |
| 4584 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4585 | @Override |
| 4586 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4587 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4590 | if (!isImsAvailableOnDevice()) { |
| 4591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4592 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4593 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4594 | int slotId = getSlotIndexOrException(subId); |
| 4595 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4596 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4597 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4598 | } catch (ImsException e) { |
| 4599 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4600 | } finally { |
| 4601 | Binder.restoreCallingIdentity(identity); |
| 4602 | } |
| 4603 | } |
| 4604 | |
| 4605 | @Override |
| 4606 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4607 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4608 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4609 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4610 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4611 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4612 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4613 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4614 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4615 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4616 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4617 | + "is inactive, ignoring unregister."); |
| 4618 | // If the subscription is no longer active, just return, since the callback will already |
| 4619 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | } |
| 4624 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4625 | |
| 4626 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4628 | message); |
| 4629 | } |
| 4630 | |
| 4631 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4632 | boolean isMmtelCapability) { |
| 4633 | Phone phone = getPhone(subId); |
| 4634 | if (phone == null) { |
| 4635 | loge("phone instance null for subid " + subId); |
| 4636 | return false; |
| 4637 | } |
| 4638 | if (isMmtelCapability) { |
| 4639 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4640 | return false; |
| 4641 | } |
| 4642 | } else { |
| 4643 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4644 | return false; |
| 4645 | } |
| 4646 | } |
| 4647 | return true; |
| 4648 | } |
| 4649 | |
| 4650 | @Override |
| 4651 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4652 | boolean isProvisioned) { |
| 4653 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4654 | |
| 4655 | final long identity = Binder.clearCallingIdentity(); |
| 4656 | try { |
| 4657 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4658 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4659 | return; |
| 4660 | } |
| 4661 | |
| 4662 | // this capability requires provisioning, route to the correct API. |
| 4663 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4664 | switch (capability) { |
| 4665 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4666 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4667 | ims.setEabProvisioned(isProvisioned); |
| 4668 | break; |
| 4669 | default: { |
| 4670 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4671 | + "rcs capability '" + capability + "', which does not require " |
| 4672 | + "provisioning."); |
| 4673 | } |
| 4674 | } |
| 4675 | } finally { |
| 4676 | Binder.restoreCallingIdentity(identity); |
| 4677 | } |
| 4678 | |
| 4679 | } |
| 4680 | |
| 4681 | |
| 4682 | @Override |
| 4683 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4684 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4685 | final long identity = Binder.clearCallingIdentity(); |
| 4686 | try { |
| 4687 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4688 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4689 | return true; |
| 4690 | } |
| 4691 | |
| 4692 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4693 | switch (capability) { |
| 4694 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4695 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4696 | return ims.isEabProvisionedOnDevice(); |
| 4697 | |
| 4698 | default: { |
| 4699 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4700 | + "capability '" + capability + "', which does not require " |
| 4701 | + "provisioning."); |
| 4702 | } |
| 4703 | } |
| 4704 | |
| 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
| 4707 | } |
| 4708 | } |
| 4709 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4710 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4711 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4712 | boolean isProvisioned) { |
| 4713 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4714 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4715 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4716 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4717 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4718 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4719 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4720 | final long identity = Binder.clearCallingIdentity(); |
| 4721 | try { |
| 4722 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4723 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4724 | return; |
| 4725 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4726 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4727 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4728 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4729 | + "not support provisioning - " + tech); |
| 4730 | return; |
| 4731 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4732 | |
| 4733 | // this capability requires provisioning, route to the correct API. |
| 4734 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4735 | switch (capability) { |
| 4736 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4737 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4738 | ims.setVolteProvisioned(isProvisioned); |
| 4739 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4740 | ims.setWfcProvisioned(isProvisioned); |
| 4741 | } |
| 4742 | break; |
| 4743 | } |
| 4744 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4745 | // There is currently no difference in VT provisioning type. |
| 4746 | ims.setVtProvisioned(isProvisioned); |
| 4747 | break; |
| 4748 | } |
| 4749 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4750 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4751 | // change the capability of the feature instead if needed. |
| 4752 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4753 | == isProvisioned) { |
| 4754 | // No change in provisioning. |
| 4755 | return; |
| 4756 | } |
| 4757 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4758 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4759 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4760 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4761 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4762 | + ", Exception" + e.getMessage()); |
| 4763 | } |
| 4764 | break; |
| 4765 | } |
| 4766 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4767 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4768 | + "MmTel capability '" + capability + "', which does not require " |
| 4769 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4770 | } |
| 4771 | } |
| 4772 | |
| 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
| 4775 | } |
| 4776 | } |
| 4777 | |
| 4778 | @Override |
| 4779 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4780 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4781 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4782 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4783 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4784 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4785 | } |
| 4786 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4787 | final long identity = Binder.clearCallingIdentity(); |
| 4788 | try { |
| 4789 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4790 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4791 | return true; |
| 4792 | } |
| 4793 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4794 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4795 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4796 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4797 | + "not support provisioning - " + tech); |
| 4798 | return true; |
| 4799 | } |
| 4800 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4801 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4802 | switch (capability) { |
| 4803 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4804 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4805 | return ims.isVolteProvisionedOnDevice(); |
| 4806 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4807 | return ims.isWfcProvisionedOnDevice(); |
| 4808 | } |
| 4809 | // This should never happen, since we are checking tech above to make sure it |
| 4810 | // is either LTE or IWLAN. |
| 4811 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4812 | + "capability."); |
| 4813 | } |
| 4814 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4815 | // There is currently no difference in VT provisioning type. |
| 4816 | return ims.isVtProvisionedOnDevice(); |
| 4817 | } |
| 4818 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4819 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4820 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4821 | } |
| 4822 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4823 | throw new IllegalArgumentException( |
| 4824 | "Tried to get provisioning for MmTel capability '" + capability |
| 4825 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4826 | } |
| 4827 | } |
| 4828 | |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | @Override |
| 4835 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4836 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4837 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4838 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4839 | } |
| 4840 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4841 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4842 | return (provisionedBits & capability) > 0; |
| 4843 | } |
| 4844 | |
| 4845 | @Override |
| 4846 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4847 | boolean isProvisioned) { |
| 4848 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4849 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4850 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4851 | } |
| 4852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4853 | "setProvisioningStatusForCapability"); |
| 4854 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4855 | // If the current provisioning status for capability already matches isProvisioned, |
| 4856 | // do nothing. |
| 4857 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4858 | return; |
| 4859 | } |
| 4860 | if (isProvisioned) { |
| 4861 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4862 | } else { |
| 4863 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | /** |
| 4868 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4869 | * technology. The bitfield should mirror the bitfield defined by |
| 4870 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4871 | */ |
| 4872 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4873 | String key = getMmTelProvisioningKey(subId, tech); |
| 4874 | // Default is no capabilities are provisioned. |
| 4875 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4876 | } |
| 4877 | |
| 4878 | /** |
| 4879 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4880 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4881 | * technology specified. |
| 4882 | * |
| 4883 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4884 | */ |
| 4885 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4886 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4887 | String key = getMmTelProvisioningKey(subId, tech); |
| 4888 | editor.putInt(key, newField); |
| 4889 | editor.commit(); |
| 4890 | } |
| 4891 | |
| 4892 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4893 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4894 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4895 | } |
| 4896 | |
| 4897 | /** |
| 4898 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4899 | * carrier associated with the subscription id. |
| 4900 | */ |
| 4901 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4902 | int capability) { |
| 4903 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4904 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4905 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4906 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4907 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4908 | false); |
| 4909 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4910 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4911 | |
| 4912 | // First check to make sure that the capability requires provisioning. |
| 4913 | switch (capability) { |
| 4914 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4915 | // intentional fallthrough |
| 4916 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4917 | if (requireVoiceVtProvisioning) { |
| 4918 | // Voice and Video requires provisioning |
| 4919 | return true; |
| 4920 | } |
| 4921 | break; |
| 4922 | } |
| 4923 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4924 | if (requireUtProvisioning) { |
| 4925 | // UT requires provisioning |
| 4926 | return true; |
| 4927 | } |
| 4928 | break; |
| 4929 | } |
| 4930 | } |
| 4931 | return false; |
| 4932 | } |
| 4933 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4934 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4935 | int capability) { |
| 4936 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4937 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4938 | |
| 4939 | boolean requireRcsProvisioning = c.getBoolean( |
| 4940 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4941 | |
| 4942 | // First check to make sure that the capability requires provisioning. |
| 4943 | switch (capability) { |
| 4944 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4945 | // intentional fallthrough |
| 4946 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4947 | if (requireRcsProvisioning) { |
| 4948 | // OPTION or PRESENCE requires provisioning |
| 4949 | return true; |
| 4950 | } |
| 4951 | break; |
| 4952 | } |
| 4953 | } |
| 4954 | return false; |
| 4955 | } |
| 4956 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4957 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4958 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4959 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4960 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4961 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4962 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
| 4965 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4966 | int slotId = getSlotIndex(subId); |
| 4967 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4968 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4969 | + subId + "' for key:" + key); |
| 4970 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4971 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4972 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4973 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4974 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4975 | + subId + "' for key:" + key); |
| 4976 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
| 4980 | } |
| 4981 | |
| 4982 | @Override |
| 4983 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4984 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4985 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4986 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4987 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
| 4990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4991 | int slotId = getSlotIndex(subId); |
| 4992 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4993 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4994 | + subId + "' for key:" + key); |
| 4995 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4996 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4997 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4998 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4999 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5000 | + subId + "' for key:" + key); |
| 5001 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5002 | } finally { |
| 5003 | Binder.restoreCallingIdentity(identity); |
| 5004 | } |
| 5005 | } |
| 5006 | |
| 5007 | @Override |
| 5008 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5009 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5010 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5011 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5013 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5014 | final long identity = Binder.clearCallingIdentity(); |
| 5015 | try { |
| 5016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5017 | int slotId = getSlotIndex(subId); |
| 5018 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5019 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5020 | + subId + "' for key:" + key); |
| 5021 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5022 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5023 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5024 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5025 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5026 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5027 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5028 | } finally { |
| 5029 | Binder.restoreCallingIdentity(identity); |
| 5030 | } |
| 5031 | } |
| 5032 | |
| 5033 | @Override |
| 5034 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5035 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5036 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5037 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5039 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5040 | final long identity = Binder.clearCallingIdentity(); |
| 5041 | try { |
| 5042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5043 | int slotId = getSlotIndex(subId); |
| 5044 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5045 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5046 | + subId + "' for key:" + key); |
| 5047 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5048 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5049 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5050 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5051 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5052 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5053 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
| 5056 | } |
| 5057 | } |
| 5058 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5059 | /** |
| 5060 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5061 | * for the given slot ID or no ImsResolver instance has been created. |
| 5062 | * @param slotId The slot ID that the IMS service is created for. |
| 5063 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5064 | */ |
| 5065 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5066 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5067 | ImsFeature.FEATURE_MMTEL)) { |
| 5068 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5069 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5070 | } |
| 5071 | } |
| 5072 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5073 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5074 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5075 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5076 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5077 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5078 | } |
| 5079 | return slotId; |
| 5080 | } |
| 5081 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5082 | private int getSlotIndex(int subId) { |
| 5083 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5084 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5085 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5086 | } |
| 5087 | return slotId; |
| 5088 | } |
| 5089 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5090 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5091 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5092 | */ |
| 5093 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5094 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5095 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5096 | try { |
| 5097 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5098 | } catch (SecurityException se) { |
| 5099 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5100 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5101 | + Binder.getCallingUid()); |
| 5102 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5103 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5104 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5105 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5106 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5107 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5108 | mApp, subId, callingPackage, callingFeatureId, |
| 5109 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5110 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5111 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
| 5115 | final Phone phone = getPhone(subId); |
| 5116 | if (phone != null) { |
| 5117 | return phone.getServiceState().getDataNetworkType(); |
| 5118 | } else { |
| 5119 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5120 | } |
| 5121 | } finally { |
| 5122 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5123 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | /** |
| 5127 | * Returns the data network type |
| 5128 | */ |
| 5129 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5130 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5131 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5132 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | /** |
| 5136 | * Returns the data network type for a subId |
| 5137 | */ |
| 5138 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5139 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5140 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5141 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5142 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5143 | mApp, functionName)) { |
| 5144 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5145 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5146 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5147 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
| 5152 | final Phone phone = getPhone(subId); |
| 5153 | if (phone != null) { |
| 5154 | return phone.getServiceState().getDataNetworkType(); |
| 5155 | } else { |
| 5156 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5157 | } |
| 5158 | } finally { |
| 5159 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5160 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5164 | * Returns the Voice network type for a subId |
| 5165 | */ |
| 5166 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5167 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5168 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5169 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5170 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5171 | mApp, functionName)) { |
| 5172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5173 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5174 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5175 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5176 | } |
| 5177 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | final long identity = Binder.clearCallingIdentity(); |
| 5179 | try { |
| 5180 | final Phone phone = getPhone(subId); |
| 5181 | if (phone != null) { |
| 5182 | return phone.getServiceState().getVoiceNetworkType(); |
| 5183 | } else { |
| 5184 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5185 | } |
| 5186 | } finally { |
| 5187 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5188 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | /** |
| 5192 | * @return true if a ICC card is present |
| 5193 | */ |
| 5194 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5195 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5196 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5197 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
| 5200 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5201 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5202 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5203 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5204 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5208 | if (phone != null) { |
| 5209 | return phone.getIccCard().hasIccCard(); |
| 5210 | } else { |
| 5211 | return false; |
| 5212 | } |
| 5213 | } finally { |
| 5214 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * Return if the current radio is LTE on CDMA. This |
| 5220 | * is a tri-state return value as for a period of time |
| 5221 | * the mode may be unknown. |
| 5222 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5223 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5224 | * @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] | 5225 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5226 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5227 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5228 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5229 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5230 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5233 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5234 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5235 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5236 | try { |
| 5237 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5238 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5239 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5240 | } |
| 5241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | final long identity = Binder.clearCallingIdentity(); |
| 5243 | try { |
| 5244 | final Phone phone = getPhone(subId); |
| 5245 | if (phone == null) { |
| 5246 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5247 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5248 | return TelephonyProperties.lte_on_cdma_device() |
| 5249 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | } |
| 5251 | } finally { |
| 5252 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5253 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5254 | } |
| 5255 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5256 | /** |
| 5257 | * {@hide} |
| 5258 | * Returns Default subId, 0 in the case of single standby. |
| 5259 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5260 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5261 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5262 | } |
| 5263 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5264 | private int getSlotForDefaultSubscription() { |
| 5265 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5266 | } |
| 5267 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5268 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5269 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5270 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5271 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5272 | private boolean isActiveSubscription(int subId) { |
| 5273 | return mSubscriptionController.isActiveSubId(subId); |
| 5274 | } |
| 5275 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5276 | /** |
| 5277 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5278 | */ |
| 5279 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5280 | final long identity = Binder.clearCallingIdentity(); |
| 5281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5283 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5284 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5285 | } finally { |
| 5286 | Binder.restoreCallingIdentity(identity); |
| 5287 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | /** |
| 5291 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5292 | */ |
| 5293 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
| 5296 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5297 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5299 | } finally { |
| 5300 | Binder.restoreCallingIdentity(identity); |
| 5301 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5302 | } |
| 5303 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5304 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5305 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5306 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5307 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5308 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5309 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5310 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5311 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5312 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5313 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5314 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5315 | } |
| 5316 | return PhoneFactory.getPhone(phoneId); |
| 5317 | } |
| 5318 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5319 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5320 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5321 | @NonNull IccLogicalChannelRequest request) { |
| 5322 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5323 | /*message=*/ "iccOpenLogicalChannel"); |
| 5324 | |
| 5325 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5326 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5327 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5328 | |
| 5329 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5330 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5331 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5332 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5333 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5334 | Phone phone; |
| 5335 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5337 | mApp, request.subId, message); |
| 5338 | phone = getPhoneFromSubId(request.subId); |
| 5339 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5340 | enforceModifyPermission(); |
| 5341 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5342 | } else { |
| 5343 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5344 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5345 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5349 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5350 | final long identity = Binder.clearCallingIdentity(); |
| 5351 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5352 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5354 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5355 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5356 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5357 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | loge("The calling package is not allowed to access ISD-R."); |
| 5359 | throw new SecurityException( |
| 5360 | "The calling package is not allowed to access ISD-R."); |
| 5361 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5362 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5365 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5366 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | return response; |
| 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5371 | } |
| 5372 | |
| 5373 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5374 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5375 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5376 | /*message=*/"iccCloseLogicalChannel"); |
| 5377 | |
| 5378 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5379 | |
| 5380 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5381 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5382 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5383 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5384 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5387 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5388 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5390 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5391 | null /* workSource */); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5392 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5393 | return success; |
| 5394 | } finally { |
| 5395 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5396 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5400 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5401 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5402 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5403 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5404 | if (DBG) { |
| 5405 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5406 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5407 | + p3 + " data=" + data); |
| 5408 | } |
| 5409 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5410 | command, p1, p2, p3, data); |
| 5411 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5412 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5413 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5414 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5415 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5416 | enforceModifyPermission(); |
| 5417 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5418 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5419 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5420 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5421 | } |
| 5422 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5423 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5424 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5428 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5431 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | return ""; |
| 5433 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5434 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5436 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5437 | null /* workSource */); |
| 5438 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | // Append the returned status code to the end of the response payload. |
| 5441 | String s = Integer.toHexString( |
| 5442 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5443 | if (response.payload != null) { |
| 5444 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5445 | } |
| 5446 | return s; |
| 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5449 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5450 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5451 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5452 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5453 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5454 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5456 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5458 | if (DBG) { |
| 5459 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5460 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5461 | } |
| 5462 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5463 | cla, command, p1, p2, p3, data); |
| 5464 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5465 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5466 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5467 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5468 | String callingPackage, int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5469 | enforceModifyPermission(); |
| 5470 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5471 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5472 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5473 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5474 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5478 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5479 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5483 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5484 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | final long identity = Binder.clearCallingIdentity(); |
| 5486 | try { |
| 5487 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5488 | && TextUtils.equals(ISDR_AID, data)) { |
| 5489 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5490 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5491 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5492 | if (bestComponent == null |
| 5493 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5494 | loge("The calling package is not allowed to select ISD-R."); |
| 5495 | throw new SecurityException( |
| 5496 | "The calling package is not allowed to select ISD-R."); |
| 5497 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5498 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5501 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5502 | null /* workSource */); |
| 5503 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5504 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | // Append the returned status code to the end of the response payload. |
| 5506 | String s = Integer.toHexString( |
| 5507 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5508 | if (response.payload != null) { |
| 5509 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5510 | } |
| 5511 | return s; |
| 5512 | } finally { |
| 5513 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5514 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5515 | } |
| 5516 | |
| 5517 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5518 | 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] | 5519 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5521 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5522 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); |
| 5524 | try { |
| 5525 | if (DBG) { |
| 5526 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5527 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5528 | } |
| 5529 | |
| 5530 | IccIoResult response = |
| 5531 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5532 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5533 | subId); |
| 5534 | |
| 5535 | if (DBG) { |
| 5536 | log("Exchange SIM_IO [R]" + response); |
| 5537 | } |
| 5538 | |
| 5539 | byte[] result = null; |
| 5540 | int length = 2; |
| 5541 | if (response.payload != null) { |
| 5542 | length = 2 + response.payload.length; |
| 5543 | result = new byte[length]; |
| 5544 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5545 | } else { |
| 5546 | result = new byte[length]; |
| 5547 | } |
| 5548 | |
| 5549 | result[length - 1] = (byte) response.sw2; |
| 5550 | result[length - 2] = (byte) response.sw1; |
| 5551 | return result; |
| 5552 | } finally { |
| 5553 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5554 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5557 | /** |
| 5558 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5559 | * on a particular subscription |
| 5560 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5561 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5562 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5563 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5564 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5565 | return null; |
| 5566 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | |
| 5568 | final long identity = Binder.clearCallingIdentity(); |
| 5569 | try { |
| 5570 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5571 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5572 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5573 | return null; |
| 5574 | } |
| 5575 | Object response = sendRequest( |
| 5576 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5577 | if (response instanceof String[]) { |
| 5578 | return (String[]) response; |
| 5579 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5580 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5581 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5582 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5585 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5588 | /** |
| 5589 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5590 | * subscription. |
| 5591 | * |
| 5592 | * @param subId the id of the subscription. |
| 5593 | * @param appType the uicc app type, must be USIM or SIM. |
| 5594 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5595 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5596 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5597 | * @return number of fplmns that is successfully written to the SIM. |
| 5598 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5599 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5600 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5601 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5602 | mApp, subId, "setForbiddenPlmns"); |
| 5603 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5604 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5605 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5606 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5607 | } |
| 5608 | if (fplmns == null) { |
| 5609 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5610 | } |
| 5611 | for (String fplmn : fplmns) { |
| 5612 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5613 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5614 | } |
| 5615 | } |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
| 5618 | Object response = sendRequest( |
| 5619 | CMD_SET_FORBIDDEN_PLMNS, |
| 5620 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5621 | subId); |
| 5622 | return (int) response; |
| 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
| 5626 | } |
| 5627 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5628 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5629 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5631 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5632 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5636 | if (response.payload == null) { |
| 5637 | return ""; |
| 5638 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | // Append the returned status code to the end of the response payload. |
| 5641 | String s = Integer.toHexString( |
| 5642 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5643 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5644 | return s; |
| 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(identity); |
| 5647 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5648 | } |
| 5649 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5650 | /** |
| 5651 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5652 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5653 | * |
| 5654 | * @param itemID the ID of the item to read |
| 5655 | * @return the NV item as a String, or null on error. |
| 5656 | */ |
| 5657 | @Override |
| 5658 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5659 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5661 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5662 | |
| 5663 | final long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
| 5665 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5666 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5668 | return value; |
| 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | /** |
| 5675 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5676 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5677 | * |
| 5678 | * @param itemID the ID of the item to read |
| 5679 | * @param itemValue the value to write, as a String |
| 5680 | * @return true on success; false on any failure |
| 5681 | */ |
| 5682 | @Override |
| 5683 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5684 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5686 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | |
| 5688 | final long identity = Binder.clearCallingIdentity(); |
| 5689 | try { |
| 5690 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5691 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5692 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5693 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5694 | return success; |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /** |
| 5701 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5702 | * Used for device configuration by some CDMA operators. |
| 5703 | * |
| 5704 | * @param preferredRoamingList byte array containing the new PRL |
| 5705 | * @return true on success; false on any failure |
| 5706 | */ |
| 5707 | @Override |
| 5708 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5709 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5710 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | |
| 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
| 5714 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5715 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5716 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5717 | return success; |
| 5718 | } finally { |
| 5719 | Binder.restoreCallingIdentity(identity); |
| 5720 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5724 | * 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] | 5725 | * Used for device configuration by some CDMA operators. |
| 5726 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5727 | * @param slotIndex - device slot. |
| 5728 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5729 | * @return true on success; false on any failure |
| 5730 | */ |
| 5731 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5732 | public boolean resetModemConfig(int slotIndex) { |
| 5733 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5734 | if (phone != null) { |
| 5735 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5736 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
| 5740 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5741 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5742 | return success; |
| 5743 | } finally { |
| 5744 | Binder.restoreCallingIdentity(identity); |
| 5745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5746 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5747 | return false; |
| 5748 | } |
| 5749 | |
| 5750 | /** |
| 5751 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5752 | * |
| 5753 | * @param slotIndex - device slot. |
| 5754 | * |
| 5755 | * @return true on success; false on any failure |
| 5756 | */ |
| 5757 | @Override |
| 5758 | public boolean rebootModem(int slotIndex) { |
| 5759 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5760 | if (phone != null) { |
| 5761 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5762 | mApp, phone.getSubId(), "rebootModem"); |
| 5763 | |
| 5764 | final long identity = Binder.clearCallingIdentity(); |
| 5765 | try { |
| 5766 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5767 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5768 | return success; |
| 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
| 5772 | } |
| 5773 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5774 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5775 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5776 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5777 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5778 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5779 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5780 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5781 | return new String[0]; |
| 5782 | } |
| 5783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5786 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
| 5789 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5792 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5793 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5794 | * {@link #disableIms(int)}. |
| 5795 | * @param slotIndex device slot. |
| 5796 | */ |
| 5797 | public void resetIms(int slotIndex) { |
| 5798 | enforceModifyPermission(); |
| 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | if (mImsResolver == null) { |
| 5803 | // may happen if the does not support IMS. |
| 5804 | return; |
| 5805 | } |
| 5806 | mImsResolver.disableIms(slotIndex); |
| 5807 | mImsResolver.enableIms(slotIndex); |
| 5808 | } finally { |
| 5809 | Binder.restoreCallingIdentity(identity); |
| 5810 | } |
| 5811 | } |
| 5812 | |
| 5813 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5814 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5815 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5816 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5817 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | |
| 5820 | final long identity = Binder.clearCallingIdentity(); |
| 5821 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5822 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5823 | // may happen if the device does not support IMS. |
| 5824 | return; |
| 5825 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5826 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(identity); |
| 5829 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5833 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5834 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5835 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5836 | public void disableIms(int slotId) { |
| 5837 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | |
| 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5841 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5842 | // may happen if the device does not support IMS. |
| 5843 | return; |
| 5844 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5845 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
| 5848 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5852 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5853 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5854 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5855 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5856 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5857 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5861 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5862 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5863 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5864 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5865 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
| 5868 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5869 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5870 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5871 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5872 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5873 | @Override |
| 5874 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5875 | enforceModifyPermission(); |
| 5876 | |
| 5877 | final long identity = Binder.clearCallingIdentity(); |
| 5878 | try { |
| 5879 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5880 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5887 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5888 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5889 | */ |
| 5890 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5891 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5892 | |
| 5893 | final long identity = Binder.clearCallingIdentity(); |
| 5894 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5895 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5896 | // may happen if the device does not support IMS. |
| 5897 | return null; |
| 5898 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5899 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5900 | } finally { |
| 5901 | Binder.restoreCallingIdentity(identity); |
| 5902 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5903 | } |
| 5904 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5905 | /** |
| 5906 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5907 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5908 | */ |
| 5909 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5910 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5911 | |
| 5912 | final long identity = Binder.clearCallingIdentity(); |
| 5913 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5914 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5915 | // may happen if the device does not support IMS. |
| 5916 | return null; |
| 5917 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5918 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | } finally { |
| 5920 | Binder.restoreCallingIdentity(identity); |
| 5921 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5922 | } |
| 5923 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5924 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5925 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5926 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5928 | * @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] | 5929 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5930 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5931 | * @param packageName The name of the package that the current configuration will be replaced |
| 5932 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5933 | * @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] | 5934 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5935 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5936 | int[] featureTypes, String packageName) { |
| 5937 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5938 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5939 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5940 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5941 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | final long identity = Binder.clearCallingIdentity(); |
| 5944 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5945 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5946 | // may happen if the device does not support IMS. |
| 5947 | return false; |
| 5948 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5949 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5950 | for (int featureType : featureTypes) { |
| 5951 | featureConfig.put(featureType, packageName); |
| 5952 | } |
| 5953 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5954 | featureConfig); |
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 | |
| 5960 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5961 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5962 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5963 | * |
| 5964 | * This should only be used for testing. |
| 5965 | * |
| 5966 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5967 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5968 | */ |
| 5969 | @Override |
| 5970 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5971 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5972 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5973 | "clearCarrierImsServiceOverride"); |
| 5974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5975 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5976 | "clearCarrierImsServiceOverride"); |
| 5977 | |
| 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | try { |
| 5980 | if (mImsResolver == null) { |
| 5981 | // may happen if the device does not support IMS. |
| 5982 | return false; |
| 5983 | } |
| 5984 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5985 | } finally { |
| 5986 | Binder.restoreCallingIdentity(identity); |
| 5987 | } |
| 5988 | } |
| 5989 | |
| 5990 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5991 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5992 | * |
| 5993 | * @param slotId The slot that the ImsService is associated with. |
| 5994 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5995 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5996 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5997 | * @return the package name of the ImsService configuration. |
| 5998 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5999 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6000 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6001 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6002 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6003 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6004 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6005 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6006 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | final long identity = Binder.clearCallingIdentity(); |
| 6008 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6009 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6010 | // may happen if the device does not support IMS. |
| 6011 | return ""; |
| 6012 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6013 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6014 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6015 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6016 | } finally { |
| 6017 | Binder.restoreCallingIdentity(identity); |
| 6018 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6019 | } |
| 6020 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6021 | /** |
| 6022 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6023 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6024 | * @param callback A callback with an integer containing the |
| 6025 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6026 | */ |
| 6027 | @Override |
| 6028 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6029 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 6030 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6031 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6032 | "IMS not available on device."); |
| 6033 | } |
| 6034 | final long token = Binder.clearCallingIdentity(); |
| 6035 | try { |
| 6036 | int slotId = getSlotIndex(subId); |
| 6037 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6038 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6039 | + subId + "'"); |
| 6040 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6041 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6042 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6043 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6044 | try { |
| 6045 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6046 | } catch (RemoteException e) { |
| 6047 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6048 | + "Ignore"); |
| 6049 | } |
| 6050 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6051 | } catch (ImsException e) { |
| 6052 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(token); |
| 6055 | } |
| 6056 | } |
| 6057 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6058 | /** |
| 6059 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6060 | */ |
| 6061 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6063 | |
| 6064 | final long identity = Binder.clearCallingIdentity(); |
| 6065 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6066 | // NOTE: Before S, this method only set the default phone. |
| 6067 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6068 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6069 | phone.setImsRegistrationState(registered); |
| 6070 | } |
| 6071 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | } finally { |
| 6073 | Binder.restoreCallingIdentity(identity); |
| 6074 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6078 | * Set the network selection mode to automatic. |
| 6079 | * |
| 6080 | */ |
| 6081 | @Override |
| 6082 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6084 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | |
| 6086 | final long identity = Binder.clearCallingIdentity(); |
| 6087 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6088 | if (!isActiveSubscription(subId)) { |
| 6089 | return; |
| 6090 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6092 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6093 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | } finally { |
| 6095 | Binder.restoreCallingIdentity(identity); |
| 6096 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6099 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6100 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6101 | * |
| 6102 | * @param subId the id of the subscription. |
| 6103 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6104 | * the operator to attach to. |
| 6105 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6106 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6107 | * normal network selection next time. |
| 6108 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6109 | */ |
| 6110 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6111 | public boolean setNetworkSelectionModeManual( |
| 6112 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6114 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6115 | |
| 6116 | if (!isActiveSubscription(subId)) { |
| 6117 | return false; |
| 6118 | } |
| 6119 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6120 | final long identity = Binder.clearCallingIdentity(); |
| 6121 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6122 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6124 | if (DBG) { |
| 6125 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6126 | + " operator: " + operatorInfo); |
| 6127 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6132 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6133 | /** |
| 6134 | * Get the manual network selection |
| 6135 | * |
| 6136 | * @param subId the id of the subscription. |
| 6137 | * |
| 6138 | * @return the previously saved user selected PLMN |
| 6139 | */ |
| 6140 | @Override |
| 6141 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6142 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6143 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6144 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6145 | |
| 6146 | final long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6149 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6150 | } |
| 6151 | |
| 6152 | final Phone phone = getPhone(subId); |
| 6153 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6154 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6155 | } |
| 6156 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6157 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6158 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6159 | } finally { |
| 6160 | Binder.restoreCallingIdentity(identity); |
| 6161 | } |
| 6162 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6163 | |
| 6164 | /** |
| 6165 | * Scans for available networks. |
| 6166 | */ |
| 6167 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6168 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6169 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6171 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6172 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6173 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6174 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6175 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6176 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6177 | .setCallingPid(Binder.getCallingPid()) |
| 6178 | .setCallingUid(Binder.getCallingUid()) |
| 6179 | .setMethod("getCellNetworkScanResults") |
| 6180 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6181 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6182 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6183 | .build()); |
| 6184 | switch (locationResult) { |
| 6185 | case DENIED_HARD: |
| 6186 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6187 | case DENIED_SOFT: |
| 6188 | return null; |
| 6189 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6190 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6191 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | try { |
| 6193 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6194 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6195 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6202 | * Get the call forwarding info, given the call forwarding reason. |
| 6203 | */ |
| 6204 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6205 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6206 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6207 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6208 | long identity = Binder.clearCallingIdentity(); |
| 6209 | try { |
| 6210 | if (DBG) { |
| 6211 | log("getCallForwarding: subId " + subId |
| 6212 | + " callForwardingReason" + callForwardingReason); |
| 6213 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6214 | |
| 6215 | Phone phone = getPhone(subId); |
| 6216 | if (phone == null) { |
| 6217 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6218 | callback.onError( |
| 6219 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6220 | } catch (RemoteException e) { |
| 6221 | // ignore |
| 6222 | } |
| 6223 | return; |
| 6224 | } |
| 6225 | |
| 6226 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6227 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6228 | @Override |
| 6229 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6230 | try { |
| 6231 | callback.onCallForwardingInfoAvailable(info); |
| 6232 | } catch (RemoteException e) { |
| 6233 | // ignore |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | @Override |
| 6238 | public void onError(int error) { |
| 6239 | try { |
| 6240 | callback.onError(error); |
| 6241 | } catch (RemoteException e) { |
| 6242 | // ignore |
| 6243 | } |
| 6244 | } |
| 6245 | }); |
| 6246 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6247 | } finally { |
| 6248 | Binder.restoreCallingIdentity(identity); |
| 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | /** |
| 6253 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6254 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6255 | */ |
| 6256 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6257 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6258 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6259 | enforceModifyPermission(); |
| 6260 | long identity = Binder.clearCallingIdentity(); |
| 6261 | try { |
| 6262 | if (DBG) { |
| 6263 | log("setCallForwarding: subId " + subId |
| 6264 | + " callForwardingInfo" + callForwardingInfo); |
| 6265 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6266 | |
| 6267 | Phone phone = getPhone(subId); |
| 6268 | if (phone == null) { |
| 6269 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6270 | callback.accept( |
| 6271 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6272 | } catch (RemoteException e) { |
| 6273 | // ignore |
| 6274 | } |
| 6275 | return; |
| 6276 | } |
| 6277 | |
| 6278 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6279 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6280 | |
| 6281 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
| 6284 | } |
| 6285 | } |
| 6286 | |
| 6287 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6288 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6289 | */ |
| 6290 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6291 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6292 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6293 | long identity = Binder.clearCallingIdentity(); |
| 6294 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6295 | Phone phone = getPhone(subId); |
| 6296 | if (phone == null) { |
| 6297 | try { |
| 6298 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6299 | } catch (RemoteException e) { |
| 6300 | // ignore |
| 6301 | } |
| 6302 | return; |
| 6303 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6304 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6305 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6306 | boolean requireUssd = c.getBoolean( |
| 6307 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6308 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6309 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6310 | if (requireUssd) { |
| 6311 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6312 | getSubscriptionCarrierId(subId)); |
| 6313 | String newUssdCommand = ""; |
| 6314 | try { |
| 6315 | newUssdCommand = carrierXmlParser.getFeature( |
| 6316 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6317 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6318 | } catch (NullPointerException e) { |
| 6319 | loge("Failed to generate USSD number" + e); |
| 6320 | } |
| 6321 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6322 | mMainThreadHandler, callback, carrierXmlParser, |
| 6323 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6324 | final String ussdCommand = newUssdCommand; |
| 6325 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6326 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6327 | }); |
| 6328 | } else { |
| 6329 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6330 | callback::accept); |
| 6331 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6332 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
| 6335 | } |
| 6336 | } |
| 6337 | |
| 6338 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6339 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6340 | */ |
| 6341 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6342 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6343 | enforceModifyPermission(); |
| 6344 | long identity = Binder.clearCallingIdentity(); |
| 6345 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6346 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6347 | |
| 6348 | Phone phone = getPhone(subId); |
| 6349 | if (phone == null) { |
| 6350 | try { |
| 6351 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6352 | } catch (RemoteException e) { |
| 6353 | // ignore |
| 6354 | } |
| 6355 | return; |
| 6356 | } |
| 6357 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6358 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6359 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6360 | boolean requireUssd = c.getBoolean( |
| 6361 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6362 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6363 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6364 | if (requireUssd) { |
| 6365 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6366 | getSubscriptionCarrierId(subId)); |
| 6367 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6368 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6369 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6370 | String newUssdCommand = ""; |
| 6371 | try { |
| 6372 | newUssdCommand = carrierXmlParser.getFeature( |
| 6373 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6374 | .makeCommand(ssAction, null); |
| 6375 | } catch (NullPointerException e) { |
| 6376 | loge("Failed to generate USSD number" + e); |
| 6377 | } |
| 6378 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6379 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6380 | final String ussdCommand = newUssdCommand; |
| 6381 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6382 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6383 | }); |
| 6384 | } else { |
| 6385 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6386 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6387 | |
| 6388 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6389 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
| 6393 | } |
| 6394 | |
| 6395 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6396 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6397 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6398 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6399 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6400 | * location related information which will be sent if the caller already possess |
| 6401 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6402 | * @param request contains the radio access networks with bands/channels to scan |
| 6403 | * @param messenger callback messenger for scan results or errors |
| 6404 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6405 | * @return the id of the requested scan which can be used to stop the scan. |
| 6406 | */ |
| 6407 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6408 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6409 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6410 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6412 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6413 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6414 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6415 | if (!renounceFineLocationAccess) { |
| 6416 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6417 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6418 | .setCallingPackage(callingPackage) |
| 6419 | .setCallingFeatureId(callingFeatureId) |
| 6420 | .setCallingPid(Binder.getCallingPid()) |
| 6421 | .setCallingUid(Binder.getCallingUid()) |
| 6422 | .setMethod("requestNetworkScan") |
| 6423 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6424 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6425 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6426 | .build()); |
| 6427 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6428 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6429 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6430 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6431 | if (e != null) { |
| 6432 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6433 | throw e; |
| 6434 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6435 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6436 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6437 | } |
| 6438 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6439 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6440 | int callingUid = Binder.getCallingUid(); |
| 6441 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6442 | final long identity = Binder.clearCallingIdentity(); |
| 6443 | try { |
| 6444 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6445 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6446 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6450 | } |
| 6451 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6452 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6453 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6454 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6455 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6456 | boolean hasNetworkScanPermission = |
| 6457 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6458 | == PERMISSION_GRANTED; |
| 6459 | |
| 6460 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6461 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6462 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6463 | } |
| 6464 | |
| 6465 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6466 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6467 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6468 | return new SecurityException("Specific channels must not be" |
| 6469 | + " scanned without location access."); |
| 6470 | } |
| 6471 | } |
| 6472 | } |
| 6473 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6474 | return null; |
| 6475 | } |
| 6476 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6477 | /** |
| 6478 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6479 | * |
| 6480 | * @param subId id of the subscription |
| 6481 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6482 | */ |
| 6483 | @Override |
| 6484 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6485 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6486 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6487 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6488 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6489 | final long identity = Binder.clearCallingIdentity(); |
| 6490 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6491 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6492 | } finally { |
| 6493 | Binder.restoreCallingIdentity(identity); |
| 6494 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6495 | } |
| 6496 | |
| 6497 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6498 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6499 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6500 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6501 | */ |
| 6502 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6503 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6504 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6505 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6506 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 | |
| 6508 | final long identity = Binder.clearCallingIdentity(); |
| 6509 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6510 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6511 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6512 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6513 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6514 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6515 | } finally { |
| 6516 | Binder.restoreCallingIdentity(identity); |
| 6517 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6521 | * Get the allowed network types for certain reason. |
| 6522 | * |
| 6523 | * @param subId the id of the subscription. |
| 6524 | * @param reason the reason the allowed network type change is taking place |
| 6525 | * @return the allowed network types. |
| 6526 | */ |
| 6527 | @Override |
| 6528 | public long getAllowedNetworkTypesForReason(int subId, |
| 6529 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6530 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6531 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6532 | final long identity = Binder.clearCallingIdentity(); |
| 6533 | try { |
| 6534 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6541 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6542 | * @param subId subscription id of the sim card |
| 6543 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6544 | * This can be passed following states |
| 6545 | * <ol> |
| 6546 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6547 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6548 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6549 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6550 | * </ol> |
| 6551 | * @return operation result. |
| 6552 | */ |
| 6553 | @Override |
| 6554 | public int setNrDualConnectivityState(int subId, |
| 6555 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6556 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6557 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6558 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6559 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6560 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6561 | } |
| 6562 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6563 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6564 | final long identity = Binder.clearCallingIdentity(); |
| 6565 | try { |
| 6566 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6567 | nrDualConnectivityState, subId, |
| 6568 | workSource); |
| 6569 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6570 | return result; |
| 6571 | } finally { |
| 6572 | Binder.restoreCallingIdentity(identity); |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | /** |
| 6577 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6578 | * @return true if dual connectivity is enabled else false |
| 6579 | */ |
| 6580 | @Override |
| 6581 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6582 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6583 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6584 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6585 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6586 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6587 | return false; |
| 6588 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6589 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6590 | final long identity = Binder.clearCallingIdentity(); |
| 6591 | try { |
| 6592 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6593 | null, subId, workSource); |
| 6594 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6595 | return isEnabled; |
| 6596 | } finally { |
| 6597 | Binder.restoreCallingIdentity(identity); |
| 6598 | } |
| 6599 | } |
| 6600 | |
| 6601 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6602 | * Set the allowed network types of the device and |
| 6603 | * provide the reason triggering the allowed network change. |
| 6604 | * |
| 6605 | * @param subId the id of the subscription. |
| 6606 | * @param reason the reason the allowed network type change is taking place |
| 6607 | * @param allowedNetworkTypes the allowed network types. |
| 6608 | * @return true on success; false on any failure. |
| 6609 | */ |
| 6610 | @Override |
| 6611 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6612 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6613 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6615 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6616 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6617 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6618 | return false; |
| 6619 | } |
| 6620 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6621 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6622 | return false; |
| 6623 | } |
| 6624 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6625 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6626 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6627 | |
| 6628 | |
| 6629 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6630 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6631 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6632 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6633 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6636 | Boolean success = (Boolean) sendRequest( |
| 6637 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6638 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6639 | |
| 6640 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6641 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6642 | } finally { |
| 6643 | Binder.restoreCallingIdentity(identity); |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6648 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6649 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6650 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6651 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6652 | * @hide |
| 6653 | */ |
| 6654 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6655 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6656 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6658 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6660 | if (phone != null) { |
| 6661 | return phone.hasMatchedTetherApnSetting(); |
| 6662 | } else { |
| 6663 | return false; |
| 6664 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6667 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6671 | * Get the user enabled state of Mobile Data. |
| 6672 | * |
| 6673 | * TODO: remove and use isUserDataEnabled. |
| 6674 | * This can't be removed now because some vendor codes |
| 6675 | * calls through ITelephony directly while they should |
| 6676 | * use TelephonyManager. |
| 6677 | * |
| 6678 | * @return true on enabled |
| 6679 | */ |
| 6680 | @Override |
| 6681 | public boolean getDataEnabled(int subId) { |
| 6682 | return isUserDataEnabled(subId); |
| 6683 | } |
| 6684 | |
| 6685 | /** |
| 6686 | * Get whether mobile data is enabled per user setting. |
| 6687 | * |
| 6688 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6689 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6690 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6691 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6692 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6693 | * |
| 6694 | * @return {@code true} if data is enabled else {@code false} |
| 6695 | */ |
| 6696 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6697 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6698 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6699 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6700 | try { |
| 6701 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6702 | functionName); |
| 6703 | } catch (Exception e) { |
| 6704 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6705 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6706 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6707 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6708 | mApp, subId, functionName); |
| 6709 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6711 | |
| 6712 | final long identity = Binder.clearCallingIdentity(); |
| 6713 | try { |
| 6714 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6715 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6716 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6717 | if (phone != null) { |
| 6718 | boolean retVal = phone.isUserDataEnabled(); |
| 6719 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6720 | return retVal; |
| 6721 | } else { |
| 6722 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6723 | return false; |
| 6724 | } |
| 6725 | } finally { |
| 6726 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6731 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6732 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6733 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6734 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6735 | * @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] | 6736 | */ |
| 6737 | @Override |
| 6738 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6739 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6740 | try { |
| 6741 | try { |
| 6742 | mApp.enforceCallingOrSelfPermission( |
| 6743 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6744 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6745 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6746 | try { |
| 6747 | mApp.enforceCallingOrSelfPermission( |
| 6748 | android.Manifest.permission.READ_PHONE_STATE, |
| 6749 | functionName); |
| 6750 | } catch (Exception e2) { |
| 6751 | mApp.enforceCallingOrSelfPermission( |
| 6752 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6753 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6754 | } |
| 6755 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6756 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6757 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6758 | |
| 6759 | final long identity = Binder.clearCallingIdentity(); |
| 6760 | try { |
| 6761 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6763 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6764 | boolean retVal; |
| 6765 | if (phone.isUsingNewDataStack()) { |
| 6766 | retVal = phone.getDataNetworkController().getDataSettingsManager() |
| 6767 | .isDataEnabled(); |
| 6768 | } else { |
| 6769 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6770 | } |
| 6771 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | return retVal; |
| 6773 | } else { |
| 6774 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6775 | return false; |
| 6776 | } |
| 6777 | } finally { |
| 6778 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6779 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6780 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6781 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6782 | /** |
| 6783 | * Check if data is enabled for a specific reason |
| 6784 | * @param subId Subscription index |
| 6785 | * @param reason the reason the data enable change is taking place |
| 6786 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6787 | */ |
| 6788 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6789 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6790 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6791 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6792 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6793 | try { |
| 6794 | mApp.enforceCallingOrSelfPermission( |
| 6795 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6796 | functionName); |
| 6797 | } catch (Exception e) { |
| 6798 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6799 | functionName); |
| 6800 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6801 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6802 | try { |
| 6803 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6804 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6805 | } catch (Exception e2) { |
| 6806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6807 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6808 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6809 | } |
| 6810 | |
| 6811 | |
| 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
| 6814 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6815 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6816 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6817 | + " reason=" + reason); |
| 6818 | } |
| 6819 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6820 | if (phone != null) { |
| 6821 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6822 | if (phone.isUsingNewDataStack()) { |
| 6823 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6824 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6825 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6826 | retVal = phone.isUserDataEnabled(); |
| 6827 | } else { |
| 6828 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6829 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6830 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6831 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6832 | return retVal; |
| 6833 | } else { |
| 6834 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6835 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6836 | + subId + " retVal=false"); |
| 6837 | } |
| 6838 | return false; |
| 6839 | } |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
| 6842 | } |
| 6843 | } |
| 6844 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6845 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6846 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6847 | if (uid == Process.PHONE_UID) { |
| 6848 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6849 | // 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] | 6850 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6851 | } |
| 6852 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6853 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6854 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6855 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6856 | || subController == null) return privilegeFromSim; |
| 6857 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6858 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6859 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6860 | |
| 6861 | final long identity = Binder.clearCallingIdentity(); |
| 6862 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6863 | int subId = phone.getSubId(); |
| 6864 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6865 | // A test override is in place for the privileges for this subId, so don't try to |
| 6866 | // read the subscription privileges. |
| 6867 | return privilegeFromSim; |
| 6868 | } |
| 6869 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6870 | SubscriptionManager subManager = (SubscriptionManager) |
| 6871 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6872 | for (String pkg : packages) { |
| 6873 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6874 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6875 | } |
| 6876 | } |
| 6877 | return privilegeFromSim; |
| 6878 | } finally { |
| 6879 | Binder.restoreCallingIdentity(identity); |
| 6880 | } |
| 6881 | } |
| 6882 | |
| 6883 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6884 | String pkgName) { |
| 6885 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6886 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6887 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6888 | || subController == null) return privilegeFromSim; |
| 6889 | |
| 6890 | final long identity = Binder.clearCallingIdentity(); |
| 6891 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6892 | int subId = phone.getSubId(); |
| 6893 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6894 | // A test override is in place for the privileges for this subId, so don't try to |
| 6895 | // read the subscription privileges. |
| 6896 | return privilegeFromSim; |
| 6897 | } |
| 6898 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6899 | SubscriptionManager subManager = (SubscriptionManager) |
| 6900 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6901 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6902 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6903 | } finally { |
| 6904 | Binder.restoreCallingIdentity(identity); |
| 6905 | } |
| 6906 | } |
| 6907 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6908 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6909 | public int getCarrierPrivilegeStatus(int subId) { |
| 6910 | final Phone phone = getPhone(subId); |
| 6911 | if (phone == null) { |
| 6912 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6913 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6914 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6915 | UiccPort port = UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
| 6916 | if (port == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6917 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6918 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6919 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6920 | |
| 6921 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6922 | port.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6923 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6924 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6925 | |
| 6926 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6927 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6928 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6929 | final Phone phone = getPhone(subId); |
| 6930 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6931 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6932 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6933 | } |
| 6934 | UiccProfile profile = |
| 6935 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6936 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6937 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6938 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6939 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6940 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6941 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6942 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6943 | } |
| 6944 | |
| 6945 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6946 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6947 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6948 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6949 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6953 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6954 | if (port == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6955 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6956 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6957 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6958 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6959 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6960 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | @Override |
| 6964 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6965 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6966 | if (TextUtils.isEmpty(pkgName)) |
| 6967 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6968 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6969 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6970 | UiccPort port = UiccController.getInstance().getUiccPort(i); |
| 6971 | if (port == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6972 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6973 | continue; |
| 6974 | } |
| 6975 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6976 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6977 | port.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6978 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6979 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6980 | break; |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6985 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6986 | |
| 6987 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6988 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6989 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6990 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6991 | loge("phoneId " + phoneId + " is not valid."); |
| 6992 | return null; |
| 6993 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6994 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
| 6995 | if (port == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6996 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6997 | return null ; |
| 6998 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6999 | return port.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7000 | } |
| 7001 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7002 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7003 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7004 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7005 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7006 | List<String> privilegedPackages = new ArrayList<>(); |
| 7007 | List<PackageInfo> packages = null; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7008 | UiccPort port = UiccController.getInstance().getUiccPort(phoneId); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7009 | // has UICC in that slot. |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7010 | if (port != null) { |
| 7011 | if (port.hasCarrierPrivilegeRules()) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7012 | if (packages == null) { |
| 7013 | // Only check packages in user 0 for now |
| 7014 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 7015 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 7016 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 7017 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7018 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7019 | } |
| 7020 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 7021 | PackageInfo pkgInfo = packages.get(p); |
| 7022 | if (pkgInfo != null && pkgInfo.packageName != null |
Sooraj Sasindran | 97bce6f | 2021-09-28 21:37:29 +0000 | [diff] [blame] | 7023 | && getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 7024 | port.getCarrierPrivilegeStatus(pkgInfo), |
| 7025 | getPhone(phoneId), pkgInfo.packageName) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7026 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7027 | privilegedPackages.add(pkgInfo.packageName); |
| 7028 | } |
| 7029 | } |
| 7030 | } |
| 7031 | } |
| 7032 | return privilegedPackages; |
| 7033 | } |
| 7034 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7035 | @Override |
| 7036 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7037 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 7038 | |
| 7039 | final long identity = Binder.clearCallingIdentity(); |
| 7040 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7041 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7042 | try { |
| 7043 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7044 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7045 | } |
| 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7048 | } |
| 7049 | return privilegedPackages; |
| 7050 | } |
| 7051 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7052 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7053 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7054 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7055 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7056 | return null; |
| 7057 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7058 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7059 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7060 | return null; |
| 7061 | } |
| 7062 | return iccId; |
| 7063 | } |
| 7064 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7065 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7066 | public void setCallComposerStatus(int subId, int status) { |
| 7067 | enforceModifyPermission(); |
| 7068 | |
| 7069 | final long identity = Binder.clearCallingIdentity(); |
| 7070 | try { |
| 7071 | Phone phone = getPhone(subId); |
| 7072 | if (phone != null) { |
| 7073 | Phone defaultPhone = phone.getImsPhone(); |
| 7074 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7075 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7076 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7077 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7078 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7079 | } |
| 7080 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7081 | } catch (ImsException e) { |
| 7082 | throw new ServiceSpecificException(e.getCode()); |
| 7083 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7084 | Binder.restoreCallingIdentity(identity); |
| 7085 | } |
| 7086 | } |
| 7087 | |
| 7088 | @Override |
| 7089 | public int getCallComposerStatus(int subId) { |
| 7090 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7091 | |
| 7092 | final long identity = Binder.clearCallingIdentity(); |
| 7093 | try { |
| 7094 | Phone phone = getPhone(subId); |
| 7095 | if (phone != null) { |
| 7096 | Phone defaultPhone = phone.getImsPhone(); |
| 7097 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7098 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7099 | return imsPhone.getCallComposerStatus(); |
| 7100 | } |
| 7101 | } |
| 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
| 7104 | } |
| 7105 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7106 | } |
| 7107 | |
| 7108 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7109 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7110 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7111 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7112 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7113 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
| 7116 | final String iccId = getIccId(subId); |
| 7117 | final Phone phone = getPhone(subId); |
| 7118 | if (phone == null) { |
| 7119 | return false; |
| 7120 | } |
| 7121 | final String subscriberId = phone.getSubscriberId(); |
| 7122 | |
| 7123 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7124 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7125 | + subscriberId + " to " + number); |
| 7126 | } |
| 7127 | |
| 7128 | if (TextUtils.isEmpty(iccId)) { |
| 7129 | return false; |
| 7130 | } |
| 7131 | |
| 7132 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7133 | |
| 7134 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7135 | if (alphaTag == null) { |
| 7136 | editor.remove(alphaTagPrefKey); |
| 7137 | } else { |
| 7138 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7139 | } |
| 7140 | |
| 7141 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7142 | // track all merged IMSIs based on line number |
| 7143 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7144 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7145 | if (number == null) { |
| 7146 | editor.remove(numberPrefKey); |
| 7147 | editor.remove(subscriberPrefKey); |
| 7148 | } else { |
| 7149 | editor.putString(numberPrefKey, number); |
| 7150 | editor.putString(subscriberPrefKey, subscriberId); |
| 7151 | } |
| 7152 | |
| 7153 | editor.commit(); |
| 7154 | return true; |
| 7155 | } finally { |
| 7156 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7157 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7161 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7162 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7163 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7164 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7165 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7166 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7167 | return null; |
| 7168 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7170 | final long identity = Binder.clearCallingIdentity(); |
| 7171 | try { |
| 7172 | String iccId = getIccId(subId); |
| 7173 | if (iccId != null) { |
| 7174 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7175 | if (DBG_MERGE) { |
| 7176 | log("getLine1NumberForDisplay returning " |
| 7177 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7178 | } |
| 7179 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7180 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7182 | return null; |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7185 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7189 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7190 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7192 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7193 | return null; |
| 7194 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | String iccId = getIccId(subId); |
| 7199 | if (iccId != null) { |
| 7200 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7201 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7202 | } |
| 7203 | return null; |
| 7204 | } finally { |
| 7205 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7206 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7207 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7208 | |
| 7209 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7210 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7211 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7212 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7213 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7215 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7216 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7217 | return null; |
| 7218 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7219 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7220 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7221 | // the process, where TelephonyManager was instantiated. |
| 7222 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
| 7224 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7225 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7226 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7227 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7228 | |
| 7229 | // Figure out what subscribers are currently active |
| 7230 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7231 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7232 | // Only consider subs which match the current subId |
| 7233 | // This logic can be simplified. See b/131189269 for progress. |
| 7234 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7235 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7236 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7237 | |
| 7238 | // First pass, find a number override for an active subscriber |
| 7239 | String mergeNumber = null; |
| 7240 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7241 | for (String key : prefs.keySet()) { |
| 7242 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7243 | final String subscriberId = (String) prefs.get(key); |
| 7244 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7245 | final String iccId = key.substring( |
| 7246 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7247 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7248 | mergeNumber = (String) prefs.get(numberKey); |
| 7249 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7250 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | + " for active subscriber " + subscriberId); |
| 7252 | } |
| 7253 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7254 | break; |
| 7255 | } |
| 7256 | } |
| 7257 | } |
| 7258 | } |
| 7259 | |
| 7260 | // Shortcut when no active merged subscribers |
| 7261 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7262 | return null; |
| 7263 | } |
| 7264 | |
| 7265 | // Second pass, find all subscribers under that line override |
| 7266 | final ArraySet<String> result = new ArraySet<>(); |
| 7267 | for (String key : prefs.keySet()) { |
| 7268 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7269 | final String number = (String) prefs.get(key); |
| 7270 | if (mergeNumber.equals(number)) { |
| 7271 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7272 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7273 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7274 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7275 | result.add(subscriberId); |
| 7276 | } |
| 7277 | } |
| 7278 | } |
| 7279 | } |
| 7280 | |
| 7281 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7282 | Arrays.sort(resultArray); |
| 7283 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7284 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7285 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7286 | } |
| 7287 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7288 | } finally { |
| 7289 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7290 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7291 | } |
| 7292 | |
| 7293 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7294 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7295 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7296 | |
| 7297 | final long identity = Binder.clearCallingIdentity(); |
| 7298 | try { |
| 7299 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7300 | TelephonyManager.class); |
| 7301 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7302 | if (subscriberId == null) { |
| 7303 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7304 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7305 | + subId); |
| 7306 | } |
| 7307 | return null; |
| 7308 | } |
| 7309 | |
| 7310 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7311 | .getSubscriptionInfo(subId); |
| 7312 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7313 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7314 | if (groupUuid == null) { |
| 7315 | return new String[]{subscriberId}; |
| 7316 | } |
| 7317 | |
| 7318 | // Get all subscriberIds from the group. |
| 7319 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7320 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7321 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7322 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7323 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7324 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7325 | if (subscriberId != null) { |
| 7326 | mergedSubscriberIds.add(subscriberId); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7331 | } finally { |
| 7332 | Binder.restoreCallingIdentity(identity); |
| 7333 | |
| 7334 | } |
| 7335 | } |
| 7336 | |
| 7337 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7338 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7339 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7340 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | |
| 7342 | final long identity = Binder.clearCallingIdentity(); |
| 7343 | try { |
| 7344 | final Phone phone = getPhone(subId); |
| 7345 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7346 | } finally { |
| 7347 | Binder.restoreCallingIdentity(identity); |
| 7348 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7349 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7350 | |
| 7351 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7352 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7353 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7354 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7355 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7356 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7357 | |
| 7358 | final long identity = Binder.clearCallingIdentity(); |
| 7359 | try { |
| 7360 | final Phone phone = getPhone(subId); |
| 7361 | if (phone == null) { |
| 7362 | return false; |
| 7363 | } |
| 7364 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7365 | cdmaNonRoamingList); |
| 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7368 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7369 | } |
| 7370 | |
| 7371 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7372 | @Deprecated |
| 7373 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7374 | enforceModifyPermission(); |
| 7375 | |
| 7376 | int returnValue = 0; |
| 7377 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7378 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7379 | if(result.exception == null) { |
| 7380 | if (result.result != null) { |
| 7381 | byte[] responseData = (byte[])(result.result); |
| 7382 | if(responseData.length > oemResp.length) { |
| 7383 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7384 | responseData.length + "bytes. Buffer Size is " + |
| 7385 | oemResp.length + "bytes."); |
| 7386 | } |
| 7387 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7388 | returnValue = responseData.length; |
| 7389 | } |
| 7390 | } else { |
| 7391 | CommandException ex = (CommandException) result.exception; |
| 7392 | returnValue = ex.getCommandError().ordinal(); |
| 7393 | if(returnValue > 0) returnValue *= -1; |
| 7394 | } |
| 7395 | } catch (RuntimeException e) { |
| 7396 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7397 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7398 | if(returnValue > 0) returnValue *= -1; |
| 7399 | } |
| 7400 | |
| 7401 | return returnValue; |
| 7402 | } |
| 7403 | |
| 7404 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7405 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7406 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7407 | try { |
| 7408 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7409 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7410 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7411 | } catch (SecurityException e) { |
| 7412 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7413 | throw e; |
| 7414 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7415 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7416 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7417 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7418 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7419 | final long identity = Binder.clearCallingIdentity(); |
| 7420 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7421 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7422 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7423 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7424 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
| 7427 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7428 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7429 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7430 | |
| 7431 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7432 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7433 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7434 | try { |
| 7435 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7436 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7437 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7438 | } |
| 7439 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7440 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7441 | } |
| 7442 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7443 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7444 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7445 | throw new SecurityException("App must be the dialer role holder to" |
| 7446 | + " upload a call composer pic"); |
| 7447 | } |
| 7448 | |
| 7449 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7450 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7451 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7452 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7453 | boolean readUntilEnd = false; |
| 7454 | int totalBytesRead = 0; |
| 7455 | byte[] buffer = new byte[16 * 1024]; |
| 7456 | while (true) { |
| 7457 | int numRead; |
| 7458 | try { |
| 7459 | numRead = input.read(buffer); |
| 7460 | } catch (IOException e) { |
| 7461 | try { |
| 7462 | fd.checkError(); |
| 7463 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7464 | null); |
| 7465 | } catch (IOException e1) { |
| 7466 | // This means that the other side closed explicitly with an error. If this |
| 7467 | // happens, log and ignore. |
| 7468 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7469 | } |
| 7470 | break; |
| 7471 | } |
| 7472 | if (numRead == -1) { |
| 7473 | readUntilEnd = true; |
| 7474 | break; |
| 7475 | } |
| 7476 | totalBytesRead += numRead; |
| 7477 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7478 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7479 | try { |
| 7480 | input.close(); |
| 7481 | } catch (IOException e) { |
| 7482 | // ignore |
| 7483 | } |
| 7484 | break; |
| 7485 | } |
| 7486 | output.write(buffer, 0, numRead); |
| 7487 | } |
| 7488 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7489 | // close is above, where the picture size is too big. |
| 7490 | |
| 7491 | try { |
| 7492 | fd.checkError(); |
| 7493 | } catch (IOException e) { |
| 7494 | loge("Remote end for call composer closed with an error: " + e); |
| 7495 | return; |
| 7496 | } |
| 7497 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7498 | if (!readUntilEnd) { |
| 7499 | loge("Did not finish reading entire image; aborting"); |
| 7500 | return; |
| 7501 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7502 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7503 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7504 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7505 | new CallComposerPictureTransfer.Factory() {}, |
| 7506 | imageData, |
| 7507 | (result) -> { |
| 7508 | if (result.first != null) { |
| 7509 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7510 | Bundle outputResult = new Bundle(); |
| 7511 | outputResult.putParcelable( |
| 7512 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7513 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7514 | outputResult); |
| 7515 | } else { |
| 7516 | callback.send(result.second, null); |
| 7517 | } |
| 7518 | } |
| 7519 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7520 | }); |
| 7521 | } |
| 7522 | |
| 7523 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7524 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7525 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7526 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | |
| 7528 | final long identity = Binder.clearCallingIdentity(); |
| 7529 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7530 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7531 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7532 | } finally { |
| 7533 | Binder.restoreCallingIdentity(identity); |
| 7534 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7535 | } |
| 7536 | |
| 7537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7538 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7539 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7540 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7541 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7542 | return false; |
| 7543 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | final long identity = Binder.clearCallingIdentity(); |
| 7546 | try { |
| 7547 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7548 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7549 | // In the long run, we may instead need to check if there exists a connection service |
| 7550 | // which can support video calling. |
| 7551 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7552 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7553 | return imsManager.isVtEnabledByPlatform() |
| 7554 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7555 | && imsManager.isVtEnabledByUser(); |
| 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
| 7558 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7559 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7560 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7561 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7562 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7563 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7565 | mApp, subId, callingPackage, callingFeatureId, |
| 7566 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | return false; |
| 7568 | } |
| 7569 | |
| 7570 | final long identity = Binder.clearCallingIdentity(); |
| 7571 | try { |
| 7572 | CarrierConfigManager configManager = |
| 7573 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7574 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7575 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7576 | } finally { |
| 7577 | Binder.restoreCallingIdentity(identity); |
| 7578 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7582 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7584 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | return false; |
| 7586 | } |
| 7587 | |
| 7588 | final long identity = Binder.clearCallingIdentity(); |
| 7589 | try { |
| 7590 | CarrierConfigManager configManager = |
| 7591 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7592 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7594 | } finally { |
| 7595 | Binder.restoreCallingIdentity(identity); |
| 7596 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7597 | } |
| 7598 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7599 | @Override |
| 7600 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7601 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7602 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | @Override |
| 7606 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7607 | final long identity = Binder.clearCallingIdentity(); |
| 7608 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7609 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7610 | } finally { |
| 7611 | Binder.restoreCallingIdentity(identity); |
| 7612 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7613 | } |
| 7614 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7615 | /** |
| 7616 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7617 | * support for the feature and device firmware support. |
| 7618 | * |
| 7619 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7620 | */ |
| 7621 | @Override |
| 7622 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7623 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7624 | final Phone phone = getPhone(subscriptionId); |
| 7625 | if (phone == null) { |
| 7626 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7627 | return false; |
| 7628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7629 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7630 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7631 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7632 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7633 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | return isCarrierSupported && isDeviceSupported; |
| 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
| 7637 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7640 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7641 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7642 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7643 | * 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] | 7644 | */ |
| 7645 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7646 | final long identity = Binder.clearCallingIdentity(); |
| 7647 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7648 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7649 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7650 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7651 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7652 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7653 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | } finally { |
| 7655 | Binder.restoreCallingIdentity(identity); |
| 7656 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7659 | @Deprecated |
| 7660 | @Override |
| 7661 | public String getDeviceId(String callingPackage) { |
| 7662 | return getDeviceIdWithFeature(callingPackage, null); |
| 7663 | } |
| 7664 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7665 | /** |
| 7666 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7667 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7668 | * |
| 7669 | * <p>Requires Permission: |
| 7670 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7671 | */ |
| 7672 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7673 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7674 | try { |
| 7675 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7676 | } catch (SecurityException se) { |
| 7677 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7678 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7679 | + Binder.getCallingUid()); |
| 7680 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7681 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7682 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7683 | return null; |
| 7684 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7685 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7686 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7687 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7688 | return null; |
| 7689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | |
| 7691 | final long identity = Binder.clearCallingIdentity(); |
| 7692 | try { |
| 7693 | return phone.getDeviceId(); |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
| 7696 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7697 | } |
| 7698 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7699 | /** |
| 7700 | * {@hide} |
| 7701 | * Returns the IMS Registration Status on a particular subid |
| 7702 | * |
| 7703 | * @param subId |
| 7704 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7705 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7706 | Phone phone = getPhone(subId); |
| 7707 | if (phone != null) { |
| 7708 | return phone.isImsRegistered(); |
| 7709 | } else { |
| 7710 | return false; |
| 7711 | } |
| 7712 | } |
| 7713 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7714 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7715 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7716 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7718 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7719 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7720 | } |
| 7721 | final long identity = Binder.clearCallingIdentity(); |
| 7722 | try { |
| 7723 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
| 7726 | } |
| 7727 | } |
| 7728 | |
| 7729 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7730 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7731 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7732 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7733 | mApp, |
| 7734 | subscriptionId, |
| 7735 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7736 | final long identity = Binder.clearCallingIdentity(); |
| 7737 | try { |
| 7738 | Phone phone = getPhone(subscriptionId); |
| 7739 | if (phone == null) { |
| 7740 | return null; |
| 7741 | } |
| 7742 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7743 | } finally { |
| 7744 | Binder.restoreCallingIdentity(identity); |
| 7745 | } |
| 7746 | } |
| 7747 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7748 | /** |
| 7749 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7750 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7751 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | final long identity = Binder.clearCallingIdentity(); |
| 7753 | try { |
| 7754 | Phone phone = getPhone(subId); |
| 7755 | if (phone != null) { |
| 7756 | return phone.isWifiCallingEnabled(); |
| 7757 | } else { |
| 7758 | return false; |
| 7759 | } |
| 7760 | } finally { |
| 7761 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7762 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7763 | } |
| 7764 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7765 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7766 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7767 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7768 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | final long identity = Binder.clearCallingIdentity(); |
| 7770 | try { |
| 7771 | Phone phone = getPhone(subId); |
| 7772 | if (phone != null) { |
| 7773 | return phone.isVideoEnabled(); |
| 7774 | } else { |
| 7775 | return false; |
| 7776 | } |
| 7777 | } finally { |
| 7778 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7779 | } |
| 7780 | } |
| 7781 | |
| 7782 | /** |
| 7783 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7784 | * defined in {@link ImsRegistrationImplBase}. |
| 7785 | */ |
| 7786 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | final long identity = Binder.clearCallingIdentity(); |
| 7788 | try { |
| 7789 | Phone phone = getPhone(subId); |
| 7790 | if (phone != null) { |
| 7791 | return phone.getImsRegistrationTech(); |
| 7792 | } else { |
| 7793 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7794 | } |
| 7795 | } finally { |
| 7796 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7797 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7798 | } |
| 7799 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7800 | @Override |
| 7801 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7802 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7803 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7804 | return; |
| 7805 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7806 | Phone defaultPhone = getDefaultPhone(); |
| 7807 | if (defaultPhone != null) { |
| 7808 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7809 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7810 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7811 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7812 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7813 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7814 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7815 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7816 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7817 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7818 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7819 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7820 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7821 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7822 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7823 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7824 | // There has been issues when Sms raw table somehow stores orphan |
| 7825 | // fragments. They lead to garbled message when new fragments come |
| 7826 | // in and combined with those stale ones. In case this happens again, |
| 7827 | // user can reset all network settings which will clean up this table. |
| 7828 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7829 | // Clean up IMS settings as well here. |
| 7830 | int slotId = getSlotIndex(subId); |
| 7831 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7832 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7833 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7834 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7835 | if (defaultPhone == null) { |
| 7836 | return; |
| 7837 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7838 | // Erase modem config if erase modem on network setting is enabled. |
| 7839 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7840 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7841 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7842 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7843 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7844 | |
| 7845 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7846 | } finally { |
| 7847 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7848 | } |
| 7849 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7850 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7851 | @VisibleForTesting |
| 7852 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7853 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7854 | return; |
| 7855 | } |
| 7856 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7857 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7858 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7859 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7860 | "user=" + defaultNetworkType); |
| 7861 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7862 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7863 | defaultNetworkType, null); |
| 7864 | } |
| 7865 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7866 | private void cleanUpSmsRawTable(Context context) { |
| 7867 | ContentResolver resolver = context.getContentResolver(); |
| 7868 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7869 | resolver.delete(uri, null, null); |
| 7870 | } |
| 7871 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7872 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7873 | public String getSimLocaleForSubscriber(int subId) { |
| 7874 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7875 | final Phone phone = getPhone(subId); |
| 7876 | if (phone == null) { |
| 7877 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7878 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7880 | final long identity = Binder.clearCallingIdentity(); |
| 7881 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7882 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7883 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7884 | if (info == null) { |
| 7885 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7886 | return null; |
| 7887 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7888 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7889 | // preferences (EF-PL and EF-LI)... |
| 7890 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7891 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7892 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7893 | if (localeFromDefaultSim != null) { |
| 7894 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7895 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7896 | + localeFromDefaultSim); |
| 7897 | return localeFromDefaultSim.toLanguageTag(); |
| 7898 | } else { |
| 7899 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7900 | } |
| 7901 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7903 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7904 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7905 | // the SIM and carrier preferences does not include a country we add the country |
| 7906 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7907 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7908 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7909 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | return mccLocale.toLanguageTag(); |
| 7911 | } |
| 7912 | |
| 7913 | if (DBG) log("No locale found - returning null"); |
| 7914 | return null; |
| 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
| 7917 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7918 | } |
| 7919 | |
| 7920 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7921 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7922 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7923 | } |
| 7924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7925 | /** |
| 7926 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7927 | */ |
| 7928 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7929 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7930 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7931 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7932 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7933 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7934 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7935 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7936 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7937 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7938 | * representing the state of the modem. |
| 7939 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7940 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7941 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7942 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7943 | */ |
| 7944 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7945 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7946 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7947 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7948 | |
| 7949 | final long identity = Binder.clearCallingIdentity(); |
| 7950 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7951 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | } finally { |
| 7953 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7954 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7955 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7956 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7957 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7958 | // less than total activity duration. |
| 7959 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7960 | if (info == null) { |
| 7961 | return false; |
| 7962 | } |
| 7963 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7964 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7965 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7966 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7967 | return (info.isValid() |
| 7968 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7969 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7970 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7971 | && (totalTxTimeMs <= activityDurationMs)); |
| 7972 | } |
| 7973 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7974 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7975 | * Returns the service state information on specified subscription. |
| 7976 | */ |
| 7977 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7978 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7979 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7980 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7981 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7982 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7983 | return null; |
| 7984 | } |
| 7985 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7986 | boolean hasFinePermission = false; |
| 7987 | boolean hasCoarsePermission = false; |
| 7988 | if (!renounceFineLocationAccess) { |
| 7989 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7990 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7991 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7992 | .setCallingPackage(callingPackage) |
| 7993 | .setCallingFeatureId(callingFeatureId) |
| 7994 | .setCallingPid(Binder.getCallingPid()) |
| 7995 | .setCallingUid(Binder.getCallingUid()) |
| 7996 | .setMethod("getServiceStateForSubscriber") |
| 7997 | .setLogAsInfo(true) |
| 7998 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7999 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8000 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8001 | .build()); |
| 8002 | hasFinePermission = |
| 8003 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8004 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8005 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8006 | if (!renounceCoarseLocationAccess) { |
| 8007 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8008 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8009 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8010 | .setCallingPackage(callingPackage) |
| 8011 | .setCallingFeatureId(callingFeatureId) |
| 8012 | .setCallingPid(Binder.getCallingPid()) |
| 8013 | .setCallingUid(Binder.getCallingUid()) |
| 8014 | .setMethod("getServiceStateForSubscriber") |
| 8015 | .setLogAsInfo(true) |
| 8016 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8017 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8018 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8019 | .build()); |
| 8020 | hasCoarsePermission = |
| 8021 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8022 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8023 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8024 | final Phone phone = getPhone(subId); |
| 8025 | if (phone == null) { |
| 8026 | return null; |
| 8027 | } |
| 8028 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8031 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8032 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8033 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8034 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8035 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8036 | Rlog.d(LOG_TAG, |
| 8037 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8038 | return null; |
| 8039 | } |
| 8040 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8041 | ServiceState ss = phone.getServiceState(); |
| 8042 | |
| 8043 | // Scrub out the location info in ServiceState depending on what level of access |
| 8044 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8045 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8046 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8047 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | } finally { |
| 8049 | Binder.restoreCallingIdentity(identity); |
| 8050 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8051 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8052 | |
| 8053 | /** |
| 8054 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8055 | * |
| 8056 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8057 | * voicemail ringtone. |
| 8058 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8059 | * PhoneAccount. |
| 8060 | */ |
| 8061 | @Override |
| 8062 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8063 | final long identity = Binder.clearCallingIdentity(); |
| 8064 | try { |
| 8065 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8066 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8067 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8071 | } finally { |
| 8072 | Binder.restoreCallingIdentity(identity); |
| 8073 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8074 | } |
| 8075 | |
| 8076 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8077 | * Sets the per-account voicemail ringtone. |
| 8078 | * |
| 8079 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8080 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8081 | * |
| 8082 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8083 | * voicemail ringtone. |
| 8084 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8085 | * PhoneAccount. |
| 8086 | */ |
| 8087 | @Override |
| 8088 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8089 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8090 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8091 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8092 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8093 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8095 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8096 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8097 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8098 | |
| 8099 | final long identity = Binder.clearCallingIdentity(); |
| 8100 | try { |
| 8101 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8102 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8103 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8104 | } |
| 8105 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8108 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8112 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8113 | * |
| 8114 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8115 | * voicemail vibration setting. |
| 8116 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8117 | */ |
| 8118 | @Override |
| 8119 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8120 | final long identity = Binder.clearCallingIdentity(); |
| 8121 | try { |
| 8122 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8123 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8124 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8125 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8126 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8127 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8128 | } finally { |
| 8129 | Binder.restoreCallingIdentity(identity); |
| 8130 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8131 | } |
| 8132 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8133 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8134 | * Sets the per-account voicemail vibration. |
| 8135 | * |
| 8136 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8137 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8138 | * |
| 8139 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8140 | * voicemail vibration setting. |
| 8141 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8142 | * specific PhoneAccount. |
| 8143 | */ |
| 8144 | @Override |
| 8145 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8146 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8147 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8148 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8149 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8150 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8152 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8153 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8154 | } |
| 8155 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8156 | final long identity = Binder.clearCallingIdentity(); |
| 8157 | try { |
| 8158 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8159 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8160 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | } |
| 8162 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8163 | } finally { |
| 8164 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8165 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8166 | } |
| 8167 | |
| 8168 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8169 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8170 | * |
| 8171 | * @throws SecurityException if the caller does not have the required permission |
| 8172 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8173 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8174 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8175 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8176 | } |
| 8177 | |
| 8178 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8179 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8180 | * permission. |
| 8181 | * |
| 8182 | * @throws SecurityException if the caller does not have the required permission |
| 8183 | */ |
| 8184 | private void enforceSendSmsPermission() { |
| 8185 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8186 | } |
| 8187 | |
| 8188 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8189 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8190 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8191 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8192 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8193 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8194 | final long identity = Binder.clearCallingIdentity(); |
| 8195 | try { |
| 8196 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8197 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8198 | if (componentName == null) { |
| 8199 | throw new SecurityException( |
| 8200 | "Caller not current active visual voicemail package[null]"); |
| 8201 | } |
| 8202 | String vvmPackage = componentName.getPackageName(); |
| 8203 | if (!callingPackage.equals(vvmPackage)) { |
| 8204 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8205 | + vvmPackage + "]"); |
| 8206 | } |
| 8207 | } finally { |
| 8208 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8209 | } |
| 8210 | } |
| 8211 | |
| 8212 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8213 | * Return the application ID for the app type. |
| 8214 | * |
| 8215 | * @param subId the subscription ID that this request applies to. |
| 8216 | * @param appType the uicc app type. |
| 8217 | * @return Application ID for specificied app type, or null if no uicc. |
| 8218 | */ |
| 8219 | @Override |
| 8220 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8221 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8222 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8223 | |
| 8224 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8225 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8226 | if (phone == null) { |
| 8227 | return null; |
| 8228 | } |
| 8229 | String aid = null; |
| 8230 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8231 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | .getApplicationByType(appType).getAid(); |
| 8233 | } catch (Exception e) { |
| 8234 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8235 | } |
| 8236 | return aid; |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8239 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8240 | } |
| 8241 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8242 | /** |
| 8243 | * Return the Electronic Serial Number. |
| 8244 | * |
| 8245 | * @param subId the subscription ID that this request applies to. |
| 8246 | * @return ESN or null if error. |
| 8247 | */ |
| 8248 | @Override |
| 8249 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8250 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8251 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | |
| 8253 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8254 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8255 | if (phone == null) { |
| 8256 | return null; |
| 8257 | } |
| 8258 | String esn = null; |
| 8259 | try { |
| 8260 | esn = phone.getEsn(); |
| 8261 | } catch (Exception e) { |
| 8262 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8263 | } |
| 8264 | return esn; |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8267 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8268 | } |
| 8269 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8270 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8271 | * Return the Preferred Roaming List Version. |
| 8272 | * |
| 8273 | * @param subId the subscription ID that this request applies to. |
| 8274 | * @return PRLVersion or null if error. |
| 8275 | */ |
| 8276 | @Override |
| 8277 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8278 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8279 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8280 | |
| 8281 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8282 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8283 | if (phone == null) { |
| 8284 | return null; |
| 8285 | } |
| 8286 | String cdmaPrlVersion = null; |
| 8287 | try { |
| 8288 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8289 | } catch (Exception e) { |
| 8290 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8291 | } |
| 8292 | return cdmaPrlVersion; |
| 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8295 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8299 | * Get snapshot of Telephony histograms |
| 8300 | * @return List of Telephony histograms |
| 8301 | * @hide |
| 8302 | */ |
| 8303 | @Override |
| 8304 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8306 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8307 | |
| 8308 | final long identity = Binder.clearCallingIdentity(); |
| 8309 | try { |
| 8310 | return RIL.getTelephonyRILTimingHistograms(); |
| 8311 | } finally { |
| 8312 | Binder.restoreCallingIdentity(identity); |
| 8313 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8314 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8315 | |
| 8316 | /** |
| 8317 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8318 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8319 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8320 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8321 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8322 | * @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] | 8323 | */ |
| 8324 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8325 | @TelephonyManager.SetCarrierRestrictionResult |
| 8326 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8327 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8328 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8329 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8330 | if (carrierRestrictionRules == null) { |
| 8331 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8332 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8336 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8337 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | } finally { |
| 8339 | Binder.restoreCallingIdentity(identity); |
| 8340 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8341 | } |
| 8342 | |
| 8343 | /** |
| 8344 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8345 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8346 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8347 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8348 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8349 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8350 | */ |
| 8351 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8352 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8353 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8354 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8355 | |
| 8356 | final long identity = Binder.clearCallingIdentity(); |
| 8357 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8358 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8359 | if (response instanceof CarrierRestrictionRules) { |
| 8360 | return (CarrierRestrictionRules) response; |
| 8361 | } |
| 8362 | // Response is an Exception of some kind, |
| 8363 | // which is signalled to the user as a NULL retval |
| 8364 | return null; |
| 8365 | } catch (Exception e) { |
| 8366 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8367 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8371 | } |
| 8372 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8373 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8374 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8375 | * @param subId the subscription ID that this action applies to. |
| 8376 | * @param enabled control enable or disable radio. |
| 8377 | * {@hide} |
| 8378 | */ |
| 8379 | @Override |
| 8380 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8381 | enforceModifyPermission(); |
| 8382 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | |
| 8384 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8385 | if (phone == null) { |
| 8386 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8387 | return; |
| 8388 | } |
| 8389 | try { |
| 8390 | phone.carrierActionSetRadioEnabled(enabled); |
| 8391 | } catch (Exception e) { |
| 8392 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8395 | } |
| 8396 | } |
| 8397 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8398 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8399 | * Enable or disable Voice over NR (VoNR) |
| 8400 | * @param subId the subscription ID that this action applies to. |
| 8401 | * @param enabled enable or disable VoNR. |
| 8402 | * @return operation result. |
| 8403 | */ |
| 8404 | @Override |
| 8405 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8406 | enforceModifyPermission(); |
| 8407 | final Phone phone = getPhone(subId); |
| 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | if (phone == null) { |
| 8411 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8412 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8413 | } |
| 8414 | |
| 8415 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8416 | try { |
| 8417 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8418 | workSource); |
| 8419 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8420 | |
| 8421 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8422 | if (DBG) { |
| 8423 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8424 | } |
| 8425 | SubscriptionManager.setSubscriptionProperty( |
| 8426 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8427 | (enabled ? "1" : "0")); |
| 8428 | } |
| 8429 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8430 | return result; |
| 8431 | } finally { |
| 8432 | Binder.restoreCallingIdentity(identity); |
| 8433 | } |
| 8434 | } |
| 8435 | |
| 8436 | /** |
| 8437 | * Is voice over NR enabled |
| 8438 | * @return true if VoNR is enabled else false |
| 8439 | */ |
| 8440 | @Override |
| 8441 | public boolean isVoNrEnabled(int subId) { |
| 8442 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8443 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8444 | final long identity = Binder.clearCallingIdentity(); |
| 8445 | try { |
| 8446 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8447 | null, subId, workSource); |
| 8448 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8449 | return isEnabled; |
| 8450 | } finally { |
| 8451 | Binder.restoreCallingIdentity(identity); |
| 8452 | } |
| 8453 | } |
| 8454 | |
| 8455 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8456 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8457 | * network status based on which carrier apps could apply actions accordingly, |
| 8458 | * enable/disable default url handler for example. |
| 8459 | * |
| 8460 | * @param subId the subscription ID that this action applies to. |
| 8461 | * @param report control start/stop reporting the default network status. |
| 8462 | * {@hide} |
| 8463 | */ |
| 8464 | @Override |
| 8465 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8466 | enforceModifyPermission(); |
| 8467 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8468 | |
| 8469 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8470 | if (phone == null) { |
| 8471 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8472 | return; |
| 8473 | } |
| 8474 | try { |
| 8475 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8476 | } catch (Exception e) { |
| 8477 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8480 | } |
| 8481 | } |
| 8482 | |
| 8483 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8484 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8485 | * @param subId the subscription ID that this action applies to. |
| 8486 | * {@hide} |
| 8487 | */ |
| 8488 | @Override |
| 8489 | public void carrierActionResetAll(int subId) { |
| 8490 | enforceModifyPermission(); |
| 8491 | final Phone phone = getPhone(subId); |
| 8492 | if (phone == null) { |
| 8493 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8494 | return; |
| 8495 | } |
| 8496 | try { |
| 8497 | phone.carrierActionResetAll(); |
| 8498 | } catch (Exception e) { |
| 8499 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8500 | } |
| 8501 | } |
| 8502 | |
| 8503 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8504 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8505 | * bug report is being generated. |
| 8506 | */ |
| 8507 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8508 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8509 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8510 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8511 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8512 | + Binder.getCallingPid() |
| 8513 | + ", uid=" + Binder.getCallingUid() |
| 8514 | + "without permission " |
| 8515 | + android.Manifest.permission.DUMP); |
| 8516 | return; |
| 8517 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8518 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8519 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8520 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8521 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8522 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8523 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8524 | @NonNull String[] args) { |
| 8525 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8526 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8527 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8528 | } |
| 8529 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8530 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8531 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8532 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8533 | * @param reason the reason the data enable change is taking place |
| 8534 | * @param enabled True if enabling the data, otherwise disabling. |
| 8535 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8536 | */ |
| 8537 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8538 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8539 | boolean enabled) { |
| 8540 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8541 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8542 | try { |
| 8543 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8544 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8545 | } catch (SecurityException se) { |
| 8546 | enforceModifyPermission(); |
| 8547 | } |
| 8548 | } else { |
| 8549 | enforceModifyPermission(); |
| 8550 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8551 | |
| 8552 | final long identity = Binder.clearCallingIdentity(); |
| 8553 | try { |
| 8554 | Phone phone = getPhone(subId); |
| 8555 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8556 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8557 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8558 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8559 | if (phone.isUsingNewDataStack()) { |
| 8560 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8561 | } else { |
| 8562 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8563 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8565 | } |
| 8566 | } finally { |
| 8567 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8568 | } |
| 8569 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8570 | |
| 8571 | /** |
| 8572 | * Get Client request stats |
| 8573 | * @return List of Client Request Stats |
| 8574 | * @hide |
| 8575 | */ |
| 8576 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8577 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8578 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8579 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8580 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8581 | return null; |
| 8582 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8583 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8585 | final long identity = Binder.clearCallingIdentity(); |
| 8586 | try { |
| 8587 | if (phone != null) { |
| 8588 | return phone.getClientRequestStats(); |
| 8589 | } |
| 8590 | |
| 8591 | return null; |
| 8592 | } finally { |
| 8593 | Binder.restoreCallingIdentity(identity); |
| 8594 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8595 | } |
| 8596 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8597 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8598 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8599 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8600 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8601 | |
| 8602 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8603 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8604 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8605 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8606 | * @param state State of SIM (power down, power up, pass through) |
| 8607 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8608 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8609 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8610 | * |
| 8611 | **/ |
| 8612 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8613 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8614 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8615 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8616 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8617 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8619 | final long identity = Binder.clearCallingIdentity(); |
| 8620 | try { |
| 8621 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8622 | phone.setSimPowerState(state, null, workSource); |
| 8623 | } |
| 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
| 8627 | } |
| 8628 | |
| 8629 | /** |
| 8630 | * Set SIM card power state. |
| 8631 | * |
| 8632 | * @param slotIndex SIM slot id. |
| 8633 | * @param state State of SIM (power down, power up, pass through) |
| 8634 | * @param callback callback to trigger after success or failure |
| 8635 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8636 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8637 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8638 | * |
| 8639 | **/ |
| 8640 | @Override |
| 8641 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8642 | IIntegerConsumer callback) { |
| 8643 | enforceModifyPermission(); |
| 8644 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8645 | |
| 8646 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8647 | |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | if (phone != null) { |
| 8651 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8652 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8653 | } |
| 8654 | } finally { |
| 8655 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8656 | } |
| 8657 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8658 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8659 | private boolean isUssdApiAllowed(int subId) { |
| 8660 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8661 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8662 | if (configManager == null) { |
| 8663 | return false; |
| 8664 | } |
| 8665 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8666 | if (pb == null) { |
| 8667 | return false; |
| 8668 | } |
| 8669 | return pb.getBoolean( |
| 8670 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8671 | } |
| 8672 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8673 | /** |
| 8674 | * Check if phone is in emergency callback mode |
| 8675 | * @return true if phone is in emergency callback mode |
| 8676 | * @param subId sub id |
| 8677 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8678 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8679 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8680 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8681 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8682 | |
| 8683 | final long identity = Binder.clearCallingIdentity(); |
| 8684 | try { |
| 8685 | if (phone != null) { |
| 8686 | return phone.isInEcm(); |
| 8687 | } else { |
| 8688 | return false; |
| 8689 | } |
| 8690 | } finally { |
| 8691 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8692 | } |
| 8693 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8694 | |
| 8695 | /** |
| 8696 | * Get the current signal strength information for the given subscription. |
| 8697 | * Because this information is not updated when the device is in a low power state |
| 8698 | * it should not be relied-upon to be current. |
| 8699 | * @param subId Subscription index |
| 8700 | * @return the most recent cached signal strength info from the modem |
| 8701 | */ |
| 8702 | @Override |
| 8703 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8704 | final long identity = Binder.clearCallingIdentity(); |
| 8705 | try { |
| 8706 | Phone p = getPhone(subId); |
| 8707 | if (p == null) { |
| 8708 | return null; |
| 8709 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8710 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8711 | return p.getSignalStrength(); |
| 8712 | } finally { |
| 8713 | Binder.restoreCallingIdentity(identity); |
| 8714 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8715 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8716 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8717 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8718 | * Get the current modem radio state for the given slot. |
| 8719 | * @param slotIndex slot index. |
| 8720 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8721 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8722 | * @return the current radio power state from the modem |
| 8723 | */ |
| 8724 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8725 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8726 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8727 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8729 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8730 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8731 | } |
| 8732 | |
| 8733 | final long identity = Binder.clearCallingIdentity(); |
| 8734 | try { |
| 8735 | return phone.getRadioPowerState(); |
| 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
| 8739 | } |
| 8740 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8741 | } |
| 8742 | |
| 8743 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8744 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8745 | * |
| 8746 | * <p>Requires one of the following permissions: |
| 8747 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8748 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8749 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8750 | * privileges. |
| 8751 | * |
| 8752 | * @param subId subscription id |
| 8753 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8754 | * {@code false}. |
| 8755 | */ |
| 8756 | @Override |
| 8757 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8758 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8759 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8760 | try { |
| 8761 | mApp.enforceCallingOrSelfPermission( |
| 8762 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8763 | functionName); |
| 8764 | } catch (Exception e) { |
| 8765 | mApp.enforceCallingOrSelfPermission( |
| 8766 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8767 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8768 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8769 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8770 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8771 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8772 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8773 | boolean isEnabled = false; |
| 8774 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8775 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8776 | Phone phone = getPhone(subId); |
| 8777 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8778 | } finally { |
| 8779 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8780 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8781 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8782 | } |
| 8783 | |
| 8784 | |
| 8785 | /** |
| 8786 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8787 | * |
| 8788 | * <p> Requires permission: |
| 8789 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8790 | * privileges. |
| 8791 | * |
| 8792 | * @param subId subscription id |
| 8793 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8794 | */ |
| 8795 | @Override |
| 8796 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8798 | mApp, subId, "setDataRoamingEnabled"); |
| 8799 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8800 | final long identity = Binder.clearCallingIdentity(); |
| 8801 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8802 | Phone phone = getPhone(subId); |
| 8803 | if (phone != null) { |
| 8804 | phone.setDataRoamingEnabled(isEnabled); |
| 8805 | } |
| 8806 | } finally { |
| 8807 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8808 | } |
| 8809 | } |
| 8810 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8811 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8812 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8813 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8814 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8815 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8816 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8817 | boolean isAllowed = true; |
| 8818 | final long identity = Binder.clearCallingIdentity(); |
| 8819 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8820 | Phone phone = getPhone(subId); |
| 8821 | if (phone != null) { |
| 8822 | isAllowed = phone.isCspPlmnEnabled(); |
| 8823 | } |
| 8824 | } finally { |
| 8825 | Binder.restoreCallingIdentity(identity); |
| 8826 | } |
| 8827 | return isAllowed; |
| 8828 | } |
| 8829 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8830 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8831 | UiccProfile profile = port.getUiccProfile(); |
| 8832 | if (profile == null || |
| 8833 | profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8834 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8835 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8836 | } |
| 8837 | return true; |
| 8838 | } |
| 8839 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8840 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8841 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8842 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8843 | mApp.getSystemService(AppOpsManager.class) |
| 8844 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8845 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8846 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8847 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8848 | try { |
| 8849 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8850 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8851 | } catch (SecurityException e) { |
| 8852 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8853 | // has carrier privileges on an active UICC |
| 8854 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8855 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8856 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8857 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8858 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8859 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8860 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8861 | Binder.getCallingUid())) { |
| 8862 | isIccIdAccessRestricted = true; |
| 8863 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8864 | final long identity = Binder.clearCallingIdentity(); |
| 8865 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8866 | UiccController uiccController = UiccController.getInstance(); |
| 8867 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8868 | if (hasReadPermission) { |
| 8869 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8870 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8871 | |
| 8872 | // Remove private info if the caller doesn't have access |
| 8873 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8874 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8875 | //setting the value after compatibility check |
| 8876 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8877 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8878 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8879 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8880 | if (card == null) { |
| 8881 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8882 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8883 | continue; |
| 8884 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8885 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8886 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8887 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8888 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8889 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8890 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8891 | for (UiccPortInfo portInfo : portInfos) { |
| 8892 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8893 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8894 | if (port == null) { |
| 8895 | // assume no access if port is null |
| 8896 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8897 | continue; |
| 8898 | } |
| 8899 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8900 | uiccPortInfos.add(portInfo); |
| 8901 | } else { |
| 8902 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8903 | } |
| 8904 | } |
| 8905 | filteredInfos.add(new UiccCardInfo( |
| 8906 | cardInfo.isEuicc(), |
| 8907 | cardInfo.getCardId(), |
| 8908 | null, |
| 8909 | cardInfo.getPhysicalSlotIndex(), |
| 8910 | cardInfo.isRemovable(), |
| 8911 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8912 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8913 | } |
| 8914 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8915 | } finally { |
| 8916 | Binder.restoreCallingIdentity(identity); |
| 8917 | } |
| 8918 | } |
| 8919 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8920 | /** |
| 8921 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8922 | * generally private and require carrier privileges to view. |
| 8923 | * |
| 8924 | * @hide |
| 8925 | */ |
| 8926 | @NonNull |
| 8927 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8928 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8929 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8930 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8931 | } |
| 8932 | return new UiccCardInfo( |
| 8933 | cardInfo.isEuicc(), |
| 8934 | cardInfo.getCardId(), |
| 8935 | null, |
| 8936 | cardInfo.getPhysicalSlotIndex(), |
| 8937 | cardInfo.isRemovable(), |
| 8938 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8939 | portinfo |
| 8940 | ); |
| 8941 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8942 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8943 | /** |
| 8944 | * @hide |
| 8945 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8946 | * These values are generally private and require carrier privileges to view. |
| 8947 | */ |
| 8948 | @NonNull |
| 8949 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8950 | return new UiccPortInfo( |
| 8951 | UiccPortInfo.ICCID_REDACTED, |
| 8952 | portInfo.getPortIndex(), |
| 8953 | portInfo.getLogicalSlotIndex(), |
| 8954 | portInfo.isActive() |
| 8955 | ); |
| 8956 | } |
| 8957 | @Override |
| 8958 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8959 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8960 | mApp.getSystemService(AppOpsManager.class) |
| 8961 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8962 | |
| 8963 | boolean hasReadPermission = false; |
| 8964 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8965 | |
| 8966 | try { |
| 8967 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8968 | hasReadPermission = true; |
| 8969 | } catch (SecurityException e) { |
| 8970 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8971 | // has carrier privileges on an active UICC |
| 8972 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8973 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8974 | hasReadPermission = true; |
| 8975 | } |
| 8976 | } |
| 8977 | |
| 8978 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8979 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8980 | Binder.getCallingUid())) { |
| 8981 | isLogicalSlotAccessRestricted = true; |
| 8982 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8983 | final long identity = Binder.clearCallingIdentity(); |
| 8984 | try { |
| 8985 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8986 | if (slots == null) { |
| 8987 | Rlog.i(LOG_TAG, "slots is null."); |
| 8988 | return null; |
| 8989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8990 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8991 | for (int i = 0; i < slots.length; i++) { |
| 8992 | UiccSlot slot = slots[i]; |
| 8993 | if (slot == null) { |
| 8994 | continue; |
| 8995 | } |
| 8996 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8997 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8998 | UiccCard card = slot.getUiccCard(); |
| 8999 | if (card != null) { |
| 9000 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9001 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9002 | cardId = slot.getEid(); |
| 9003 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9004 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 9005 | // read permission otherwise set to null.(card is null which means no |
| 9006 | // carrier permission) |
| 9007 | cardId = hasReadPermission ? slot.getIccId( |
| 9008 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9009 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9010 | } |
| 9011 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9012 | if (cardId != null) { |
| 9013 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9014 | // if cardId is an EID, it's all digits so this is fine |
| 9015 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9016 | } |
| 9017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9018 | int cardState = 0; |
| 9019 | switch (slot.getCardState()) { |
| 9020 | case CARDSTATE_ABSENT: |
| 9021 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9022 | break; |
| 9023 | case CARDSTATE_PRESENT: |
| 9024 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9025 | break; |
| 9026 | case CARDSTATE_ERROR: |
| 9027 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9028 | break; |
| 9029 | case CARDSTATE_RESTRICTED: |
| 9030 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9031 | break; |
| 9032 | default: |
| 9033 | break; |
| 9034 | |
| 9035 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9036 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9037 | int[] portIndexes = slot.getPortList(); |
| 9038 | for (int portIdx : portIndexes) { |
| 9039 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 9040 | callingPackage, hasReadPermission)); |
| 9041 | if (slot.isPortActive(portIdx)) { |
| 9042 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 9043 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 9044 | port.getPhoneId(), true)); |
| 9045 | } else { |
| 9046 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 9047 | } |
| 9048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9049 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9050 | slot.isEuicc(), |
| 9051 | cardId, |
| 9052 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9053 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9054 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9055 | //setting the value after compatibility check |
| 9056 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9057 | } |
| 9058 | return infos; |
| 9059 | } finally { |
| 9060 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9061 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9062 | } |
| 9063 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9064 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9065 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9066 | boolean hasReadPermission) { |
| 9067 | String iccId = slot.getIccId(portIndex); |
| 9068 | if (hasReadPermission) { // if has read permission |
| 9069 | return iccId; |
| 9070 | } else { |
| 9071 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9072 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9073 | // if no read permission, checking carrier privilege access |
| 9074 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9075 | return iccId; |
| 9076 | } |
| 9077 | } |
| 9078 | } |
| 9079 | // No read permission or carrier privilege access. |
| 9080 | return UiccPortInfo.ICCID_REDACTED; |
| 9081 | } |
| 9082 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9083 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9084 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9085 | public boolean switchSlots(int[] physicalSlots) { |
| 9086 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9087 | |
| 9088 | final long identity = Binder.clearCallingIdentity(); |
| 9089 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9090 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9091 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9092 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9093 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9094 | physicalSlots[i], i)); |
| 9095 | } |
| 9096 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9097 | } finally { |
| 9098 | Binder.restoreCallingIdentity(identity); |
| 9099 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9100 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9101 | |
| 9102 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9103 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9104 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9105 | enforceModifyPermission(); |
| 9106 | |
| 9107 | final long identity = Binder.clearCallingIdentity(); |
| 9108 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9109 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9110 | } finally { |
| 9111 | Binder.restoreCallingIdentity(identity); |
| 9112 | } |
| 9113 | } |
| 9114 | |
| 9115 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9116 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9117 | final long identity = Binder.clearCallingIdentity(); |
| 9118 | try { |
| 9119 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9120 | } finally { |
| 9121 | Binder.restoreCallingIdentity(identity); |
| 9122 | } |
| 9123 | } |
| 9124 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9125 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9126 | * A test API to reload the UICC profile. |
| 9127 | * |
| 9128 | * <p>Requires that the calling app has permission |
| 9129 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9130 | * @hide |
| 9131 | */ |
| 9132 | @Override |
| 9133 | public void refreshUiccProfile(int subId) { |
| 9134 | enforceModifyPermission(); |
| 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | Phone phone = getPhone(subId); |
| 9139 | if (phone == null) { |
| 9140 | return; |
| 9141 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9142 | UiccPort uiccPort = phone.getUiccPort(); |
| 9143 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9144 | return; |
| 9145 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9146 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9147 | if (uiccProfile == null) { |
| 9148 | return; |
| 9149 | } |
| 9150 | uiccProfile.refresh(); |
| 9151 | } finally { |
| 9152 | Binder.restoreCallingIdentity(identity); |
| 9153 | } |
| 9154 | } |
| 9155 | |
| 9156 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9157 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9158 | */ |
| 9159 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9160 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9161 | } |
| 9162 | |
| 9163 | /** |
| 9164 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9165 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9166 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9167 | */ |
| 9168 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9169 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9170 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9171 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9172 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9173 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9174 | return isDataRoamingEnabled; |
| 9175 | } |
| 9176 | |
| 9177 | /** |
| 9178 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9179 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9180 | */ |
| 9181 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9182 | List<Integer> list = TelephonyProperties.default_network(); |
| 9183 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9184 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9185 | return list.get(phoneId); |
| 9186 | } |
| 9187 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9188 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9189 | |
| 9190 | @Override |
| 9191 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9192 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9193 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9194 | |
| 9195 | final long identity = Binder.clearCallingIdentity(); |
| 9196 | try { |
| 9197 | final Phone phone = getPhone(subId); |
| 9198 | if (phone == null) { |
| 9199 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9200 | return; |
| 9201 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9202 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9203 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9204 | if (carrierPrivilegeRules == null) { |
| 9205 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9206 | } else { |
| 9207 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9209 | } finally { |
| 9210 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9211 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9212 | } |
| 9213 | |
| 9214 | @Override |
| 9215 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9216 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9217 | |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
| 9219 | try { |
| 9220 | final Phone phone = getPhone(subId); |
| 9221 | if (phone == null) { |
| 9222 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9223 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9224 | } |
| 9225 | return phone.getCarrierIdListVersion(); |
| 9226 | } finally { |
| 9227 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9228 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9229 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9230 | |
| 9231 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9232 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9233 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9234 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9235 | mApp, subId, callingPackage, callingFeatureId, |
| 9236 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9237 | return -1; |
| 9238 | } |
| 9239 | |
| 9240 | final long identity = Binder.clearCallingIdentity(); |
| 9241 | try { |
| 9242 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9243 | } finally { |
| 9244 | Binder.restoreCallingIdentity(identity); |
| 9245 | } |
| 9246 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9247 | |
| 9248 | @Override |
| 9249 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9250 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9251 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9252 | mApp, subId, "getCdmaRoamingMode"); |
| 9253 | |
| 9254 | final long identity = Binder.clearCallingIdentity(); |
| 9255 | try { |
| 9256 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9257 | } finally { |
| 9258 | Binder.restoreCallingIdentity(identity); |
| 9259 | } |
| 9260 | } |
| 9261 | |
| 9262 | @Override |
| 9263 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9265 | mApp, subId, "setCdmaRoamingMode"); |
| 9266 | |
| 9267 | final long identity = Binder.clearCallingIdentity(); |
| 9268 | try { |
| 9269 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9270 | } finally { |
| 9271 | Binder.restoreCallingIdentity(identity); |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9276 | public int getCdmaSubscriptionMode(int subId) { |
| 9277 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9278 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9279 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9280 | |
| 9281 | final long identity = Binder.clearCallingIdentity(); |
| 9282 | try { |
| 9283 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9290 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9292 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9293 | |
| 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9297 | } finally { |
| 9298 | Binder.restoreCallingIdentity(identity); |
| 9299 | } |
| 9300 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9301 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9302 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9303 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9304 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9305 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9306 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9307 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9308 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9309 | } |
| 9310 | final long identity = Binder.clearCallingIdentity(); |
| 9311 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9312 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9313 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9314 | if (phone.getEmergencyNumberTracker() != null |
| 9315 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9316 | emergencyNumberListInternal.put( |
| 9317 | phone.getSubId(), |
| 9318 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9319 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9320 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9321 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9322 | } finally { |
| 9323 | Binder.restoreCallingIdentity(identity); |
| 9324 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9325 | } |
| 9326 | |
| 9327 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9328 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9329 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9330 | if (!exactMatch) { |
| 9331 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9332 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9333 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9334 | } |
| 9335 | final long identity = Binder.clearCallingIdentity(); |
| 9336 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9337 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9338 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9339 | && phone.getEmergencyNumberTracker() |
| 9340 | .isEmergencyNumber(number, exactMatch)) { |
| 9341 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9342 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9343 | } |
| 9344 | return false; |
| 9345 | } finally { |
| 9346 | Binder.restoreCallingIdentity(identity); |
| 9347 | } |
| 9348 | } |
| 9349 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9350 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9351 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9352 | */ |
| 9353 | @Override |
| 9354 | public void startEmergencyCallbackMode() { |
| 9355 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9356 | "startEmergencyCallbackMode"); |
| 9357 | enforceModifyPermission(); |
| 9358 | final long identity = Binder.clearCallingIdentity(); |
| 9359 | try { |
| 9360 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9361 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9362 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9363 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9364 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9365 | gsmCdmaPhone.obtainMessage( |
| 9366 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9367 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9368 | } |
| 9369 | } |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9376 | * Update emergency number list for test mode. |
| 9377 | */ |
| 9378 | @Override |
| 9379 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9381 | "updateEmergencyNumberListTestMode"); |
| 9382 | |
| 9383 | final long identity = Binder.clearCallingIdentity(); |
| 9384 | try { |
| 9385 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9386 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9387 | if (tracker != null) { |
| 9388 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9389 | } |
| 9390 | } |
| 9391 | } finally { |
| 9392 | Binder.restoreCallingIdentity(identity); |
| 9393 | } |
| 9394 | } |
| 9395 | |
| 9396 | /** |
| 9397 | * Get the full emergency number list for test mode. |
| 9398 | */ |
| 9399 | @Override |
| 9400 | public List<String> getEmergencyNumberListTestMode() { |
| 9401 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9402 | "getEmergencyNumberListTestMode"); |
| 9403 | |
| 9404 | final long identity = Binder.clearCallingIdentity(); |
| 9405 | try { |
| 9406 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9407 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9408 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9409 | if (tracker != null) { |
| 9410 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9411 | emergencyNumbers.add(num.getNumber()); |
| 9412 | } |
| 9413 | } |
| 9414 | } |
| 9415 | return new ArrayList<>(emergencyNumbers); |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
| 9418 | } |
| 9419 | } |
| 9420 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9421 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9422 | public int getEmergencyNumberDbVersion(int subId) { |
| 9423 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9424 | |
| 9425 | final long identity = Binder.clearCallingIdentity(); |
| 9426 | try { |
| 9427 | final Phone phone = getPhone(subId); |
| 9428 | if (phone == null) { |
| 9429 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9430 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9431 | } |
| 9432 | return phone.getEmergencyNumberDbVersion(); |
| 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
| 9437 | |
| 9438 | @Override |
| 9439 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9440 | enforceModifyPermission(); |
| 9441 | |
| 9442 | final long identity = Binder.clearCallingIdentity(); |
| 9443 | try { |
| 9444 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9445 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9446 | if (tracker != null) { |
| 9447 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9448 | } |
| 9449 | } |
| 9450 | } finally { |
| 9451 | Binder.restoreCallingIdentity(identity); |
| 9452 | } |
| 9453 | } |
| 9454 | |
| 9455 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9456 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9457 | enforceActiveEmergencySessionPermission(); |
| 9458 | |
| 9459 | final long identity = Binder.clearCallingIdentity(); |
| 9460 | try { |
| 9461 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9462 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9463 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9464 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9465 | } |
| 9466 | } |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
| 9472 | @Override |
| 9473 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9474 | enforceActiveEmergencySessionPermission(); |
| 9475 | |
| 9476 | final long identity = Binder.clearCallingIdentity(); |
| 9477 | try { |
| 9478 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9479 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9480 | if (tracker != null) { |
| 9481 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9482 | } |
| 9483 | } |
| 9484 | } finally { |
| 9485 | Binder.restoreCallingIdentity(identity); |
| 9486 | } |
| 9487 | } |
| 9488 | |
| 9489 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9490 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9491 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9492 | Phone phone = getPhone(subId); |
| 9493 | if (phone == null) { |
| 9494 | return null; |
| 9495 | } |
| 9496 | final long identity = Binder.clearCallingIdentity(); |
| 9497 | try { |
| 9498 | UiccProfile profile = UiccController.getInstance() |
| 9499 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9500 | if (profile != null) { |
| 9501 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9502 | } |
| 9503 | } finally { |
| 9504 | Binder.restoreCallingIdentity(identity); |
| 9505 | } |
| 9506 | return null; |
| 9507 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9508 | |
| 9509 | /** |
| 9510 | * Enable or disable a modem stack. |
| 9511 | */ |
| 9512 | @Override |
| 9513 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9514 | enforceModifyPermission(); |
| 9515 | |
| 9516 | final long identity = Binder.clearCallingIdentity(); |
| 9517 | try { |
| 9518 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9519 | if (phone == null) { |
| 9520 | return false; |
| 9521 | } else { |
| 9522 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9523 | } |
| 9524 | } finally { |
| 9525 | Binder.restoreCallingIdentity(identity); |
| 9526 | } |
| 9527 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9528 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9529 | /** |
| 9530 | * Whether a modem stack is enabled or not. |
| 9531 | */ |
| 9532 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9533 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9534 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9535 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9536 | if (phone == null) return false; |
| 9537 | |
| 9538 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9539 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9540 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9541 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9542 | } |
| 9543 | |
| 9544 | final long identity = Binder.clearCallingIdentity(); |
| 9545 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9546 | try { |
| 9547 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9548 | } catch (NoSuchElementException ex) { |
| 9549 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9550 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
| 9554 | } |
| 9555 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9556 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9557 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9558 | enforceModifyPermission(); |
| 9559 | |
| 9560 | final long identity = Binder.clearCallingIdentity(); |
| 9561 | try { |
| 9562 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9563 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9564 | .commit(); |
| 9565 | } finally { |
| 9566 | Binder.restoreCallingIdentity(identity); |
| 9567 | } |
| 9568 | } |
| 9569 | |
| 9570 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9571 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9572 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9574 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9575 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9576 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9577 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9578 | |
| 9579 | final long identity = Binder.clearCallingIdentity(); |
| 9580 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9581 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9582 | } finally { |
| 9583 | Binder.restoreCallingIdentity(identity); |
| 9584 | } |
| 9585 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9586 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9587 | @TelephonyManager.IsMultiSimSupportedResult |
| 9588 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9589 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9590 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9591 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9592 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9593 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9594 | } |
| 9595 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9596 | // supported by the modem, indicate that it is restricted. |
| 9597 | PhoneCapability staticCapability = |
| 9598 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9599 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9600 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9601 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9602 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9603 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9604 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9605 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9606 | } |
| 9607 | // Check if support of multiple SIMs is restricted by carrier |
| 9608 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9609 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9610 | } |
| 9611 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9612 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9613 | } |
| 9614 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9615 | /** |
| 9616 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9617 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9618 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9619 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9620 | * @param numOfSims number of active sims we want to switch to |
| 9621 | */ |
| 9622 | @Override |
| 9623 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9624 | if (numOfSims == 1) { |
| 9625 | enforceModifyPermission(); |
| 9626 | } else { |
| 9627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9628 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9629 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9630 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9631 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9632 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9633 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9634 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9635 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9636 | return; |
| 9637 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9638 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9644 | @Override |
| 9645 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9646 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9647 | Phone phone = getPhone(subId); |
| 9648 | if (phone == null) { |
| 9649 | return false; |
| 9650 | } |
| 9651 | final long identity = Binder.clearCallingIdentity(); |
| 9652 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9653 | UiccPort uiccPort = phone.getUiccPort(); |
| 9654 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9655 | return false; |
| 9656 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9657 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9658 | if (uiccProfile == null) { |
| 9659 | return false; |
| 9660 | } |
| 9661 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9662 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9663 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9664 | } |
| 9665 | return false; |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | } |
| 9670 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9671 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9672 | * Get whether making changes to modem configurations will trigger reboot. |
| 9673 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9674 | */ |
| 9675 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9676 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9677 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9679 | mApp, subId, callingPackage, callingFeatureId, |
| 9680 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9681 | return false; |
| 9682 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9683 | final long identity = Binder.clearCallingIdentity(); |
| 9684 | try { |
| 9685 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9686 | } finally { |
| 9687 | Binder.restoreCallingIdentity(identity); |
| 9688 | } |
| 9689 | } |
| 9690 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9691 | private void updateModemStateMetrics() { |
| 9692 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9693 | // TODO: check the state for each modem if the api is ready. |
| 9694 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9695 | } |
| 9696 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9697 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9698 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9699 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9700 | // Verify that the callingPackage belongs to the calling UID |
| 9701 | mApp.getSystemService(AppOpsManager.class) |
| 9702 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9703 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9704 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9705 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9706 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9707 | if (slotInfos != null) { |
| 9708 | for (int i = 0; i < slotInfos.length; i++) { |
| 9709 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9710 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9711 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9712 | portInfo.getLogicalSlotIndex())); |
| 9713 | } |
| 9714 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9715 | } |
| 9716 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9717 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9718 | } finally { |
| 9719 | Binder.restoreCallingIdentity(identity); |
| 9720 | } |
| 9721 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9722 | |
| 9723 | /** |
| 9724 | * Get the IRadio HAL Version |
| 9725 | */ |
| 9726 | @Override |
| 9727 | public int getRadioHalVersion() { |
| 9728 | Phone phone = getDefaultPhone(); |
| 9729 | if (phone == null) return -1; |
| 9730 | HalVersion hv = phone.getHalVersion(); |
| 9731 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9732 | return hv.major * 100 + hv.minor; |
| 9733 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9734 | |
| 9735 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9736 | * Get the current calling package name. |
| 9737 | * @return the current calling package name |
| 9738 | */ |
| 9739 | @Override |
| 9740 | public String getCurrentPackageName() { |
| 9741 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9742 | } |
| 9743 | |
| 9744 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9745 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9746 | * corresponding network requests on a subId. |
| 9747 | * |
| 9748 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9749 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9750 | * 2) APN is un-metered for this subscription, or |
| 9751 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9752 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9753 | * |
| 9754 | * @return whether data is allowed for a apn type. |
| 9755 | * |
| 9756 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9757 | */ |
| 9758 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9759 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9760 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9761 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9762 | |
| 9763 | // Now that all security checks passes, perform the operation as ourselves. |
| 9764 | final long identity = Binder.clearCallingIdentity(); |
| 9765 | try { |
| 9766 | Phone phone = getPhone(subId); |
| 9767 | if (phone == null) return false; |
| 9768 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9769 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9770 | boolean isDataEnabled; |
| 9771 | if (phone.isUsingNewDataStack()) { |
| 9772 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9773 | } else { |
| 9774 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9775 | } |
| 9776 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9777 | } finally { |
| 9778 | Binder.restoreCallingIdentity(identity); |
| 9779 | } |
| 9780 | } |
| 9781 | |
| 9782 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9783 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9784 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9785 | |
| 9786 | // Now that all security checks passes, perform the operation as ourselves. |
| 9787 | final long identity = Binder.clearCallingIdentity(); |
| 9788 | try { |
| 9789 | Phone phone = getPhone(subId); |
| 9790 | if (phone == null) return true; // By default return true. |
| 9791 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9792 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9793 | } finally { |
| 9794 | Binder.restoreCallingIdentity(identity); |
| 9795 | } |
| 9796 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9797 | |
| 9798 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9799 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9800 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9801 | enforceModifyPermission(); |
| 9802 | long token = Binder.clearCallingIdentity(); |
| 9803 | try { |
| 9804 | Phone phone = getPhone(subscriptionId); |
| 9805 | if (phone == null) { |
| 9806 | try { |
| 9807 | if (resultCallback != null) { |
| 9808 | resultCallback.accept(false); |
| 9809 | } |
| 9810 | } catch (RemoteException e) { |
| 9811 | // ignore |
| 9812 | } |
| 9813 | return; |
| 9814 | } |
| 9815 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9816 | Pair.create(specifiers, (x) -> { |
| 9817 | try { |
| 9818 | if (resultCallback != null) { |
| 9819 | resultCallback.accept(x); |
| 9820 | } |
| 9821 | } catch (RemoteException e) { |
| 9822 | // ignore |
| 9823 | } |
| 9824 | }); |
| 9825 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9826 | } finally { |
| 9827 | Binder.restoreCallingIdentity(token); |
| 9828 | } |
| 9829 | } |
| 9830 | |
| 9831 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9832 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9833 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9834 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9835 | mApp, subId, "getSystemSelectionChannels"); |
| 9836 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9837 | final long identity = Binder.clearCallingIdentity(); |
| 9838 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9839 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9840 | if (result instanceof IllegalStateException) { |
| 9841 | throw (IllegalStateException) result; |
| 9842 | } |
| 9843 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9844 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9845 | return specifiers; |
| 9846 | } finally { |
| 9847 | Binder.restoreCallingIdentity(identity); |
| 9848 | } |
| 9849 | } |
| 9850 | |
| 9851 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9852 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9853 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9854 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9855 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9856 | if (iccRecords == null) { |
| 9857 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9858 | return false; |
| 9859 | } |
| 9860 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9861 | } |
| 9862 | |
| 9863 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9864 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9865 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9866 | if (callingPackage == null) { |
| 9867 | callingPackage = getCurrentPackageName(); |
| 9868 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9869 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9870 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9871 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9872 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9873 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9874 | } |
| 9875 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9876 | Intent intent = new Intent(); |
| 9877 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9878 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9879 | // Bring up choose default SMS subscription dialog right now |
| 9880 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9881 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9882 | mApp.startActivity(intent); |
| 9883 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9884 | |
| 9885 | @Override |
| 9886 | public String getMmsUAProfUrl(int subId) { |
| 9887 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9888 | final long identity = Binder.clearCallingIdentity(); |
| 9889 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9890 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9891 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9892 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9893 | return carrierUAProfUrl; |
| 9894 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9895 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9896 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9897 | } finally { |
| 9898 | Binder.restoreCallingIdentity(identity); |
| 9899 | } |
| 9900 | } |
| 9901 | |
| 9902 | @Override |
| 9903 | public String getMmsUserAgent(int subId) { |
| 9904 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9905 | final long identity = Binder.clearCallingIdentity(); |
| 9906 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9907 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9908 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9909 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9910 | return carrierUserAgent; |
| 9911 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9912 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9913 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9914 | } finally { |
| 9915 | Binder.restoreCallingIdentity(identity); |
| 9916 | } |
| 9917 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9918 | |
| 9919 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9920 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9921 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9922 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9923 | final long identity = Binder.clearCallingIdentity(); |
| 9924 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9925 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9926 | if (phone == null) return false; |
| 9927 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9928 | switch (policy) { |
| 9929 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9930 | if (phone.isUsingNewDataStack()) { |
| 9931 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9932 | } else { |
| 9933 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9934 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9935 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9936 | if (phone.isUsingNewDataStack()) { |
| 9937 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9938 | } else { |
| 9939 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9940 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9941 | default: |
| 9942 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9943 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9944 | } finally { |
| 9945 | Binder.restoreCallingIdentity(identity); |
| 9946 | } |
| 9947 | } |
| 9948 | |
| 9949 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9950 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9951 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9952 | enforceModifyPermission(); |
| 9953 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9954 | final long identity = Binder.clearCallingIdentity(); |
| 9955 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9956 | Phone phone = getPhone(subscriptionId); |
| 9957 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9958 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9959 | switch (policy) { |
| 9960 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9961 | if (phone.isUsingNewDataStack()) { |
| 9962 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9963 | } else { |
| 9964 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9965 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9966 | break; |
| 9967 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9968 | if (phone.isUsingNewDataStack()) { |
| 9969 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9970 | } else { |
| 9971 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9972 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9973 | break; |
| 9974 | default: |
| 9975 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9976 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9977 | } finally { |
| 9978 | Binder.restoreCallingIdentity(identity); |
| 9979 | } |
| 9980 | } |
| 9981 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9982 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9983 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9984 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9985 | * otherwise. |
| 9986 | */ |
| 9987 | @Override |
| 9988 | public void setCepEnabled(boolean isCepEnabled) { |
| 9989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9990 | |
| 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9994 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9995 | Phone defaultPhone = phone.getImsPhone(); |
| 9996 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9997 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9998 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9999 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10000 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10001 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10002 | + imsPhone.getMsisdn()); |
| 10003 | } |
| 10004 | } |
| 10005 | } finally { |
| 10006 | Binder.restoreCallingIdentity(identity); |
| 10007 | } |
| 10008 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10009 | |
| 10010 | /** |
| 10011 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10012 | * |
| 10013 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10014 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10015 | * before being read. |
| 10016 | */ |
| 10017 | @Override |
| 10018 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10019 | isCompressed) { |
| 10020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10021 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10022 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10023 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10024 | } |
| 10025 | if (!isImsAvailableOnDevice()) { |
| 10026 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10027 | "IMS not available on device."); |
| 10028 | } |
| 10029 | |
| 10030 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10031 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10032 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10033 | } finally { |
| 10034 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10035 | } |
| 10036 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10037 | |
| 10038 | @Override |
| 10039 | public boolean isIccLockEnabled(int subId) { |
| 10040 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10041 | |
| 10042 | // Now that all security checks passes, perform the operation as ourselves. |
| 10043 | final long identity = Binder.clearCallingIdentity(); |
| 10044 | try { |
| 10045 | Phone phone = getPhone(subId); |
| 10046 | if (phone != null && phone.getIccCard() != null) { |
| 10047 | return phone.getIccCard().getIccLockEnabled(); |
| 10048 | } else { |
| 10049 | return false; |
| 10050 | } |
| 10051 | } finally { |
| 10052 | Binder.restoreCallingIdentity(identity); |
| 10053 | } |
| 10054 | } |
| 10055 | |
| 10056 | /** |
| 10057 | * Set the ICC pin lock enabled or disabled. |
| 10058 | * |
| 10059 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10060 | * three cases: |
| 10061 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10062 | * successfully. |
| 10063 | * - Positive number and zero for remaining password attempts. |
| 10064 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10065 | * |
| 10066 | */ |
| 10067 | @Override |
| 10068 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10069 | enforceModifyPermission(); |
| 10070 | |
| 10071 | Phone phone = getPhone(subId); |
| 10072 | if (phone == null) { |
| 10073 | return 0; |
| 10074 | } |
| 10075 | // Now that all security checks passes, perform the operation as ourselves. |
| 10076 | final long identity = Binder.clearCallingIdentity(); |
| 10077 | try { |
| 10078 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10079 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10080 | return attemptsRemaining; |
| 10081 | |
| 10082 | } catch (Exception e) { |
| 10083 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10084 | } finally { |
| 10085 | Binder.restoreCallingIdentity(identity); |
| 10086 | } |
| 10087 | return 0; |
| 10088 | } |
| 10089 | |
| 10090 | /** |
| 10091 | * Change the ICC password used in ICC pin lock. |
| 10092 | * |
| 10093 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10094 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10095 | * - Positive number and zero for remaining password attempts. |
| 10096 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10097 | * |
| 10098 | */ |
| 10099 | @Override |
| 10100 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10101 | enforceModifyPermission(); |
| 10102 | |
| 10103 | Phone phone = getPhone(subId); |
| 10104 | if (phone == null) { |
| 10105 | return 0; |
| 10106 | } |
| 10107 | // Now that all security checks passes, perform the operation as ourselves. |
| 10108 | final long identity = Binder.clearCallingIdentity(); |
| 10109 | try { |
| 10110 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10111 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10112 | return attemptsRemaining; |
| 10113 | |
| 10114 | } catch (Exception e) { |
| 10115 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10116 | } finally { |
| 10117 | Binder.restoreCallingIdentity(identity); |
| 10118 | } |
| 10119 | return 0; |
| 10120 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10121 | |
| 10122 | /** |
| 10123 | * Request for receiving user activity notification |
| 10124 | */ |
| 10125 | @Override |
| 10126 | public void requestUserActivityNotification() { |
| 10127 | if (!mNotifyUserActivity.get() |
| 10128 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10129 | mNotifyUserActivity.set(true); |
| 10130 | } |
| 10131 | } |
| 10132 | |
| 10133 | /** |
| 10134 | * Called when userActivity is signalled in the power manager. |
| 10135 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10136 | */ |
| 10137 | @Override |
| 10138 | public void userActivity() { |
| 10139 | // *************************************** |
| 10140 | // * Inherited from PhoneWindowManager * |
| 10141 | // *************************************** |
| 10142 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10143 | // WITH ITS LOCKS HELD. |
| 10144 | // |
| 10145 | // This code must be VERY careful about the locks |
| 10146 | // it acquires. |
| 10147 | // In fact, the current code acquires way too many, |
| 10148 | // and probably has lurking deadlocks. |
| 10149 | |
| 10150 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10151 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10152 | } |
| 10153 | |
| 10154 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10155 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10156 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10157 | } |
| 10158 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10159 | |
| 10160 | @Override |
| 10161 | public boolean canConnectTo5GInDsdsMode() { |
| 10162 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10163 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10164 | |
| 10165 | @Override |
| 10166 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10167 | String callingFeatureId) { |
| 10168 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10169 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10170 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10171 | } |
| 10172 | |
| 10173 | Phone phone = getPhone(subId); |
| 10174 | if (phone == null) { |
| 10175 | throw new RuntimeException("phone is not available"); |
| 10176 | } |
| 10177 | // Now that all security checks passes, perform the operation as ourselves. |
| 10178 | final long identity = Binder.clearCallingIdentity(); |
| 10179 | try { |
| 10180 | return phone.getEquivalentHomePlmns(); |
| 10181 | } finally { |
| 10182 | Binder.restoreCallingIdentity(identity); |
| 10183 | } |
| 10184 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10185 | |
| 10186 | @Override |
| 10187 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10188 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10189 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10190 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10191 | if (radioInterfaceCapabilities == null) { |
| 10192 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10193 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10194 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10195 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10196 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10197 | @Override |
| 10198 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10199 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10200 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10201 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10202 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10203 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10204 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10205 | if (DBG) { |
| 10206 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10207 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10208 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10209 | } |
| 10210 | |
| 10211 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10212 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10213 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10214 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10215 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10216 | if (callback != null) { |
| 10217 | try { |
| 10218 | callback.onAuthenticationFailure( |
| 10219 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10220 | } catch (RemoteException exception) { |
| 10221 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10222 | } |
| 10223 | return; |
| 10224 | } |
| 10225 | } |
| 10226 | |
| 10227 | final long token = Binder.clearCallingIdentity(); |
| 10228 | try { |
| 10229 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10230 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10231 | forceBootStrapping, callback)); |
| 10232 | } finally { |
| 10233 | Binder.restoreCallingIdentity(token); |
| 10234 | } |
| 10235 | } |
| 10236 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10237 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10238 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10239 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10240 | * requested radio power state will actually be set. See {@link |
| 10241 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10242 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10243 | * @param enable {@code true} if trying to turn radio on. |
| 10244 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10245 | * false}. |
| 10246 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10247 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10248 | boolean isPhoneAvailable = false; |
| 10249 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10250 | Phone phone = PhoneFactory.getPhone(i); |
| 10251 | if (phone != null) { |
| 10252 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10253 | isPhoneAvailable = true; |
| 10254 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10255 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10256 | |
| 10257 | // return true if successfully informed the phone object about the thermal radio power |
| 10258 | // request. |
| 10259 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10260 | } |
| 10261 | |
| 10262 | private int handleDataThrottlingRequest(int subId, |
| 10263 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10264 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10265 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10266 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10267 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10268 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10269 | } |
| 10270 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10271 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10272 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10273 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10274 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10275 | } |
| 10276 | |
| 10277 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10278 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10279 | if (isDataThrottlingSupported) { |
| 10280 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10281 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10282 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10283 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10284 | } else if (thermalMitigationResult |
| 10285 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10286 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10287 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10288 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10289 | } |
| 10290 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10291 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10292 | |
| 10293 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10294 | } |
| 10295 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10296 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10297 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10298 | for (String pckg : context.getResources() |
| 10299 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10300 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10301 | } |
| 10302 | } |
| 10303 | |
| 10304 | return sThermalMitigationAllowlistedPackages; |
| 10305 | } |
| 10306 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10307 | private boolean isAnyPhoneInEmergencyState() { |
| 10308 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10309 | if (tm.isInEmergencyCall()) { |
| 10310 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10311 | return true; |
| 10312 | } |
| 10313 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10314 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10315 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10316 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10317 | + phone.isInEcm()); |
| 10318 | return true; |
| 10319 | } |
| 10320 | } |
| 10321 | |
| 10322 | return false; |
| 10323 | } |
| 10324 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10325 | /** |
| 10326 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10327 | * @param packageName name of package to be allowlisted |
| 10328 | * @param context |
| 10329 | */ |
| 10330 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10331 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10332 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10333 | } |
| 10334 | |
| 10335 | /** |
| 10336 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10337 | * @param packageName name of package to remove from allowlist |
| 10338 | * @param context |
| 10339 | */ |
| 10340 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10341 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10342 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10343 | } |
| 10344 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10345 | /** |
| 10346 | * Thermal mitigation request to control functionalities at modem. |
| 10347 | * |
| 10348 | * @param subId the id of the subscription. |
| 10349 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10350 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10351 | * |
| 10352 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10353 | */ |
| 10354 | @Override |
| 10355 | @ThermalMitigationResult |
| 10356 | public int sendThermalMitigationRequest( |
| 10357 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10358 | ThermalMitigationRequest thermalMitigationRequest, |
| 10359 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10360 | enforceModifyPermission(); |
| 10361 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10362 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10363 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10364 | .contains(callingPackage)) { |
| 10365 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10366 | + "calling package: " + callingPackage); |
| 10367 | } |
| 10368 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10369 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10370 | final long identity = Binder.clearCallingIdentity(); |
| 10371 | |
| 10372 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10373 | try { |
| 10374 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10375 | switch (thermalMitigationAction) { |
| 10376 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10377 | thermalMitigationResult = |
| 10378 | handleDataThrottlingRequest(subId, |
| 10379 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10380 | break; |
| 10381 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10382 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10383 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10384 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10385 | } |
| 10386 | |
| 10387 | // Ensure that radio is on. If not able to power on due to phone being |
| 10388 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10389 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10390 | thermalMitigationResult = |
| 10391 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10392 | break; |
| 10393 | } |
| 10394 | |
| 10395 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10396 | false); |
| 10397 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10398 | break; |
| 10399 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10400 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10401 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10402 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10403 | } |
| 10404 | |
| 10405 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10406 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10407 | Phone phone = getPhone(subId); |
| 10408 | if (phone == null) { |
| 10409 | thermalMitigationResult = |
| 10410 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10411 | break; |
| 10412 | } |
| 10413 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10414 | TelephonyConnectionService service = |
| 10415 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10416 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10417 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10418 | thermalMitigationResult = |
| 10419 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10420 | break; |
| 10421 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10422 | thermalMitigationResult = |
| 10423 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10424 | break; |
| 10425 | } |
| 10426 | } else { |
| 10427 | thermalMitigationResult = |
| 10428 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10429 | break; |
| 10430 | } |
| 10431 | |
| 10432 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10433 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10434 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10435 | thermalMitigationResult = |
| 10436 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10437 | break; |
| 10438 | } |
| 10439 | thermalMitigationResult = |
| 10440 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10441 | break; |
| 10442 | default: |
| 10443 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10444 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10445 | } |
| 10446 | } catch (IllegalArgumentException e) { |
| 10447 | throw e; |
| 10448 | } catch (Exception e) { |
| 10449 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10450 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10451 | } finally { |
| 10452 | Binder.restoreCallingIdentity(identity); |
| 10453 | } |
| 10454 | |
| 10455 | if (DBG) { |
| 10456 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10457 | + thermalMitigationResult); |
| 10458 | } |
| 10459 | |
| 10460 | return thermalMitigationResult; |
| 10461 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10462 | |
| 10463 | /** |
| 10464 | * Set the GbaService Package Name that Telephony will bind to. |
| 10465 | * |
| 10466 | * @param subId The sim that the GbaService is associated with. |
| 10467 | * @param packageName The name of the package to be replaced with. |
| 10468 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10469 | */ |
| 10470 | @Override |
| 10471 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10472 | enforceModifyPermission(); |
| 10473 | |
| 10474 | final long identity = Binder.clearCallingIdentity(); |
| 10475 | try { |
| 10476 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10477 | } finally { |
| 10478 | Binder.restoreCallingIdentity(identity); |
| 10479 | } |
| 10480 | } |
| 10481 | |
| 10482 | /** |
| 10483 | * Return the package name of the currently bound GbaService. |
| 10484 | * |
| 10485 | * @param subId The sim that the GbaService is associated with. |
| 10486 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10487 | */ |
| 10488 | @Override |
| 10489 | public String getBoundGbaService(int subId) { |
| 10490 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10491 | |
| 10492 | final long identity = Binder.clearCallingIdentity(); |
| 10493 | try { |
| 10494 | return getGbaManager(subId).getServicePackage(); |
| 10495 | } finally { |
| 10496 | Binder.restoreCallingIdentity(identity); |
| 10497 | } |
| 10498 | } |
| 10499 | |
| 10500 | /** |
| 10501 | * Set the release time for telephony to unbind GbaService. |
| 10502 | * |
| 10503 | * @param subId The sim that the GbaService is associated with. |
| 10504 | * @param interval The release time to unbind GbaService by millisecond. |
| 10505 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10506 | */ |
| 10507 | @Override |
| 10508 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10509 | enforceModifyPermission(); |
| 10510 | |
| 10511 | final long identity = Binder.clearCallingIdentity(); |
| 10512 | try { |
| 10513 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10514 | } finally { |
| 10515 | Binder.restoreCallingIdentity(identity); |
| 10516 | } |
| 10517 | } |
| 10518 | |
| 10519 | /** |
| 10520 | * Return the release time for telephony to unbind GbaService. |
| 10521 | * |
| 10522 | * @param subId The sim that the GbaService is associated with. |
| 10523 | * @return The release time to unbind GbaService by millisecond. |
| 10524 | */ |
| 10525 | @Override |
| 10526 | public int getGbaReleaseTime(int subId) { |
| 10527 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10528 | |
| 10529 | final long identity = Binder.clearCallingIdentity(); |
| 10530 | try { |
| 10531 | return getGbaManager(subId).getReleaseTime(); |
| 10532 | } finally { |
| 10533 | Binder.restoreCallingIdentity(identity); |
| 10534 | } |
| 10535 | } |
| 10536 | |
| 10537 | private GbaManager getGbaManager(int subId) { |
| 10538 | GbaManager instance = GbaManager.getInstance(subId); |
| 10539 | if (instance == null) { |
| 10540 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10541 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10542 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10543 | } |
| 10544 | return instance; |
| 10545 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10546 | |
| 10547 | /** |
| 10548 | * indicate whether the device and the carrier can support |
| 10549 | * RCS VoLTE single registration. |
| 10550 | */ |
| 10551 | @Override |
| 10552 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10553 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10554 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10555 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10556 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10557 | |
| 10558 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10559 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10560 | } |
| 10561 | |
| 10562 | final long identity = Binder.clearCallingIdentity(); |
| 10563 | try { |
| 10564 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10565 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10566 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10567 | if (isCapable != null) { |
| 10568 | return isCapable; |
| 10569 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10570 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10571 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10572 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10573 | } finally { |
| 10574 | Binder.restoreCallingIdentity(identity); |
| 10575 | } |
| 10576 | } |
| 10577 | |
| 10578 | /** |
| 10579 | * Register RCS provisioning callback. |
| 10580 | */ |
| 10581 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10582 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10583 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10584 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10585 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10586 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10587 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10588 | |
| 10589 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10590 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10591 | } |
| 10592 | if (!isImsAvailableOnDevice()) { |
| 10593 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10594 | "IMS not available on device."); |
| 10595 | } |
| 10596 | |
| 10597 | final long identity = Binder.clearCallingIdentity(); |
| 10598 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10599 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10600 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10601 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10602 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10603 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10604 | } finally { |
| 10605 | Binder.restoreCallingIdentity(identity); |
| 10606 | } |
| 10607 | } |
| 10608 | |
| 10609 | /** |
| 10610 | * Unregister RCS provisioning callback. |
| 10611 | */ |
| 10612 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10613 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10614 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10615 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10616 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10617 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10618 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10619 | |
| 10620 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10621 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10622 | } |
| 10623 | if (!isImsAvailableOnDevice()) { |
| 10624 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10625 | "IMS not available on device."); |
| 10626 | } |
| 10627 | |
| 10628 | final long identity = Binder.clearCallingIdentity(); |
| 10629 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10630 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10631 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10632 | } finally { |
| 10633 | Binder.restoreCallingIdentity(identity); |
| 10634 | } |
| 10635 | } |
| 10636 | |
| 10637 | /** |
| 10638 | * trigger RCS reconfiguration. |
| 10639 | */ |
| 10640 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10641 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10642 | "triggerRcsReconfiguration", |
| 10643 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10644 | |
| 10645 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10646 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10647 | } |
| 10648 | if (!isImsAvailableOnDevice()) { |
| 10649 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10650 | "IMS not available on device."); |
| 10651 | } |
| 10652 | |
| 10653 | final long identity = Binder.clearCallingIdentity(); |
| 10654 | try { |
| 10655 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10656 | } finally { |
| 10657 | Binder.restoreCallingIdentity(identity); |
| 10658 | } |
| 10659 | } |
| 10660 | |
| 10661 | /** |
| 10662 | * Provide the client configuration parameters of the RCS application. |
| 10663 | */ |
| 10664 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10665 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10666 | "setRcsClientConfiguration", |
| 10667 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10668 | |
| 10669 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10670 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10671 | } |
| 10672 | if (!isImsAvailableOnDevice()) { |
| 10673 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10674 | "IMS not available on device."); |
| 10675 | } |
| 10676 | |
| 10677 | final long identity = Binder.clearCallingIdentity(); |
| 10678 | |
| 10679 | try { |
| 10680 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10681 | if (configBinder == null) { |
| 10682 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10683 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10684 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10685 | } else { |
| 10686 | configBinder.setRcsClientConfiguration(rcc); |
| 10687 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10688 | |
| 10689 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10690 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10691 | } catch (RemoteException e) { |
| 10692 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10693 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10694 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10695 | } finally { |
| 10696 | Binder.restoreCallingIdentity(identity); |
| 10697 | } |
| 10698 | } |
| 10699 | |
| 10700 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10701 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10702 | */ |
| 10703 | @Override |
| 10704 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10705 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10706 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10707 | |
| 10708 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10709 | } |
| 10710 | |
| 10711 | /** |
| 10712 | * Gets the test mode for RCS VoLTE single registration. |
| 10713 | */ |
| 10714 | @Override |
| 10715 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10716 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10717 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10718 | |
| 10719 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10720 | } |
| 10721 | |
| 10722 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10723 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10724 | */ |
| 10725 | @Override |
| 10726 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10727 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10728 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10729 | enforceModifyPermission(); |
| 10730 | |
| 10731 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10732 | : Boolean.parseBoolean(enabledStr); |
| 10733 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10734 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10735 | } |
| 10736 | |
| 10737 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10738 | * Sends a device to device communication message. Only usable via shell. |
| 10739 | * @param message message to send. |
| 10740 | * @param value message value. |
| 10741 | */ |
| 10742 | @Override |
| 10743 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10744 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10745 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10746 | enforceModifyPermission(); |
| 10747 | |
| 10748 | final long identity = Binder.clearCallingIdentity(); |
| 10749 | try { |
| 10750 | TelephonyConnectionService service = |
| 10751 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10752 | if (service == null) { |
| 10753 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10754 | return; |
| 10755 | } |
| 10756 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10757 | } finally { |
| 10758 | Binder.restoreCallingIdentity(identity); |
| 10759 | } |
| 10760 | } |
| 10761 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10762 | /** |
| 10763 | * Sets the specified device to device transport active. |
| 10764 | * @param transport The transport to set active. |
| 10765 | */ |
| 10766 | @Override |
| 10767 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10768 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10769 | "setActiveDeviceToDeviceTransport"); |
| 10770 | enforceModifyPermission(); |
| 10771 | |
| 10772 | final long identity = Binder.clearCallingIdentity(); |
| 10773 | try { |
| 10774 | TelephonyConnectionService service = |
| 10775 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10776 | if (service == null) { |
| 10777 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10778 | return; |
| 10779 | } |
| 10780 | service.setActiveDeviceToDeviceTransport(transport); |
| 10781 | } finally { |
| 10782 | Binder.restoreCallingIdentity(identity); |
| 10783 | } |
| 10784 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10785 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10786 | @Override |
| 10787 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10788 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10789 | "setDeviceToDeviceForceEnabled"); |
| 10790 | |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10794 | p -> { |
| 10795 | Phone thePhone = p.getImsPhone(); |
| 10796 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10797 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10798 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10799 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10800 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10801 | (ImsPhoneCallTracker) tracker; |
| 10802 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10803 | } |
| 10804 | } |
| 10805 | } |
| 10806 | ); |
| 10807 | } finally { |
| 10808 | Binder.restoreCallingIdentity(identity); |
| 10809 | } |
| 10810 | } |
| 10811 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10812 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10813 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10814 | */ |
| 10815 | @Override |
| 10816 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10817 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10818 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10819 | } |
| 10820 | |
| 10821 | /** |
| 10822 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10823 | */ |
| 10824 | @Override |
| 10825 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10826 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10827 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10828 | enforceModifyPermission(); |
| 10829 | |
| 10830 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10831 | : Boolean.parseBoolean(enabledStr); |
| 10832 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10833 | subId, enabled); |
| 10834 | } |
| 10835 | |
| 10836 | /** |
| 10837 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10838 | */ |
| 10839 | @Override |
| 10840 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10841 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10842 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10843 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10844 | |
| 10845 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10846 | * Overrides the ims feature validation result |
| 10847 | */ |
| 10848 | @Override |
| 10849 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10850 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10851 | "setImsFeatureValidationOverride"); |
| 10852 | |
| 10853 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10854 | : Boolean.parseBoolean(enabledStr); |
| 10855 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10856 | subId, enabled); |
| 10857 | } |
| 10858 | |
| 10859 | /** |
| 10860 | * Gets the ims feature validation override value |
| 10861 | */ |
| 10862 | @Override |
| 10863 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10864 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10865 | "getImsFeatureValidationOverride"); |
| 10866 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10867 | } |
| 10868 | |
| 10869 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10870 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10871 | * their mobile plan. |
| 10872 | */ |
| 10873 | @Override |
| 10874 | public String getMobileProvisioningUrl() { |
| 10875 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10876 | final long identity = Binder.clearCallingIdentity(); |
| 10877 | try { |
| 10878 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10879 | } finally { |
| 10880 | Binder.restoreCallingIdentity(identity); |
| 10881 | } |
| 10882 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10883 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10884 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10885 | * Get the EAB contact from the EAB database. |
| 10886 | */ |
| 10887 | @Override |
| 10888 | public String getContactFromEab(String contact) { |
| 10889 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10890 | enforceModifyPermission(); |
| 10891 | final long identity = Binder.clearCallingIdentity(); |
| 10892 | try { |
| 10893 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10894 | } finally { |
| 10895 | Binder.restoreCallingIdentity(identity); |
| 10896 | } |
| 10897 | } |
| 10898 | |
| 10899 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10900 | * Get the EAB capability from the EAB database. |
| 10901 | */ |
| 10902 | @Override |
| 10903 | public String getCapabilityFromEab(String contact) { |
| 10904 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10905 | enforceModifyPermission(); |
| 10906 | final long identity = Binder.clearCallingIdentity(); |
| 10907 | try { |
| 10908 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10909 | } finally { |
| 10910 | Binder.restoreCallingIdentity(identity); |
| 10911 | } |
| 10912 | } |
| 10913 | |
| 10914 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10915 | * Remove the EAB contacts from the EAB database. |
| 10916 | */ |
| 10917 | @Override |
| 10918 | public int removeContactFromEab(int subId, String contacts) { |
| 10919 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10920 | enforceModifyPermission(); |
| 10921 | final long identity = Binder.clearCallingIdentity(); |
| 10922 | try { |
| 10923 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10924 | } finally { |
| 10925 | Binder.restoreCallingIdentity(identity); |
| 10926 | } |
| 10927 | } |
| 10928 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10929 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10930 | public boolean getDeviceUceEnabled() { |
| 10931 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10932 | final long identity = Binder.clearCallingIdentity(); |
| 10933 | try { |
| 10934 | return mApp.getDeviceUceEnabled(); |
| 10935 | } finally { |
| 10936 | Binder.restoreCallingIdentity(identity); |
| 10937 | } |
| 10938 | } |
| 10939 | |
| 10940 | @Override |
| 10941 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10942 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10943 | final long identity = Binder.clearCallingIdentity(); |
| 10944 | try { |
| 10945 | mApp.setDeviceUceEnabled(isEnabled); |
| 10946 | } finally { |
| 10947 | Binder.restoreCallingIdentity(identity); |
| 10948 | } |
| 10949 | } |
| 10950 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10951 | /** |
| 10952 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10953 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10954 | */ |
| 10955 | // Used for SHELL command only right now. |
| 10956 | @Override |
| 10957 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10958 | List<String> featureTags) { |
| 10959 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10960 | "addUceRegistrationOverrideShell"); |
| 10961 | final long identity = Binder.clearCallingIdentity(); |
| 10962 | try { |
| 10963 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10964 | new ArraySet<>(featureTags)); |
| 10965 | } catch (ImsException e) { |
| 10966 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10967 | } finally { |
| 10968 | Binder.restoreCallingIdentity(identity); |
| 10969 | } |
| 10970 | } |
| 10971 | |
| 10972 | /** |
| 10973 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10974 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10975 | */ |
| 10976 | // Used for SHELL command only right now. |
| 10977 | @Override |
| 10978 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10979 | List<String> featureTags) { |
| 10980 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10981 | "removeUceRegistrationOverrideShell"); |
| 10982 | final long identity = Binder.clearCallingIdentity(); |
| 10983 | try { |
| 10984 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10985 | new ArraySet<>(featureTags)); |
| 10986 | } catch (ImsException e) { |
| 10987 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10988 | } finally { |
| 10989 | Binder.restoreCallingIdentity(identity); |
| 10990 | } |
| 10991 | } |
| 10992 | |
| 10993 | /** |
| 10994 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10995 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10996 | */ |
| 10997 | // Used for SHELL command only right now. |
| 10998 | @Override |
| 10999 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11000 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11001 | "clearUceRegistrationOverrideShell"); |
| 11002 | final long identity = Binder.clearCallingIdentity(); |
| 11003 | try { |
| 11004 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11005 | } catch (ImsException e) { |
| 11006 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11007 | } finally { |
| 11008 | Binder.restoreCallingIdentity(identity); |
| 11009 | } |
| 11010 | } |
| 11011 | |
| 11012 | /** |
| 11013 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11014 | */ |
| 11015 | // Used for SHELL command only right now. |
| 11016 | @Override |
| 11017 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11018 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11019 | "getLatestRcsContactUceCapabilityShell"); |
| 11020 | final long identity = Binder.clearCallingIdentity(); |
| 11021 | try { |
| 11022 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11023 | } catch (ImsException e) { |
| 11024 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11025 | } finally { |
| 11026 | Binder.restoreCallingIdentity(identity); |
| 11027 | } |
| 11028 | } |
| 11029 | |
| 11030 | /** |
| 11031 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11032 | * device does not have an active PUBLISH. |
| 11033 | */ |
| 11034 | // Used for SHELL command only right now. |
| 11035 | @Override |
| 11036 | public String getLastUcePidfXmlShell(int subId) { |
| 11037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11038 | final long identity = Binder.clearCallingIdentity(); |
| 11039 | try { |
| 11040 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11041 | } catch (ImsException e) { |
| 11042 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11043 | } finally { |
| 11044 | Binder.restoreCallingIdentity(identity); |
| 11045 | } |
| 11046 | } |
| 11047 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11048 | /** |
| 11049 | * Remove UCE requests cannot be sent to the network status. |
| 11050 | */ |
| 11051 | // Used for SHELL command only right now. |
| 11052 | @Override |
| 11053 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11054 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11055 | final long identity = Binder.clearCallingIdentity(); |
| 11056 | try { |
| 11057 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11058 | } catch (ImsException e) { |
| 11059 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
| 11064 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11065 | /** |
| 11066 | * Remove UCE requests cannot be sent to the network status. |
| 11067 | */ |
| 11068 | // Used for SHELL command only. |
| 11069 | @Override |
| 11070 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11071 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11072 | final long identity = Binder.clearCallingIdentity(); |
| 11073 | try { |
| 11074 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11075 | } catch (ImsException e) { |
| 11076 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11077 | } finally { |
| 11078 | Binder.restoreCallingIdentity(identity); |
| 11079 | } |
| 11080 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11081 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11082 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11083 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11084 | String callingPackage) { |
| 11085 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11086 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11087 | |
| 11088 | final int callingUid = Binder.getCallingUid(); |
| 11089 | // Verify that tha callingPackage belongs to the calling UID |
| 11090 | mApp.getSystemService(AppOpsManager.class) |
| 11091 | .checkPackage(callingUid, callingPackage); |
| 11092 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11093 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11094 | |
| 11095 | final long identity = Binder.clearCallingIdentity(); |
| 11096 | try { |
| 11097 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11098 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11099 | |
| 11100 | if (result instanceof IllegalStateException) { |
| 11101 | throw (IllegalStateException) result; |
| 11102 | } |
| 11103 | } finally { |
| 11104 | Binder.restoreCallingIdentity(identity); |
| 11105 | } |
| 11106 | } |
| 11107 | |
| 11108 | @Override |
| 11109 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11110 | String callingPackage) { |
| 11111 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11112 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11113 | |
| 11114 | final int callingUid = Binder.getCallingUid(); |
| 11115 | // Verify that tha callingPackage belongs to the calling UID |
| 11116 | mApp.getSystemService(AppOpsManager.class) |
| 11117 | .checkPackage(callingUid, callingPackage); |
| 11118 | |
| 11119 | final long identity = Binder.clearCallingIdentity(); |
| 11120 | try { |
| 11121 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11122 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11123 | |
| 11124 | if (result instanceof IllegalStateException) { |
| 11125 | throw (IllegalStateException) result; |
| 11126 | } |
| 11127 | } finally { |
| 11128 | Binder.restoreCallingIdentity(identity); |
| 11129 | } |
| 11130 | } |
| 11131 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11132 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11133 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11134 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11135 | // phone/system process do not have further restriction on request |
| 11136 | return; |
| 11137 | } |
| 11138 | |
| 11139 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11140 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11141 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11142 | context.enforceCallingOrSelfPermission( |
| 11143 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11144 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11145 | } |
| 11146 | |
| 11147 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11148 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11149 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11150 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11151 | || info.isEnabled()) { |
| 11152 | throw new IllegalArgumentException( |
| 11153 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11154 | } |
| 11155 | |
| 11156 | // Thresholds length for each RAN need in range. This has been validated in |
| 11157 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11158 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11159 | final int[] thresholds = info.getThresholds(); |
| 11160 | Objects.requireNonNull(thresholds); |
| 11161 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11162 | || thresholds.length |
| 11163 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11164 | throw new IllegalArgumentException( |
| 11165 | "thresholds length is out of range: " + thresholds.length); |
| 11166 | } |
| 11167 | } |
| 11168 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11169 | |
| 11170 | /** |
| 11171 | * Gets the current phone capability. |
| 11172 | * |
| 11173 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11174 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11175 | * It's used to evaluate possible phone config change, for example from single |
| 11176 | * SIM device to multi-SIM device. |
| 11177 | */ |
| 11178 | @Override |
| 11179 | public PhoneCapability getPhoneCapability() { |
| 11180 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11181 | final long identity = Binder.clearCallingIdentity(); |
| 11182 | try { |
| 11183 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11184 | } finally { |
| 11185 | Binder.restoreCallingIdentity(identity); |
| 11186 | } |
| 11187 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11188 | |
| 11189 | /** |
| 11190 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11191 | * required to be done shortly after the API is invoked. |
| 11192 | */ |
| 11193 | @Override |
| 11194 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11195 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11196 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11197 | enforceRebootPermission(); |
| 11198 | |
| 11199 | final long identity = Binder.clearCallingIdentity(); |
| 11200 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11201 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11202 | } finally { |
| 11203 | Binder.restoreCallingIdentity(identity); |
| 11204 | } |
| 11205 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11206 | |
| 11207 | /** |
| 11208 | * Request to get the current slicing configuration including URSP rules and |
| 11209 | * NSSAIs (configured, allowed and rejected). |
| 11210 | * |
| 11211 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11212 | */ |
| 11213 | @Override |
| 11214 | public void getSlicingConfig(ResultReceiver callback) { |
| 11215 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11216 | |
| 11217 | final long identity = Binder.clearCallingIdentity(); |
| 11218 | try { |
| 11219 | Phone phone = getDefaultPhone(); |
| 11220 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11221 | } finally { |
| 11222 | Binder.restoreCallingIdentity(identity); |
| 11223 | } |
| 11224 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11225 | |
| 11226 | /** |
| 11227 | * Register an IMS connection state callback |
| 11228 | */ |
| 11229 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11230 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11231 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11232 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11233 | // ImsMmTelManager |
| 11234 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11235 | TelephonyPermissions |
| 11236 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11237 | mApp, subId, "registerImsStateCallback"); |
| 11238 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11239 | // ImsRcsManager or SipDelegateManager |
| 11240 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11241 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11242 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11243 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11244 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11245 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11246 | } |
| 11247 | |
| 11248 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11249 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11250 | "IMS not available on device."); |
| 11251 | } |
| 11252 | |
| 11253 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11255 | } |
| 11256 | |
| 11257 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11258 | if (controller == null) { |
| 11259 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11260 | "IMS not available on device."); |
| 11261 | } |
| 11262 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11263 | if (callingPackage == null) { |
| 11264 | callingPackage = getCurrentPackageName(); |
| 11265 | } |
| 11266 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11267 | final long token = Binder.clearCallingIdentity(); |
| 11268 | try { |
| 11269 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11270 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11271 | } catch (ImsException e) { |
| 11272 | throw new ServiceSpecificException(e.getCode()); |
| 11273 | } finally { |
| 11274 | Binder.restoreCallingIdentity(token); |
| 11275 | } |
| 11276 | } |
| 11277 | |
| 11278 | /** |
| 11279 | * Unregister an IMS connection state callback |
| 11280 | */ |
| 11281 | @Override |
| 11282 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11283 | final long token = Binder.clearCallingIdentity(); |
| 11284 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11285 | if (controller == null) { |
| 11286 | return; |
| 11287 | } |
| 11288 | try { |
| 11289 | controller.unregisterImsStateCallback(cb); |
| 11290 | } finally { |
| 11291 | Binder.restoreCallingIdentity(token); |
| 11292 | } |
| 11293 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11294 | |
| 11295 | /** |
| 11296 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11297 | * |
| 11298 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11299 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11300 | * SecurityException. |
| 11301 | * If there is current registered network this value will be same as the registered cell |
| 11302 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11303 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11304 | * it will be cleared and null will be returned. |
| 11305 | * |
| 11306 | */ |
| 11307 | @Override |
| 11308 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11309 | String callingFeatureId) { |
| 11310 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11311 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11312 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11313 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11314 | .setCallingPackage(callingPackage) |
| 11315 | .setCallingFeatureId(callingFeatureId) |
| 11316 | .setCallingPid(Binder.getCallingPid()) |
| 11317 | .setCallingUid(Binder.getCallingUid()) |
| 11318 | .setMethod("getLastKnownCellIdentity") |
| 11319 | .setLogAsInfo(true) |
| 11320 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11321 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11322 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11323 | .build()); |
| 11324 | |
| 11325 | boolean hasFinePermission = |
| 11326 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11327 | if (!hasFinePermission |
| 11328 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11329 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11330 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11331 | } |
| 11332 | |
| 11333 | final long identity = Binder.clearCallingIdentity(); |
| 11334 | try { |
| 11335 | Phone phone = getPhone(subId); |
| 11336 | if (phone == null) return null; |
| 11337 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11338 | if (sst == null) return null; |
| 11339 | return sst.getLastKnownCellIdentity(); |
| 11340 | } finally { |
| 11341 | Binder.restoreCallingIdentity(identity); |
| 11342 | } |
| 11343 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11344 | |
| 11345 | @Override |
| 11346 | public boolean isUsingNewDataStack() { |
| 11347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11348 | return getDefaultPhone().isUsingNewDataStack(); |
| 11349 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11350 | |
| 11351 | /** |
| 11352 | * Sets the modem service class Name that Telephony will bind to. |
| 11353 | * |
| 11354 | * @param serviceName The class name of the modem service. |
| 11355 | * @return true if the operation is succeed, otherwise false. |
| 11356 | */ |
| 11357 | public boolean setModemService(String serviceName) { |
| 11358 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11359 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11361 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11362 | "setModemService"); |
| 11363 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11364 | } |
| 11365 | |
| 11366 | /** |
| 11367 | * Return the class name of the currently bounded modem service. |
| 11368 | * |
| 11369 | * @return the class name of the modem service. |
| 11370 | */ |
| 11371 | public String getModemService() { |
| 11372 | String result; |
| 11373 | Log.d(LOG_TAG, "getModemService"); |
| 11374 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11375 | TelephonyPermissions |
| 11376 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11377 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11378 | "getModemService"); |
| 11379 | result = mPhoneConfigurationManager.getModemService(); |
| 11380 | Log.d(LOG_TAG, "result = " + result); |
| 11381 | return result; |
| 11382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11383 | } |