Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 25 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 26 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 27 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 29 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 30 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 31 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 32 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 33 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 34 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 35 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 36 | import android.content.Context; |
| 37 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 38 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 39 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.net.Uri; |
| 43 | import android.os.AsyncResult; |
| 44 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 45 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Bundle; |
| 47 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Looper; |
| 50 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 52 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 53 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 54 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 55 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 56 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 57 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 58 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 59 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 60 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 61 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 62 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 63 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 64 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 65 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 66 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 67 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 68 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 69 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 70 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 71 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 72 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 73 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 74 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 75 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 76 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 77 | import android.telephony.CellIdentityCdma; |
| 78 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 79 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 80 | import android.telephony.CellInfoGsm; |
| 81 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 82 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 83 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 84 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 85 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 86 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 87 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 88 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 89 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 90 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 91 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 92 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 93 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 96 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 97 | import android.telephony.SignalStrengthUpdateRequest; |
| 98 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 99 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 100 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 102 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 105 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 106 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 107 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 108 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 110 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 111 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 112 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 113 | import android.telephony.gba.GbaAuthRequest; |
| 114 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 115 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 116 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 117 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 118 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 119 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 121 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 122 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 123 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 124 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 125 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 126 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 127 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 128 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 129 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 130 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 132 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 133 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 135 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 136 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 137 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 138 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 139 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.CallTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 168 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 174 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 181 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 193 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 195 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 196 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 197 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 198 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 199 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 200 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 201 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 202 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 203 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 204 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 205 | import com.android.services.telephony.TelecomAccountRegistry; |
| 206 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 207 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 208 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 209 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 210 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 211 | import java.io.IOException; |
| 212 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 213 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 214 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 215 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 216 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 217 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 218 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 219 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 220 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 221 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 223 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 225 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 226 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Implementation of the ITelephony interface. |
| 230 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 231 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 232 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 233 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 234 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 235 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 236 | |
| 237 | // Message codes used with mMainThreadHandler |
| 238 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 239 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 240 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 241 | private static final int CMD_OPEN_CHANNEL = 9; |
| 242 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 243 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 244 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 245 | private static final int CMD_NV_READ_ITEM = 13; |
| 246 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 247 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 248 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 249 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 250 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 251 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 252 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 253 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 254 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 255 | private static final int CMD_SEND_ENVELOPE = 25; |
| 256 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 257 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 258 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 259 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 260 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 261 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 262 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 263 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 264 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 265 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 266 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 268 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 269 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 270 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 271 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 272 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 274 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 275 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 276 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 277 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 278 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 279 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 280 | private static final int CMD_SWITCH_SLOTS = 50; |
| 281 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 283 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 284 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 285 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 286 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 287 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 288 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 289 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 290 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 291 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 292 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 293 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 294 | private static final int CMD_MODEM_REBOOT = 64; |
| 295 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 296 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 297 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 298 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 299 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 300 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 301 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 302 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 303 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 304 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 305 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 306 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 307 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 308 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 309 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 310 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 311 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 312 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 313 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 314 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 315 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 316 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 317 | private static final int CMD_GET_CALL_WAITING = 87; |
| 318 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 319 | private static final int CMD_SET_CALL_WAITING = 89; |
| 320 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 321 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 322 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 323 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 324 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 325 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 326 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 327 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 328 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 330 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 331 | private static final int CMD_SET_SIM_POWER = 101; |
| 332 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 333 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 334 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 335 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 336 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 337 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 338 | 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] | 339 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 340 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 341 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 342 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 344 | // Parameters of select command. |
| 345 | private static final int SELECT_COMMAND = 0xA4; |
| 346 | private static final int SELECT_P1 = 0x04; |
| 347 | private static final int SELECT_P2 = 0; |
| 348 | private static final int SELECT_P3 = 0x10; |
| 349 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | /** The singleton instance. */ |
| 351 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 352 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 353 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 354 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 355 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 356 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 357 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 358 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 359 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 360 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 361 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 362 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 363 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 364 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 366 | /** User Activity */ |
| 367 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 368 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 369 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 370 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 371 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 372 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 373 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 374 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 375 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 376 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 377 | // String to store multi SIM allowed |
| 378 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 379 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 380 | // The AID of ISD-R. |
| 381 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 382 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 383 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 384 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 385 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 386 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 387 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 388 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 389 | 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] | 390 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 391 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 392 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 393 | */ |
| 394 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 395 | "reset_network_erase_modem_config_enabled"; |
| 396 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 397 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 398 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 399 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 400 | * A request object to use for transmitting data to an ICC. |
| 401 | */ |
| 402 | private static final class IccAPDUArgument { |
| 403 | public int channel, cla, command, p1, p2, p3; |
| 404 | public String data; |
| 405 | |
| 406 | public IccAPDUArgument(int channel, int cla, int command, |
| 407 | int p1, int p2, int p3, String data) { |
| 408 | this.channel = channel; |
| 409 | this.cla = cla; |
| 410 | this.command = command; |
| 411 | this.p1 = p1; |
| 412 | this.p2 = p2; |
| 413 | this.p3 = p3; |
| 414 | this.data = data; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 419 | * A request object to use for transmitting data to an ICC. |
| 420 | */ |
| 421 | private static final class ManualNetworkSelectionArgument { |
| 422 | public OperatorInfo operatorInfo; |
| 423 | public boolean persistSelection; |
| 424 | |
| 425 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 426 | this.operatorInfo = operatorInfo; |
| 427 | this.persistSelection = persistSelection; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 433 | * request after sending. The main thread will notify the request when it is complete. |
| 434 | */ |
| 435 | private static final class MainThreadRequest { |
| 436 | /** The argument to use for the request */ |
| 437 | public Object argument; |
| 438 | /** The result of the request that is run on the main thread */ |
| 439 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 440 | // The subscriber id that this request applies to. Defaults to |
| 441 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 442 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 444 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 445 | public Phone phone; |
| 446 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 447 | public WorkSource workSource; |
| 448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | public MainThreadRequest(Object argument) { |
| 450 | this.argument = argument; |
| 451 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 452 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 453 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 454 | this.argument = argument; |
| 455 | if (phone != null) { |
| 456 | this.phone = phone; |
| 457 | } |
| 458 | this.workSource = workSource; |
| 459 | } |
| 460 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 461 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 462 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 463 | if (subId != null) { |
| 464 | this.subId = subId; |
| 465 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 466 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 467 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 470 | private static final class IncomingThirdPartyCallArgs { |
| 471 | public final ComponentName component; |
| 472 | public final String callId; |
| 473 | public final String callerDisplayName; |
| 474 | |
| 475 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 476 | String callerDisplayName) { |
| 477 | this.component = component; |
| 478 | this.callId = callId; |
| 479 | this.callerDisplayName = callerDisplayName; |
| 480 | } |
| 481 | } |
| 482 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | /** |
| 484 | * A handler that processes messages on the main thread in the phone process. Since many |
| 485 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 486 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 487 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 488 | * on, which will be notified when the operation completes and will contain the result of the |
| 489 | * request. |
| 490 | * |
| 491 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 492 | * note that request.result must be set to something non-null for the calling thread to |
| 493 | * unblock. |
| 494 | */ |
| 495 | private final class MainThreadHandler extends Handler { |
| 496 | @Override |
| 497 | public void handleMessage(Message msg) { |
| 498 | MainThreadRequest request; |
| 499 | Message onCompleted; |
| 500 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 501 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 503 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | |
| 505 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 506 | case CMD_HANDLE_USSD_REQUEST: { |
| 507 | request = (MainThreadRequest) msg.obj; |
| 508 | final Phone phone = getPhoneFromRequest(request); |
| 509 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 510 | String ussdRequest = ussdObject.first; |
| 511 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 512 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 513 | if (!isUssdApiAllowed(request.subId)) { |
| 514 | // Carrier does not support use of this API, return failure. |
| 515 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 516 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 517 | Bundle returnData = new Bundle(); |
| 518 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 519 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 520 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | request.result = true; |
| 522 | notifyRequester(request); |
| 523 | return; |
| 524 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 525 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | try { |
| 527 | request.result = phone != null |
| 528 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 529 | } catch (CallStateException cse) { |
| 530 | request.result = false; |
| 531 | } |
| 532 | // Wake up the requesting thread |
| 533 | notifyRequester(request); |
| 534 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 537 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 538 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 539 | final Phone phone = getPhoneFromRequest(request); |
| 540 | request.result = phone != null ? |
| 541 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 542 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 543 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 545 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 547 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 551 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 552 | if (uiccCard == null) { |
| 553 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 556 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 558 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 559 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 561 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 563 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 564 | break; |
| 565 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 567 | ar = (AsyncResult) msg.obj; |
| 568 | request = (MainThreadRequest) ar.userObj; |
| 569 | if (ar.exception == null && ar.result != null) { |
| 570 | request.result = ar.result; |
| 571 | } else { |
| 572 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 573 | if (ar.result == null) { |
| 574 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 575 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 576 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 577 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 578 | } else { |
| 579 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 580 | } |
| 581 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 583 | break; |
| 584 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 586 | request = (MainThreadRequest) msg.obj; |
| 587 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 588 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 589 | if (uiccCard == null) { |
| 590 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 591 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | } else { |
| 594 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 595 | request); |
| 596 | uiccCard.iccTransmitApduBasicChannel( |
| 597 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 598 | iccArgument.p3, iccArgument.data, onCompleted); |
| 599 | } |
| 600 | break; |
| 601 | |
| 602 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 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("iccTransmitApduBasicChannel: Empty response"); |
| 611 | } else if (ar.exception instanceof CommandException) { |
| 612 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 613 | ar.exception); |
| 614 | } else { |
| 615 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 616 | } |
| 617 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case CMD_EXCHANGE_SIM_IO: |
| 622 | request = (MainThreadRequest) msg.obj; |
| 623 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 624 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | if (uiccCard == null) { |
| 626 | loge("iccExchangeSimIO: 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_EXCHANGE_SIM_IO_DONE, |
| 631 | request); |
| 632 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 633 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 634 | iccArgument.data, onCompleted); |
| 635 | } |
| 636 | break; |
| 637 | |
| 638 | case EVENT_EXCHANGE_SIM_IO_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 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 646 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 647 | break; |
| 648 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 649 | case CMD_SEND_ENVELOPE: |
| 650 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 651 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | if (uiccCard == null) { |
| 653 | loge("sendEnvelopeWithStatus: No UICC"); |
| 654 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } else { |
| 657 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 658 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 659 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case EVENT_SEND_ENVELOPE_DONE: |
| 663 | ar = (AsyncResult) msg.obj; |
| 664 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 665 | if (ar.exception == null && ar.result != null) { |
| 666 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 667 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 668 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 669 | if (ar.result == null) { |
| 670 | loge("sendEnvelopeWithStatus: Empty response"); |
| 671 | } else if (ar.exception instanceof CommandException) { |
| 672 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 673 | ar.exception); |
| 674 | } else { |
| 675 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 676 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 677 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 679 | break; |
| 680 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | case CMD_OPEN_CHANNEL: |
| 682 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 683 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 684 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 685 | if (uiccCard == null) { |
| 686 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 687 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 688 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 689 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 690 | } else { |
| 691 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 692 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 693 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case EVENT_OPEN_CHANNEL_DONE: |
| 698 | ar = (AsyncResult) msg.obj; |
| 699 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 702 | int[] result = (int[]) ar.result; |
| 703 | int channelId = result[0]; |
| 704 | byte[] selectResponse = null; |
| 705 | if (result.length > 1) { |
| 706 | selectResponse = new byte[result.length - 1]; |
| 707 | for (int i = 1; i < result.length; ++i) { |
| 708 | selectResponse[i - 1] = (byte) result[i]; |
| 709 | } |
| 710 | } |
| 711 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 712 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | if (ar.result == null) { |
| 715 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 716 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | if (ar.exception != null) { |
| 718 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 719 | } |
| 720 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 721 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 722 | if (ar.exception instanceof CommandException) { |
| 723 | CommandException.Error error = |
| 724 | ((CommandException) (ar.exception)).getCommandError(); |
| 725 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 726 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 727 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 728 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 732 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 734 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case CMD_CLOSE_CHANNEL: |
| 739 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 740 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 741 | if (uiccCard == null) { |
| 742 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 743 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 745 | } else { |
| 746 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 747 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 748 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 753 | break; |
| 754 | |
| 755 | case CMD_NV_READ_ITEM: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 758 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 759 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | ar = (AsyncResult) msg.obj; |
| 764 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | if (ar.exception == null && ar.result != null) { |
| 766 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 767 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 768 | request.result = ""; |
| 769 | if (ar.result == null) { |
| 770 | loge("nvReadItem: Empty response"); |
| 771 | } else if (ar.exception instanceof CommandException) { |
| 772 | loge("nvReadItem: CommandException: " + |
| 773 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 774 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
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 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | case CMD_NV_WRITE_ITEM: |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 784 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 785 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 786 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 787 | break; |
| 788 | |
| 789 | case EVENT_NV_WRITE_ITEM_DONE: |
| 790 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 791 | break; |
| 792 | |
| 793 | case CMD_NV_WRITE_CDMA_PRL: |
| 794 | request = (MainThreadRequest) msg.obj; |
| 795 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 796 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 797 | break; |
| 798 | |
| 799 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 800 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 801 | break; |
| 802 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 803 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 804 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 805 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 806 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 807 | break; |
| 808 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 809 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 810 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 811 | break; |
| 812 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 813 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 814 | request = (MainThreadRequest) msg.obj; |
| 815 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 816 | request); |
| 817 | Phone phone = getPhoneFromRequest(request); |
| 818 | if (phone != null) { |
| 819 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 820 | } else { |
| 821 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 822 | request.result = false; |
| 823 | notifyRequester(request); |
| 824 | } |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 829 | ar = (AsyncResult) msg.obj; |
| 830 | request = (MainThreadRequest) ar.userObj; |
| 831 | if (ar.exception == null && ar.result != null) { |
| 832 | request.result = ar.result; |
| 833 | } else { |
| 834 | // request.result must be set to something non-null |
| 835 | // for the calling thread to unblock |
| 836 | if (request.result != null) { |
| 837 | request.result = ar.result; |
| 838 | } else { |
| 839 | request.result = false; |
| 840 | } |
| 841 | if (ar.result == null) { |
| 842 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 843 | } else if (ar.exception instanceof CommandException) { |
| 844 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 845 | + ar.exception); |
| 846 | } else { |
| 847 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 848 | } |
| 849 | } |
| 850 | notifyRequester(request); |
| 851 | break; |
| 852 | |
| 853 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 854 | request = (MainThreadRequest) msg.obj; |
| 855 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 856 | Phone phone = getPhoneFromRequest(request); |
| 857 | if (phone != null) { |
| 858 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 859 | request.workSource); |
| 860 | } else { |
| 861 | loge("enableNrDualConnectivity: No phone object"); |
| 862 | request.result = |
| 863 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 864 | notifyRequester(request); |
| 865 | } |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 870 | ar = (AsyncResult) msg.obj; |
| 871 | request = (MainThreadRequest) ar.userObj; |
| 872 | if (ar.exception == null) { |
| 873 | request.result = |
| 874 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 875 | } else { |
| 876 | request.result = |
| 877 | TelephonyManager |
| 878 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 879 | if (ar.exception instanceof CommandException) { |
| 880 | CommandException.Error error = |
| 881 | ((CommandException) (ar.exception)).getCommandError(); |
| 882 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 883 | request.result = |
| 884 | TelephonyManager |
| 885 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 886 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 887 | request.result = |
| 888 | TelephonyManager |
| 889 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 890 | } |
| 891 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 892 | + ar.exception); |
| 893 | } else { |
| 894 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 895 | } |
| 896 | } |
| 897 | notifyRequester(request); |
| 898 | break; |
| 899 | } |
| 900 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 901 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 903 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 904 | request); |
| 905 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 906 | break; |
| 907 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 908 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 909 | ar = (AsyncResult) msg.obj; |
| 910 | request = (MainThreadRequest) ar.userObj; |
| 911 | if (ar.exception == null && ar.result != null) { |
| 912 | request.result = ar.result; // Integer |
| 913 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 914 | // request.result must be set to something non-null |
| 915 | // for the calling thread to unblock |
| 916 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 918 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 919 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 920 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 921 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 922 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 923 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 924 | } |
| 925 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 926 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 929 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 930 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 931 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 932 | request); |
| 933 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 934 | (Pair<Integer, Long>) request.argument; |
| 935 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 936 | reasonWithNetworkTypes.first, |
| 937 | reasonWithNetworkTypes.second, |
| 938 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 939 | break; |
| 940 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 941 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 942 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 943 | break; |
| 944 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 945 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 946 | request = (MainThreadRequest)msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 948 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 949 | break; |
| 950 | |
| 951 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 952 | ar = (AsyncResult)msg.obj; |
| 953 | request = (MainThreadRequest)ar.userObj; |
| 954 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 955 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 956 | break; |
| 957 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 958 | case CMD_SET_VOICEMAIL_NUMBER: |
| 959 | request = (MainThreadRequest) msg.obj; |
| 960 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 961 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 962 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 963 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 964 | break; |
| 965 | |
| 966 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 967 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 968 | break; |
| 969 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 970 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 973 | request); |
| 974 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 975 | break; |
| 976 | |
| 977 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 978 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 979 | break; |
| 980 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 981 | case CMD_PERFORM_NETWORK_SCAN: |
| 982 | request = (MainThreadRequest) msg.obj; |
| 983 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 984 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 985 | break; |
| 986 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 988 | request = (MainThreadRequest) msg.obj; |
| 989 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 990 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 991 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 992 | request.argument; |
| 993 | int callForwardingReason = args.first; |
| 994 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 995 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | } |
| 997 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 998 | ar = (AsyncResult) msg.obj; |
| 999 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1000 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1001 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1002 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1005 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1006 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1007 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1008 | // any service for voice call. |
| 1009 | if ((callForwardInfo.serviceClass |
| 1010 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1011 | callForwardingInfo = new CallForwardingInfo(true, |
| 1012 | callForwardInfo.reason, |
| 1013 | callForwardInfo.number, |
| 1014 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | // Didn't find a call forward info for voice call. |
| 1019 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1021 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1022 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1023 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | } else { |
| 1025 | if (ar.result == null) { |
| 1026 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1027 | } |
| 1028 | if (ar.exception != null) { |
| 1029 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1030 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1031 | int errorCode = TelephonyManager |
| 1032 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1033 | if (ar.exception instanceof CommandException) { |
| 1034 | CommandException.Error error = |
| 1035 | ((CommandException) (ar.exception)).getCommandError(); |
| 1036 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1037 | errorCode = TelephonyManager |
| 1038 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1039 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1040 | errorCode = TelephonyManager |
| 1041 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1042 | } |
| 1043 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1046 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1048 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1052 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1053 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1055 | request.argument).first; |
| 1056 | request.phone.setCallForwardingOption( |
| 1057 | callForwardingInfoToSet.isEnabled() |
| 1058 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1059 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | callForwardingInfoToSet.getReason(), |
| 1061 | callForwardingInfoToSet.getNumber(), |
| 1062 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1063 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1065 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | Consumer<Integer> callback = |
| 1070 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1071 | request.argument).second; |
| 1072 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1073 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1074 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1075 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | if (ar.exception instanceof CommandException) { |
| 1077 | CommandException.Error error = |
| 1078 | ((CommandException) (ar.exception)).getCommandError(); |
| 1079 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1080 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1081 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1083 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1084 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | callback.accept(errorCode); |
| 1088 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1089 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1091 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1095 | request = (MainThreadRequest) msg.obj; |
| 1096 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1097 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1098 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1102 | ar = (AsyncResult) msg.obj; |
| 1103 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1105 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1106 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1107 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | // Service Class is a bit mask per 3gpp 27.007. |
| 1109 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1110 | if (callForwardResults.length > 1 |
| 1111 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1113 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1115 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1116 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1117 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1118 | } |
| 1119 | } else { |
| 1120 | if (ar.result == null) { |
| 1121 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1122 | } |
| 1123 | if (ar.exception != null) { |
| 1124 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1125 | } |
| 1126 | if (ar.exception instanceof CommandException) { |
| 1127 | CommandException.Error error = |
| 1128 | ((CommandException) (ar.exception)).getCommandError(); |
| 1129 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1130 | callForwardingStatus = |
| 1131 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1132 | } |
| 1133 | } |
| 1134 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1137 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1138 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1139 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1140 | request = (MainThreadRequest) msg.obj; |
| 1141 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1142 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1143 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1144 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1145 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1146 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1147 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1148 | ar = (AsyncResult) msg.obj; |
| 1149 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1150 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1151 | Consumer<Integer> callback = |
| 1152 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1153 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1154 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1155 | if (ar.exception instanceof CommandException) { |
| 1156 | CommandException.Error error = |
| 1157 | ((CommandException) (ar.exception)).getCommandError(); |
| 1158 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1159 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1160 | } else { |
| 1161 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1162 | } |
| 1163 | } else { |
| 1164 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1165 | } |
| 1166 | } else { |
| 1167 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1168 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1169 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1170 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1172 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1173 | ar = (AsyncResult) msg.obj; |
| 1174 | request = (MainThreadRequest) ar.userObj; |
| 1175 | CellNetworkScanResult cellScanResult; |
| 1176 | if (ar.exception == null && ar.result != null) { |
| 1177 | cellScanResult = new CellNetworkScanResult( |
| 1178 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1179 | (List<OperatorInfo>) ar.result); |
| 1180 | } else { |
| 1181 | if (ar.result == null) { |
| 1182 | loge("getCellNetworkScanResults: Empty response"); |
| 1183 | } |
| 1184 | if (ar.exception != null) { |
| 1185 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1186 | } |
| 1187 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1188 | if (ar.exception instanceof CommandException) { |
| 1189 | CommandException.Error error = |
| 1190 | ((CommandException) (ar.exception)).getCommandError(); |
| 1191 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1192 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1193 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1194 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1195 | } |
| 1196 | } |
| 1197 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1198 | } |
| 1199 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1200 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1201 | break; |
| 1202 | |
| 1203 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1204 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1205 | ManualNetworkSelectionArgument selArg = |
| 1206 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1207 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1208 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1209 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1210 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1211 | break; |
| 1212 | |
| 1213 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1214 | ar = (AsyncResult) msg.obj; |
| 1215 | request = (MainThreadRequest) ar.userObj; |
| 1216 | if (ar.exception == null) { |
| 1217 | request.result = true; |
| 1218 | } else { |
| 1219 | request.result = false; |
| 1220 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1221 | } |
| 1222 | notifyRequester(request); |
| 1223 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1224 | break; |
| 1225 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1226 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1227 | request = (MainThreadRequest) msg.obj; |
| 1228 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1229 | if (defaultPhone != null) { |
| 1230 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1231 | } else { |
| 1232 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1233 | Bundle bundle = new Bundle(); |
| 1234 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1235 | new ModemActivityInfo(0, 0, 0, |
| 1236 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1237 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1238 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1239 | break; |
| 1240 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1241 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1242 | ar = (AsyncResult) msg.obj; |
| 1243 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1244 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1245 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1246 | ModemActivityInfo ret = null; |
| 1247 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1248 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | // Update the last modem activity info and the result of the request. |
| 1250 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1251 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1252 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1253 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1254 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1255 | .getTransmitTimeMillis(); |
| 1256 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1257 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1258 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1259 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1260 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1261 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1262 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1263 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1264 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1265 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1266 | info.getReceiveTimeMillis() |
| 1267 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1268 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1269 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1270 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1271 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1272 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1273 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1274 | } else { |
| 1275 | if (ar.result == null) { |
| 1276 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1277 | error = TelephonyManager.ModemActivityInfoException |
| 1278 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1279 | } else if (ar.exception instanceof CommandException) { |
| 1280 | loge("queryModemActivityInfo: CommandException: " + |
| 1281 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1282 | error = TelephonyManager.ModemActivityInfoException |
| 1283 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1284 | } else { |
| 1285 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1286 | error = TelephonyManager.ModemActivityInfoException |
| 1287 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1288 | } |
| 1289 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1290 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1291 | if (ret != null) { |
| 1292 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1293 | } else { |
| 1294 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1295 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1296 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1297 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1298 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1299 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1300 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | case CMD_SET_ALLOWED_CARRIERS: |
| 1302 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1303 | CarrierRestrictionRules argument = |
| 1304 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1305 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1306 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | |
| 1309 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
| 1312 | if (ar.exception == null && ar.result != null) { |
| 1313 | request.result = ar.result; |
| 1314 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1315 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1316 | if (ar.exception instanceof CommandException) { |
| 1317 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1318 | CommandException.Error error = |
| 1319 | ((CommandException) (ar.exception)).getCommandError(); |
| 1320 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1321 | request.result = |
| 1322 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1323 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1324 | } else { |
| 1325 | loge("setAllowedCarriers: Unknown exception"); |
| 1326 | } |
| 1327 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1328 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1329 | break; |
| 1330 | |
| 1331 | case CMD_GET_ALLOWED_CARRIERS: |
| 1332 | request = (MainThreadRequest) msg.obj; |
| 1333 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1334 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1335 | break; |
| 1336 | |
| 1337 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1338 | ar = (AsyncResult) msg.obj; |
| 1339 | request = (MainThreadRequest) ar.userObj; |
| 1340 | if (ar.exception == null && ar.result != null) { |
| 1341 | request.result = ar.result; |
| 1342 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1343 | request.result = new IllegalStateException( |
| 1344 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1345 | if (ar.result == null) { |
| 1346 | loge("getAllowedCarriers: Empty response"); |
| 1347 | } else if (ar.exception instanceof CommandException) { |
| 1348 | loge("getAllowedCarriers: CommandException: " + |
| 1349 | ar.exception); |
| 1350 | } else { |
| 1351 | loge("getAllowedCarriers: Unknown exception"); |
| 1352 | } |
| 1353 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1354 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1355 | break; |
| 1356 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1357 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1358 | ar = (AsyncResult) msg.obj; |
| 1359 | request = (MainThreadRequest) ar.userObj; |
| 1360 | if (ar.exception == null && ar.result != null) { |
| 1361 | request.result = ar.result; |
| 1362 | } else { |
| 1363 | request.result = new IllegalArgumentException( |
| 1364 | "Failed to retrieve Forbidden Plmns"); |
| 1365 | if (ar.result == null) { |
| 1366 | loge("getForbiddenPlmns: Empty response"); |
| 1367 | } else { |
| 1368 | loge("getForbiddenPlmns: Unknown exception"); |
| 1369 | } |
| 1370 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1371 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1375 | request = (MainThreadRequest) msg.obj; |
| 1376 | uiccCard = getUiccCardFromRequest(request); |
| 1377 | if (uiccCard == null) { |
| 1378 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1379 | request.result = new IllegalArgumentException( |
| 1380 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1381 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1382 | break; |
| 1383 | } |
| 1384 | Integer appType = (Integer) request.argument; |
| 1385 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1386 | if (uiccApp == null) { |
| 1387 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1388 | + appType); |
| 1389 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1390 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1391 | break; |
| 1392 | } else { |
| 1393 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1394 | + " specified type -- " + appType); |
| 1395 | } |
| 1396 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1397 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1398 | onCompleted); |
| 1399 | break; |
| 1400 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1401 | case CMD_SWITCH_SLOTS: |
| 1402 | request = (MainThreadRequest) msg.obj; |
| 1403 | int[] physicalSlots = (int[]) request.argument; |
| 1404 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1405 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1406 | break; |
| 1407 | |
| 1408 | case EVENT_SWITCH_SLOTS_DONE: |
| 1409 | ar = (AsyncResult) msg.obj; |
| 1410 | request = (MainThreadRequest) ar.userObj; |
| 1411 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1412 | notifyRequester(request); |
| 1413 | break; |
| 1414 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1417 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1418 | break; |
| 1419 | |
| 1420 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1421 | ar = (AsyncResult) msg.obj; |
| 1422 | request = (MainThreadRequest) ar.userObj; |
| 1423 | if (ar.exception != null) { |
| 1424 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1425 | } else { |
| 1426 | int mode = ((int[]) ar.result)[0]; |
| 1427 | if (mode == 0) { |
| 1428 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1429 | } else { |
| 1430 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1431 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1432 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1433 | notifyRequester(request); |
| 1434 | break; |
| 1435 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1436 | request = (MainThreadRequest) msg.obj; |
| 1437 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1438 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1439 | break; |
| 1440 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1441 | ar = (AsyncResult) msg.obj; |
| 1442 | request = (MainThreadRequest) ar.userObj; |
| 1443 | if (ar.exception != null) { |
| 1444 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1445 | } else { |
| 1446 | request.result = ((int[]) ar.result)[0]; |
| 1447 | } |
| 1448 | notifyRequester(request); |
| 1449 | break; |
| 1450 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1451 | request = (MainThreadRequest) msg.obj; |
| 1452 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1453 | int mode = (int) request.argument; |
| 1454 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1455 | break; |
| 1456 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1457 | ar = (AsyncResult) msg.obj; |
| 1458 | request = (MainThreadRequest) ar.userObj; |
| 1459 | request.result = ar.exception == null; |
| 1460 | notifyRequester(request); |
| 1461 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1462 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1463 | request = (MainThreadRequest) msg.obj; |
| 1464 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1465 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1466 | break; |
| 1467 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1468 | ar = (AsyncResult) msg.obj; |
| 1469 | request = (MainThreadRequest) ar.userObj; |
| 1470 | if (ar.exception != null) { |
| 1471 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1472 | } else { |
| 1473 | request.result = ((int[]) ar.result)[0]; |
| 1474 | } |
| 1475 | notifyRequester(request); |
| 1476 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1477 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1478 | request = (MainThreadRequest) msg.obj; |
| 1479 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1480 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1481 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1482 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1483 | break; |
| 1484 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1485 | ar = (AsyncResult) msg.obj; |
| 1486 | request = (MainThreadRequest) ar.userObj; |
| 1487 | request.result = ar.exception == null; |
| 1488 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1489 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | case CMD_GET_ALL_CELL_INFO: |
| 1491 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1492 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1493 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1494 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1495 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1496 | ar = (AsyncResult) msg.obj; |
| 1497 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1498 | // If a timeout occurs, the response will be null |
| 1499 | request.result = (ar.exception == null && ar.result != null) |
| 1500 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1501 | synchronized (request) { |
| 1502 | request.notifyAll(); |
| 1503 | } |
| 1504 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1505 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1506 | request = (MainThreadRequest) msg.obj; |
| 1507 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1508 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1509 | break; |
| 1510 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1511 | ar = (AsyncResult) msg.obj; |
| 1512 | request = (MainThreadRequest) ar.userObj; |
| 1513 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1514 | try { |
| 1515 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1516 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1517 | cb.onError( |
| 1518 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1519 | ar.exception.getClass().getName(), |
| 1520 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1521 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1522 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1523 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1524 | } else { |
| 1525 | // use the result as returned |
| 1526 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1527 | } |
| 1528 | } catch (RemoteException re) { |
| 1529 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1530 | } |
| 1531 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1532 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1533 | request = (MainThreadRequest) msg.obj; |
| 1534 | WorkSource ws = (WorkSource) request.argument; |
| 1535 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1536 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1537 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1538 | } |
| 1539 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1540 | ar = (AsyncResult) msg.obj; |
| 1541 | request = (MainThreadRequest) ar.userObj; |
| 1542 | if (ar.exception == null) { |
| 1543 | request.result = ar.result; |
| 1544 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1545 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1546 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1547 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | synchronized (request) { |
| 1551 | request.notifyAll(); |
| 1552 | } |
| 1553 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1554 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1555 | case CMD_MODEM_REBOOT: |
| 1556 | request = (MainThreadRequest) msg.obj; |
| 1557 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1558 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1559 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1560 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1561 | handleNullReturnEvent(msg, "rebootModem"); |
| 1562 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1563 | case CMD_REQUEST_ENABLE_MODEM: |
| 1564 | request = (MainThreadRequest) msg.obj; |
| 1565 | boolean enable = (boolean) request.argument; |
| 1566 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1567 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1568 | PhoneConfigurationManager.getInstance() |
| 1569 | .enablePhone(request.phone, enable, onCompleted); |
| 1570 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1571 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1572 | ar = (AsyncResult) msg.obj; |
| 1573 | request = (MainThreadRequest) ar.userObj; |
| 1574 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1575 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1576 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1577 | if ((boolean) request.result) { |
| 1578 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1579 | updateModemStateMetrics(); |
| 1580 | } else { |
| 1581 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1582 | + ar.exception); |
| 1583 | } |
| 1584 | notifyRequester(request); |
| 1585 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1586 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1587 | case CMD_GET_MODEM_STATUS: |
| 1588 | request = (MainThreadRequest) msg.obj; |
| 1589 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1590 | PhoneConfigurationManager.getInstance() |
| 1591 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1592 | break; |
| 1593 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1594 | ar = (AsyncResult) msg.obj; |
| 1595 | request = (MainThreadRequest) ar.userObj; |
| 1596 | int id = request.phone.getPhoneId(); |
| 1597 | if (ar.exception == null && ar.result != null) { |
| 1598 | request.result = ar.result; |
| 1599 | //update the cache as modem status has changed |
| 1600 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1601 | (boolean) request.result); |
| 1602 | } else { |
| 1603 | // Return true if modem status cannot be retrieved. For most cases, |
| 1604 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1605 | // and disable modem are not supported. Modem is always on. |
| 1606 | // TODO: this should be fixed in R to support a third |
| 1607 | // status UNKNOWN b/131631629 |
| 1608 | request.result = true; |
| 1609 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1610 | + ar.exception); |
| 1611 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1612 | notifyRequester(request); |
| 1613 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1614 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1615 | request = (MainThreadRequest) msg.obj; |
| 1616 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1617 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1618 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1619 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1620 | break; |
| 1621 | } |
| 1622 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1623 | ar = (AsyncResult) msg.obj; |
| 1624 | request = (MainThreadRequest) ar.userObj; |
| 1625 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1626 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1627 | args.second.accept(ar.exception == null); |
| 1628 | notifyRequester(request); |
| 1629 | break; |
| 1630 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1631 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1632 | request = (MainThreadRequest) msg.obj; |
| 1633 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1634 | Phone phone = getPhoneFromRequest(request); |
| 1635 | if (phone != null) { |
| 1636 | phone.getSystemSelectionChannels(onCompleted); |
| 1637 | } else { |
| 1638 | loge("getSystemSelectionChannels: No phone object"); |
| 1639 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1640 | notifyRequester(request); |
| 1641 | } |
| 1642 | break; |
| 1643 | } |
| 1644 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1645 | ar = (AsyncResult) msg.obj; |
| 1646 | request = (MainThreadRequest) ar.userObj; |
| 1647 | if (ar.exception == null && ar.result != null) { |
| 1648 | request.result = ar.result; |
| 1649 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1650 | request.result = new IllegalStateException( |
| 1651 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1652 | if (ar.result == null) { |
| 1653 | loge("getSystemSelectionChannels: Empty response"); |
| 1654 | } else { |
| 1655 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1656 | } |
| 1657 | } |
| 1658 | notifyRequester(request); |
| 1659 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1660 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1661 | ar = (AsyncResult) msg.obj; |
| 1662 | request = (MainThreadRequest) ar.userObj; |
| 1663 | if (ar.exception == null && ar.result != null) { |
| 1664 | request.result = ar.result; |
| 1665 | } else { |
| 1666 | request.result = -1; |
| 1667 | loge("Failed to set Forbidden Plmns"); |
| 1668 | if (ar.result == null) { |
| 1669 | loge("setForbidenPlmns: Empty response"); |
| 1670 | } else if (ar.exception != null) { |
| 1671 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1672 | request.result = -1; |
| 1673 | } else { |
| 1674 | loge("setForbiddenPlmns: Unknown exception"); |
| 1675 | } |
| 1676 | } |
| 1677 | notifyRequester(request); |
| 1678 | break; |
| 1679 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1680 | request = (MainThreadRequest) msg.obj; |
| 1681 | uiccCard = getUiccCardFromRequest(request); |
| 1682 | if (uiccCard == null) { |
| 1683 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1684 | request.result = -1; |
| 1685 | notifyRequester(request); |
| 1686 | break; |
| 1687 | } |
| 1688 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1689 | (Pair<Integer, List<String>>) request.argument; |
| 1690 | appType = setFplmnsArgs.first; |
| 1691 | List<String> fplmns = setFplmnsArgs.second; |
| 1692 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1693 | if (uiccApp == null) { |
| 1694 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1695 | request.result = -1; |
| 1696 | loge("Failed to get UICC App"); |
| 1697 | notifyRequester(request); |
| 1698 | } else { |
| 1699 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1700 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1701 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1702 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1703 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1704 | case CMD_ERASE_MODEM_CONFIG: |
| 1705 | request = (MainThreadRequest) msg.obj; |
| 1706 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1707 | defaultPhone.eraseModemConfig(onCompleted); |
| 1708 | break; |
| 1709 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1710 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1711 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1712 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1713 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1714 | request = (MainThreadRequest) msg.obj; |
| 1715 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1716 | notifyRequester(request); |
| 1717 | break; |
| 1718 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1719 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1722 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1723 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1724 | changed.first, changed.second, onCompleted); |
| 1725 | break; |
| 1726 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1727 | ar = (AsyncResult) msg.obj; |
| 1728 | request = (MainThreadRequest) ar.userObj; |
| 1729 | if (ar.exception == null) { |
| 1730 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1731 | // If the operation is successful, update the PIN storage |
| 1732 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1733 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1734 | UiccController.getInstance().getPinStorage() |
| 1735 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1736 | } else { |
| 1737 | request.result = msg.arg1; |
| 1738 | } |
| 1739 | notifyRequester(request); |
| 1740 | break; |
| 1741 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1742 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1743 | request = (MainThreadRequest) msg.obj; |
| 1744 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1745 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1746 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1747 | enabled.first, enabled.second, onCompleted); |
| 1748 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1749 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1750 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1751 | ar = (AsyncResult) msg.obj; |
| 1752 | request = (MainThreadRequest) ar.userObj; |
| 1753 | if (ar.exception == null) { |
| 1754 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1755 | // If the operation is successful, update the PIN storage |
| 1756 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1757 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1758 | if (enabled.first) { |
| 1759 | UiccController.getInstance().getPinStorage() |
| 1760 | .storePin(enabled.second, phoneId); |
| 1761 | } else { |
| 1762 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1763 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1764 | } else { |
| 1765 | request.result = msg.arg1; |
| 1766 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1767 | |
| 1768 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1769 | notifyRequester(request); |
| 1770 | break; |
| 1771 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1772 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1773 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1774 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1775 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1776 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1777 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1778 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1779 | |
| 1780 | case CMD_SET_DATA_THROTTLING: { |
| 1781 | request = (MainThreadRequest) msg.obj; |
| 1782 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1783 | DataThrottlingRequest dataThrottlingRequest = |
| 1784 | (DataThrottlingRequest) request.argument; |
| 1785 | Phone phone = getPhoneFromRequest(request); |
| 1786 | if (phone != null) { |
| 1787 | phone.setDataThrottling(onCompleted, |
| 1788 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1789 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1790 | } else { |
| 1791 | loge("setDataThrottling: No phone object"); |
| 1792 | request.result = |
| 1793 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1794 | notifyRequester(request); |
| 1795 | } |
| 1796 | |
| 1797 | break; |
| 1798 | } |
| 1799 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1800 | ar = (AsyncResult) msg.obj; |
| 1801 | request = (MainThreadRequest) ar.userObj; |
| 1802 | |
| 1803 | if (ar.exception == null) { |
| 1804 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1805 | } else if (ar.exception instanceof CommandException) { |
| 1806 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1807 | CommandException.Error error = |
| 1808 | ((CommandException) (ar.exception)).getCommandError(); |
| 1809 | |
| 1810 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1811 | request.result = TelephonyManager |
| 1812 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1813 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1814 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1815 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1816 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1817 | } else { |
| 1818 | request.result = |
| 1819 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1820 | } |
| 1821 | } else { |
| 1822 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1823 | } |
| 1824 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1825 | notifyRequester(request); |
| 1826 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1827 | |
| 1828 | case CMD_SET_SIM_POWER: { |
| 1829 | request = (MainThreadRequest) msg.obj; |
| 1830 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1831 | request = (MainThreadRequest) msg.obj; |
| 1832 | int stateToSet = |
| 1833 | ((Pair<Integer, IIntegerConsumer>) |
| 1834 | request.argument).first; |
| 1835 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1836 | break; |
| 1837 | } |
| 1838 | case EVENT_SET_SIM_POWER_DONE: { |
| 1839 | ar = (AsyncResult) msg.obj; |
| 1840 | request = (MainThreadRequest) ar.userObj; |
| 1841 | IIntegerConsumer callback = |
| 1842 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1843 | if (ar.exception != null) { |
| 1844 | loge("setSimPower exception: " + ar.exception); |
| 1845 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1846 | .RESULT_ERROR_UNKNOWN; |
| 1847 | if (ar.exception instanceof CommandException) { |
| 1848 | CommandException.Error error = |
| 1849 | ((CommandException) (ar.exception)).getCommandError(); |
| 1850 | if (error == CommandException.Error.SIM_ERR) { |
| 1851 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1852 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1853 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1854 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1855 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1856 | } else { |
| 1857 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1858 | } |
| 1859 | } |
| 1860 | try { |
| 1861 | callback.accept(errorCode); |
| 1862 | } catch (RemoteException e) { |
| 1863 | // Ignore if the remote process is no longer available to call back. |
| 1864 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1865 | } |
| 1866 | } else { |
| 1867 | try { |
| 1868 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1869 | } catch (RemoteException e) { |
| 1870 | // Ignore if the remote process is no longer available to call back. |
| 1871 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1872 | } |
| 1873 | } |
| 1874 | break; |
| 1875 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1876 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1877 | request = (MainThreadRequest) msg.obj; |
| 1878 | |
| 1879 | final Phone phone = getPhoneFromRequest(request); |
| 1880 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1881 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1882 | notifyRequester(request); |
| 1883 | break; |
| 1884 | } |
| 1885 | |
| 1886 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1887 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1888 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1889 | request); |
| 1890 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1891 | request.subId, pair.first /*callingUid*/, |
| 1892 | pair.second /*request*/, onCompleted); |
| 1893 | break; |
| 1894 | } |
| 1895 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1896 | ar = (AsyncResult) msg.obj; |
| 1897 | request = (MainThreadRequest) ar.userObj; |
| 1898 | // request.result will be the exception of ar if present, true otherwise. |
| 1899 | // Be cautious not to leave result null which will wait() forever |
| 1900 | request.result = ar.exception != null ? ar.exception : true; |
| 1901 | notifyRequester(request); |
| 1902 | break; |
| 1903 | } |
| 1904 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1905 | request = (MainThreadRequest) msg.obj; |
| 1906 | |
| 1907 | Phone phone = getPhoneFromRequest(request); |
| 1908 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1909 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1910 | notifyRequester(request); |
| 1911 | break; |
| 1912 | } |
| 1913 | |
| 1914 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1915 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1916 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1917 | request); |
| 1918 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1919 | request.subId, pair.first /*callingUid*/, |
| 1920 | pair.second /*request*/, onCompleted); |
| 1921 | break; |
| 1922 | } |
| 1923 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1924 | ar = (AsyncResult) msg.obj; |
| 1925 | request = (MainThreadRequest) ar.userObj; |
| 1926 | request.result = ar.exception != null ? ar.exception : true; |
| 1927 | notifyRequester(request); |
| 1928 | break; |
| 1929 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1930 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1931 | case CMD_GET_SLICING_CONFIG: { |
| 1932 | request = (MainThreadRequest) msg.obj; |
| 1933 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 1934 | request.phone.getSlicingConfig(onCompleted); |
| 1935 | break; |
| 1936 | } |
| 1937 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 1938 | ar = (AsyncResult) msg.obj; |
| 1939 | request = (MainThreadRequest) ar.userObj; |
| 1940 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1941 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1942 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1943 | Bundle bundle = new Bundle(); |
| 1944 | int resultCode = 0; |
| 1945 | if (ar.exception != null) { |
| 1946 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 1947 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1948 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1949 | } else if (ar.result == null) { |
| 1950 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1951 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1952 | } else { |
| 1953 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1954 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 1955 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1959 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1960 | } |
| 1961 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 1962 | result.send(resultCode, bundle); |
| 1963 | notifyRequester(request); |
| 1964 | break; |
| 1965 | } |
| 1966 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1967 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1968 | request = (MainThreadRequest) msg.obj; |
| 1969 | request.result = |
| 1970 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1971 | notifyRequester(request); |
| 1972 | break; |
| 1973 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | default: |
| 1975 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1976 | break; |
| 1977 | } |
| 1978 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1979 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1980 | private void notifyRequester(MainThreadRequest request) { |
| 1981 | synchronized (request) { |
| 1982 | request.notifyAll(); |
| 1983 | } |
| 1984 | } |
| 1985 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1986 | private void handleNullReturnEvent(Message msg, String command) { |
| 1987 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1988 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1989 | if (ar.exception == null) { |
| 1990 | request.result = true; |
| 1991 | } else { |
| 1992 | request.result = false; |
| 1993 | if (ar.exception instanceof CommandException) { |
| 1994 | loge(command + ": CommandException: " + ar.exception); |
| 1995 | } else { |
| 1996 | loge(command + ": Unknown exception"); |
| 1997 | } |
| 1998 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1999 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2000 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | /** |
| 2004 | * Posts the specified command to be executed on the main thread, |
| 2005 | * waits for the request to complete, and returns the result. |
| 2006 | * @see #sendRequestAsync |
| 2007 | */ |
| 2008 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2009 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2010 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /** |
| 2014 | * Posts the specified command to be executed on the main thread, |
| 2015 | * waits for the request to complete, and returns the result. |
| 2016 | * @see #sendRequestAsync |
| 2017 | */ |
| 2018 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2019 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2020 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * Posts the specified command to be executed on the main thread, |
| 2025 | * waits for the request to complete, and returns the result. |
| 2026 | * @see #sendRequestAsync |
| 2027 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2028 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2029 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * Posts the specified command to be executed on the main thread, |
| 2034 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2035 | * if not timeout or null otherwise. |
| 2036 | * @see #sendRequestAsync |
| 2037 | */ |
| 2038 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2039 | long timeoutInMs) { |
| 2040 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | /** |
| 2044 | * Posts the specified command to be executed on the main thread, |
| 2045 | * waits for the request to complete, and returns the result. |
| 2046 | * @see #sendRequestAsync |
| 2047 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2048 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2049 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | /** |
| 2053 | * Posts the specified command to be executed on the main thread, |
| 2054 | * waits for the request to complete, and returns the result. |
| 2055 | * @see #sendRequestAsync |
| 2056 | */ |
| 2057 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2058 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2059 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2063 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2064 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2065 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2066 | * @see #sendRequestAsync |
| 2067 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2068 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2069 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2071 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2072 | } |
| 2073 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2074 | MainThreadRequest request = null; |
| 2075 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2076 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2077 | } else if (phone != null) { |
| 2078 | request = new MainThreadRequest(argument, phone, workSource); |
| 2079 | } else { |
| 2080 | request = new MainThreadRequest(argument, subId, workSource); |
| 2081 | } |
| 2082 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2084 | msg.sendToTarget(); |
| 2085 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2086 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2088 | if (timeoutInMs >= 0) { |
| 2089 | // Wait for at least timeoutInMs before returning null request result |
| 2090 | long now = SystemClock.elapsedRealtime(); |
| 2091 | long deadline = now + timeoutInMs; |
| 2092 | while (request == null && now < deadline) { |
| 2093 | try { |
| 2094 | request.wait(deadline - now); |
| 2095 | } catch (InterruptedException e) { |
| 2096 | // Do nothing, go back and check if request is completed or timeout |
| 2097 | } finally { |
| 2098 | now = SystemClock.elapsedRealtime(); |
| 2099 | } |
| 2100 | } |
| 2101 | } else { |
| 2102 | // Wait for the request to complete |
| 2103 | while (request.result == null) { |
| 2104 | try { |
| 2105 | request.wait(); |
| 2106 | } catch (InterruptedException e) { |
| 2107 | // Do nothing, go back and wait until the request is complete |
| 2108 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | } |
| 2110 | } |
| 2111 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2112 | if (request.result == null) { |
| 2113 | Log.wtf(LOG_TAG, |
| 2114 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2115 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 | return request.result; |
| 2117 | } |
| 2118 | |
| 2119 | /** |
| 2120 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2121 | * Posts the specified command to be executed on the main thread, and |
| 2122 | * returns immediately. |
| 2123 | * @see #sendRequest |
| 2124 | */ |
| 2125 | private void sendRequestAsync(int command) { |
| 2126 | mMainThreadHandler.sendEmptyMessage(command); |
| 2127 | } |
| 2128 | |
| 2129 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2130 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2131 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2132 | */ |
| 2133 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2134 | sendRequestAsync(command, argument, null, null); |
| 2135 | } |
| 2136 | |
| 2137 | /** |
| 2138 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2139 | * @see {@link #sendRequest(int,Object)} |
| 2140 | */ |
| 2141 | private void sendRequestAsync( |
| 2142 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2143 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2144 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2145 | msg.sendToTarget(); |
| 2146 | } |
| 2147 | |
| 2148 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2149 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2150 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2151 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2152 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2153 | synchronized (PhoneInterfaceManager.class) { |
| 2154 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2155 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | } else { |
| 2157 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2158 | } |
| 2159 | return sInstance; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2164 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame^] | 2167 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2168 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2169 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2170 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2171 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2172 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2173 | mTelephonySharedPreferences = |
| 2174 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2175 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2176 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2177 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2178 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2179 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2180 | publish(); |
| 2181 | } |
| 2182 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2183 | private Phone getDefaultPhone() { |
| 2184 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2185 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2186 | } |
| 2187 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | private void publish() { |
| 2189 | if (DBG) log("publish: " + this); |
| 2190 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2191 | TelephonyFrameworkInitializer |
| 2192 | .getTelephonyServiceManager() |
| 2193 | .getTelephonyServiceRegisterer() |
| 2194 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2197 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2198 | if (request.phone != null) { |
| 2199 | return request.phone; |
| 2200 | } else { |
| 2201 | return getPhoneFromSubId(request.subId); |
| 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | private Phone getPhoneFromSubId(int subId) { |
| 2206 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2207 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2208 | } |
| 2209 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2210 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2211 | Phone phone = getPhoneFromRequest(request); |
| 2212 | return phone == null ? null : |
| 2213 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2214 | } |
| 2215 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2216 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2217 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2218 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2221 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2222 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2223 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2224 | } |
| 2225 | |
| 2226 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2227 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2228 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2231 | private boolean isImsAvailableOnDevice() { |
| 2232 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2233 | if (pm == null) { |
| 2234 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2235 | // so do not throw error and allow. |
| 2236 | return true; |
| 2237 | } |
| 2238 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2239 | } |
| 2240 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2242 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2243 | } |
| 2244 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2245 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | if (DBG) log("dial: " + number); |
| 2247 | // No permission check needed here: This is just a wrapper around the |
| 2248 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2249 | // the UI before it does anything. |
| 2250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2251 | final long identity = Binder.clearCallingIdentity(); |
| 2252 | try { |
| 2253 | String url = createTelUrl(number); |
| 2254 | if (url == null) { |
| 2255 | return; |
| 2256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2259 | PhoneConstants.State state = mCM.getState(subId); |
| 2260 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2261 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2262 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2263 | mApp.startActivity(intent); |
| 2264 | } |
| 2265 | } finally { |
| 2266 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2271 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2274 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | if (DBG) log("call: " + number); |
| 2276 | |
| 2277 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2278 | // need to do a permission check since we're calling startActivity() |
| 2279 | // from the context of the phone app. |
| 2280 | enforceCallPermission(); |
| 2281 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2282 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | != AppOpsManager.MODE_ALLOWED) { |
| 2284 | return; |
| 2285 | } |
| 2286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2287 | final long identity = Binder.clearCallingIdentity(); |
| 2288 | try { |
| 2289 | String url = createTelUrl(number); |
| 2290 | if (url == null) { |
| 2291 | return; |
| 2292 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | boolean isValid = false; |
| 2295 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2296 | if (slist != null) { |
| 2297 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2298 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2299 | isValid = true; |
| 2300 | break; |
| 2301 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2302 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2304 | if (!isValid) { |
| 2305 | return; |
| 2306 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2307 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2308 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2309 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2310 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2311 | mApp.startActivity(intent); |
| 2312 | } finally { |
| 2313 | Binder.restoreCallingIdentity(identity); |
| 2314 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2317 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2318 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2319 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2320 | } |
| 2321 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2322 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2323 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2324 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2325 | } |
| 2326 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2327 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2329 | |
| 2330 | final long identity = Binder.clearCallingIdentity(); |
| 2331 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2332 | Phone phone = getPhone(subId); |
| 2333 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2334 | checkSimPin.start(); |
| 2335 | return checkSimPin.unlockSim(null, pin); |
| 2336 | } finally { |
| 2337 | Binder.restoreCallingIdentity(identity); |
| 2338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2341 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2343 | |
| 2344 | final long identity = Binder.clearCallingIdentity(); |
| 2345 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2346 | Phone phone = getPhone(subId); |
| 2347 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2348 | checkSimPuk.start(); |
| 2349 | return checkSimPuk.unlockSim(puk, pin); |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(identity); |
| 2352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2356 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | * a synchronous one. |
| 2358 | */ |
| 2359 | private static class UnlockSim extends Thread { |
| 2360 | |
| 2361 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2362 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | |
| 2364 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2365 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2366 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2367 | |
| 2368 | // For replies from SimCard interface |
| 2369 | private Handler mHandler; |
| 2370 | |
| 2371 | // For async handler to identify request type |
| 2372 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2373 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2374 | UnlockSim(int phoneId, IccCard simCard) { |
| 2375 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | mSimCard = simCard; |
| 2377 | } |
| 2378 | |
| 2379 | @Override |
| 2380 | public void run() { |
| 2381 | Looper.prepare(); |
| 2382 | synchronized (UnlockSim.this) { |
| 2383 | mHandler = new Handler() { |
| 2384 | @Override |
| 2385 | public void handleMessage(Message msg) { |
| 2386 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2387 | switch (msg.what) { |
| 2388 | case SUPPLY_PIN_COMPLETE: |
| 2389 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2390 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2391 | mRetryCount = msg.arg1; |
| 2392 | if (ar.exception != null) { |
| 2393 | if (ar.exception instanceof CommandException && |
| 2394 | ((CommandException)(ar.exception)).getCommandError() |
| 2395 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2396 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2397 | } //When UiccCardApp dispose,handle message and return exception |
| 2398 | else if (ar.exception instanceof CommandException && |
| 2399 | ((CommandException) (ar.exception)).getCommandError() |
| 2400 | == CommandException.Error.ABORTED) { |
| 2401 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2402 | } else { |
| 2403 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2404 | } |
| 2405 | } else { |
| 2406 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | mDone = true; |
| 2409 | UnlockSim.this.notifyAll(); |
| 2410 | } |
| 2411 | break; |
| 2412 | } |
| 2413 | } |
| 2414 | }; |
| 2415 | UnlockSim.this.notifyAll(); |
| 2416 | } |
| 2417 | Looper.loop(); |
| 2418 | } |
| 2419 | |
| 2420 | /* |
| 2421 | * Use PIN or PUK to unlock SIM card |
| 2422 | * |
| 2423 | * If PUK is null, unlock SIM card with PIN |
| 2424 | * |
| 2425 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2426 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2427 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | |
| 2429 | while (mHandler == null) { |
| 2430 | try { |
| 2431 | wait(); |
| 2432 | } catch (InterruptedException e) { |
| 2433 | Thread.currentThread().interrupt(); |
| 2434 | } |
| 2435 | } |
| 2436 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2437 | |
| 2438 | if (puk == null) { |
| 2439 | mSimCard.supplyPin(pin, callback); |
| 2440 | } else { |
| 2441 | mSimCard.supplyPuk(puk, pin, callback); |
| 2442 | } |
| 2443 | |
| 2444 | while (!mDone) { |
| 2445 | try { |
| 2446 | Log.d(LOG_TAG, "wait for done"); |
| 2447 | wait(); |
| 2448 | } catch (InterruptedException e) { |
| 2449 | // Restore the interrupted status |
| 2450 | Thread.currentThread().interrupt(); |
| 2451 | } |
| 2452 | } |
| 2453 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2454 | int[] resultArray = new int[2]; |
| 2455 | resultArray[0] = mResult; |
| 2456 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2457 | |
| 2458 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2459 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2460 | } |
| 2461 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2462 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | } |
| 2465 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2466 | /** |
| 2467 | * This method has been removed due to privacy and stability concerns. |
| 2468 | */ |
| 2469 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2471 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2472 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2475 | @Override |
| 2476 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2477 | mApp.getSystemService(AppOpsManager.class) |
| 2478 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2479 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2480 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2481 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2482 | // Callers targeting S have no business invoking this method. |
| 2483 | return; |
| 2484 | } |
| 2485 | |
| 2486 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2487 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2488 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2489 | .setCallingPackage(callingPackage) |
| 2490 | .setCallingFeatureId(null) |
| 2491 | .setCallingPid(Binder.getCallingPid()) |
| 2492 | .setCallingUid(Binder.getCallingUid()) |
| 2493 | .setMethod("updateServiceLocation") |
| 2494 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2495 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2496 | .build()); |
| 2497 | // Apps that lack location permission have no business calling this method; |
| 2498 | // however, because no permission was declared in the public API, denials must |
| 2499 | // all be "soft". |
| 2500 | switch (locationResult) { |
| 2501 | case DENIED_HARD: /* fall through */ |
| 2502 | case DENIED_SOFT: |
| 2503 | return; |
| 2504 | } |
| 2505 | |
| 2506 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | final long identity = Binder.clearCallingIdentity(); |
| 2508 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2509 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2511 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | } |
| 2513 | } finally { |
| 2514 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2515 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | } |
| 2517 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2518 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2519 | @Override |
| 2520 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2521 | return isRadioOnWithFeature(callingPackage, null); |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | @Override |
| 2526 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2527 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2528 | callingFeatureId); |
| 2529 | } |
| 2530 | |
| 2531 | @Deprecated |
| 2532 | @Override |
| 2533 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2534 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2538 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2539 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2540 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2541 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2542 | return false; |
| 2543 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | return isRadioOnForSubscriber(subId); |
| 2548 | } finally { |
| 2549 | Binder.restoreCallingIdentity(identity); |
| 2550 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | final Phone phone = getPhone(subId); |
| 2557 | if (phone != null) { |
| 2558 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2559 | } else { |
| 2560 | return false; |
| 2561 | } |
| 2562 | } finally { |
| 2563 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2564 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2568 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2569 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2570 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | final Phone phone = getPhone(subId); |
| 2577 | if (phone != null) { |
| 2578 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2579 | } |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2582 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2586 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2589 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2590 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2591 | |
| 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
| 2594 | final Phone phone = getPhone(subId); |
| 2595 | if (phone == null) { |
| 2596 | return false; |
| 2597 | } |
| 2598 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2599 | toggleRadioOnOffForSubscriber(subId); |
| 2600 | } |
| 2601 | return true; |
| 2602 | } finally { |
| 2603 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2604 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2606 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2607 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2608 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2609 | /* |
| 2610 | * If any of the Radios are available, it will need to be |
| 2611 | * shutdown. So return true if any Radio is available. |
| 2612 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2616 | Phone phone = PhoneFactory.getPhone(i); |
| 2617 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2618 | } |
| 2619 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2620 | return false; |
| 2621 | } finally { |
| 2622 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2623 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2626 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2627 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | enforceModifyPermission(); |
| 2629 | |
| 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2633 | logv("Shutting down Phone " + i); |
| 2634 | shutdownRadioUsingPhoneId(i); |
| 2635 | } |
| 2636 | } finally { |
| 2637 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | |
| 2641 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2642 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2643 | if (phone != null && phone.isRadioAvailable()) { |
| 2644 | phone.shutdownRadio(); |
| 2645 | } |
| 2646 | } |
| 2647 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2648 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2649 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | |
| 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2654 | if (defaultPhone != null) { |
| 2655 | defaultPhone.setRadioPower(turnOn); |
| 2656 | return true; |
| 2657 | } else { |
| 2658 | loge("There's no default phone."); |
| 2659 | return false; |
| 2660 | } |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2663 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2666 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2668 | |
| 2669 | final long identity = Binder.clearCallingIdentity(); |
| 2670 | try { |
| 2671 | final Phone phone = getPhone(subId); |
| 2672 | if (phone != null) { |
| 2673 | phone.setRadioPower(turnOn); |
| 2674 | return true; |
| 2675 | } else { |
| 2676 | return false; |
| 2677 | } |
| 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2680 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2683 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2684 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | public boolean enableDataConnectivity() { |
| 2686 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2691 | final Phone phone = getPhone(subId); |
| 2692 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2693 | phone.getDataEnabledSettings().setDataEnabled( |
| 2694 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2695 | return true; |
| 2696 | } else { |
| 2697 | return false; |
| 2698 | } |
| 2699 | } finally { |
| 2700 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2701 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | } |
| 2703 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2704 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2705 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2706 | public boolean disableDataConnectivity() { |
| 2707 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | |
| 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
| 2711 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2712 | final Phone phone = getPhone(subId); |
| 2713 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2714 | phone.getDataEnabledSettings().setDataEnabled( |
| 2715 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | return true; |
| 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 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2725 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2726 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2727 | final long identity = Binder.clearCallingIdentity(); |
| 2728 | try { |
| 2729 | final Phone phone = getPhone(subId); |
| 2730 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2731 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2732 | } else { |
| 2733 | return false; |
| 2734 | } |
| 2735 | } finally { |
| 2736 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2737 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2741 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2744 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2745 | enforceCallPermission(); |
| 2746 | |
| 2747 | final long identity = Binder.clearCallingIdentity(); |
| 2748 | try { |
| 2749 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2750 | return; |
| 2751 | } |
| 2752 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2753 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| 2756 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2757 | }; |
| 2758 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2759 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | |
| 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
| 2764 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2765 | return false; |
| 2766 | } |
| 2767 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2768 | } finally { |
| 2769 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2770 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2773 | /** |
| 2774 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2775 | * tag on getCallState Binder call. |
| 2776 | */ |
| 2777 | @Deprecated |
| 2778 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2780 | if (CompatChanges.isChangeEnabled( |
| 2781 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2782 | Binder.getCallingUid())) { |
| 2783 | // Do not allow this API to be called on API version 31+, it should only be |
| 2784 | // called on old apps using this Binder call directly. |
| 2785 | throw new SecurityException("This method can only be used for applications " |
| 2786 | + "targeting API version 30 or less."); |
| 2787 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2790 | Phone phone = getPhone(getDefaultSubscription()); |
| 2791 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2792 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(identity); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | @Override |
| 2799 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2800 | if (CompatChanges.isChangeEnabled( |
| 2801 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2802 | Binder.getCallingUid())) { |
| 2803 | // Check READ_PHONE_STATE for API version 31+ |
| 2804 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2805 | featureId, "getCallStateForSubscription")) { |
| 2806 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2807 | + "targeting API level 31+."); |
| 2808 | } |
| 2809 | } |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2813 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2814 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2815 | } finally { |
| 2816 | Binder.restoreCallingIdentity(identity); |
| 2817 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2820 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2821 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2822 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2823 | } |
| 2824 | |
| 2825 | @Override |
| 2826 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | final long identity = Binder.clearCallingIdentity(); |
| 2828 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2829 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | if (phone != null) { |
| 2831 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2832 | } else { |
| 2833 | return PhoneConstantConversions.convertDataState( |
| 2834 | PhoneConstants.DataState.DISCONNECTED); |
| 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 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2841 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2842 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2843 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2844 | } |
| 2845 | |
| 2846 | @Override |
| 2847 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2848 | final long identity = Binder.clearCallingIdentity(); |
| 2849 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2850 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | if (phone != null) { |
| 2852 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2853 | } else { |
| 2854 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2855 | } |
| 2856 | } finally { |
| 2857 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2862 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2864 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2865 | |
| 2866 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2867 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2868 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2869 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2870 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2871 | .setCallingPid(Binder.getCallingPid()) |
| 2872 | .setCallingUid(Binder.getCallingUid()) |
| 2873 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2874 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2875 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2876 | .build()); |
| 2877 | switch (locationResult) { |
| 2878 | case DENIED_HARD: |
| 2879 | throw new SecurityException("Not allowed to access cell location"); |
| 2880 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2881 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2882 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2885 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2886 | final long identity = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2889 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2890 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2891 | } finally { |
| 2892 | Binder.restoreCallingIdentity(identity); |
| 2893 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2896 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2897 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2898 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2899 | // registered cell info, so return a NULL country instead. |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2902 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2903 | // Get default phone in this case. |
| 2904 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2905 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2906 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2908 | if (phone == null) return ""; |
| 2909 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2910 | if (sst == null) return ""; |
| 2911 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2912 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2913 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
| 2916 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2919 | /** |
| 2920 | * This method was removed due to potential issues caused by performing partial |
| 2921 | * updates of service state, and lack of a credible use case. |
| 2922 | * |
| 2923 | * This has the ability to break the telephony implementation by disabling notification of |
| 2924 | * changes in device connectivity. DO NOT USE THIS! |
| 2925 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2926 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | public void enableLocationUpdates() { |
| 2928 | mApp.enforceCallingOrSelfPermission( |
| 2929 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2932 | /** |
| 2933 | * This method was removed due to potential issues caused by performing partial |
| 2934 | * updates of service state, and lack of a credible use case. |
| 2935 | * |
| 2936 | * This has the ability to break the telephony implementation by disabling notification of |
| 2937 | * changes in device connectivity. DO NOT USE THIS! |
| 2938 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2939 | @Override |
| 2940 | public void disableLocationUpdates() { |
| 2941 | mApp.enforceCallingOrSelfPermission( |
| 2942 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | @Override |
| 2946 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2947 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2948 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2949 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2950 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2951 | throw new SecurityException( |
| 2952 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2953 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2954 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2955 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2957 | return null; |
| 2958 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2959 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2960 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2961 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2962 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2963 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2965 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2966 | for (CellInfo ci : info) { |
| 2967 | if (ci instanceof CellInfoGsm) { |
| 2968 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2969 | } else if (ci instanceof CellInfoWcdma) { |
| 2970 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2971 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2972 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2973 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2976 | private List<CellInfo> getCachedCellInfo() { |
| 2977 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2978 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2979 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2980 | if (info != null) cellInfos.addAll(info); |
| 2981 | } |
| 2982 | return cellInfos; |
| 2983 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2984 | |
| 2985 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2986 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2987 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2988 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2989 | |
| 2990 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2991 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2992 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2993 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2994 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2995 | .setCallingPid(Binder.getCallingPid()) |
| 2996 | .setCallingUid(Binder.getCallingUid()) |
| 2997 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2998 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2999 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3000 | .build()); |
| 3001 | switch (locationResult) { |
| 3002 | case DENIED_HARD: |
| 3003 | throw new SecurityException("Not allowed to access cell info"); |
| 3004 | case DENIED_SOFT: |
| 3005 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3008 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3009 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3010 | return getCachedCellInfo(); |
| 3011 | } |
| 3012 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3013 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3014 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | final long identity = Binder.clearCallingIdentity(); |
| 3016 | try { |
| 3017 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3018 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3019 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3020 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3021 | if (info != null) cellInfos.addAll(info); |
| 3022 | } |
| 3023 | return cellInfos; |
| 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3026 | } |
| 3027 | } |
| 3028 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3029 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3030 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3031 | String callingFeatureId) { |
| 3032 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3033 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3037 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3038 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3039 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3040 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3043 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3044 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3046 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3047 | |
| 3048 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3049 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3050 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3051 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3052 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3053 | .setCallingPid(Binder.getCallingPid()) |
| 3054 | .setCallingUid(Binder.getCallingUid()) |
| 3055 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3056 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3057 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3058 | .build()); |
| 3059 | switch (locationResult) { |
| 3060 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3061 | if (TelephonyPermissions |
| 3062 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3063 | // Safetynet logging for b/154934934 |
| 3064 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3065 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3066 | throw new SecurityException("Not allowed to access cell info"); |
| 3067 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3068 | if (TelephonyPermissions |
| 3069 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3070 | // Safetynet logging for b/154934934 |
| 3071 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3072 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3073 | try { |
| 3074 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3075 | } catch (RemoteException re) { |
| 3076 | // Drop without consequences |
| 3077 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3078 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3079 | } |
| 3080 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3081 | |
| 3082 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3083 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3084 | |
| 3085 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3086 | } |
| 3087 | |
| 3088 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3089 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3090 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3091 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | |
| 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3095 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
| 3098 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3101 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3102 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3103 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3104 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3105 | return null; |
| 3106 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3107 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3108 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3109 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3110 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3111 | return null; |
| 3112 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | |
| 3114 | final long identity = Binder.clearCallingIdentity(); |
| 3115 | try { |
| 3116 | return phone.getImei(); |
| 3117 | } finally { |
| 3118 | Binder.restoreCallingIdentity(identity); |
| 3119 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3123 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3124 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3125 | String tac = null; |
| 3126 | if (phone != null) { |
| 3127 | String imei = phone.getImei(); |
| 3128 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3129 | } |
| 3130 | return tac; |
| 3131 | } |
| 3132 | |
| 3133 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3134 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3135 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3136 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3137 | return null; |
| 3138 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3139 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3140 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3141 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3142 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3143 | return null; |
| 3144 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | |
| 3146 | final long identity = Binder.clearCallingIdentity(); |
| 3147 | try { |
| 3148 | return phone.getMeid(); |
| 3149 | } finally { |
| 3150 | Binder.restoreCallingIdentity(identity); |
| 3151 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3155 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3156 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3157 | String manufacturerCode = null; |
| 3158 | if (phone != null) { |
| 3159 | String meid = phone.getMeid(); |
| 3160 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3161 | } |
| 3162 | return manufacturerCode; |
| 3163 | } |
| 3164 | |
| 3165 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3166 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3167 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3168 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3169 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3170 | return null; |
| 3171 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3172 | int subId = phone.getSubId(); |
| 3173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3174 | mApp, subId, callingPackage, callingFeatureId, |
| 3175 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3176 | return null; |
| 3177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3178 | |
| 3179 | final long identity = Binder.clearCallingIdentity(); |
| 3180 | try { |
| 3181 | return phone.getDeviceSvn(); |
| 3182 | } finally { |
| 3183 | Binder.restoreCallingIdentity(identity); |
| 3184 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3187 | @Override |
| 3188 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | final long identity = Binder.clearCallingIdentity(); |
| 3190 | try { |
| 3191 | final Phone phone = getPhone(subId); |
| 3192 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
| 3195 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | @Override |
| 3199 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
| 3202 | final Phone phone = getPhone(subId); |
| 3203 | return phone == null ? null : phone.getCarrierName(); |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
| 3206 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3207 | } |
| 3208 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3209 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3210 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3211 | final long identity = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | final Phone phone = getPhone(subId); |
| 3214 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3215 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
| 3218 | } |
| 3219 | } |
| 3220 | |
| 3221 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3222 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
| 3225 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3226 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3227 | } finally { |
| 3228 | Binder.restoreCallingIdentity(identity); |
| 3229 | } |
| 3230 | } |
| 3231 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3232 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3233 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3234 | if (!isSubscriptionMccMnc) { |
| 3235 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3236 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3237 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3238 | if (phone == null) { |
| 3239 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3240 | } |
| 3241 | final long identity = Binder.clearCallingIdentity(); |
| 3242 | try { |
| 3243 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3244 | } finally { |
| 3245 | Binder.restoreCallingIdentity(identity); |
| 3246 | } |
| 3247 | } |
| 3248 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3249 | // |
| 3250 | // Internal helper methods. |
| 3251 | // |
| 3252 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3253 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3254 | * Make sure the caller is the calling package itself |
| 3255 | * |
| 3256 | * @throws SecurityException if the caller is not the calling package |
| 3257 | */ |
| 3258 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3259 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3260 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3261 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3262 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3263 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3264 | } catch (PackageManager.NameNotFoundException e) { |
| 3265 | // packageUid is -1 |
| 3266 | } |
| 3267 | if (packageUid != callingUid) { |
| 3268 | throw new SecurityException(message + ": Package " + callingPackage |
| 3269 | + " does not belong to " + callingUid); |
| 3270 | } |
| 3271 | } |
| 3272 | |
| 3273 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3275 | * |
| 3276 | * @throws SecurityException if the caller does not have the required permission |
| 3277 | */ |
| 3278 | private void enforceModifyPermission() { |
| 3279 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3280 | } |
| 3281 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3282 | /** |
| 3283 | * Make sure the caller is system. |
| 3284 | * |
| 3285 | * @throws SecurityException if the caller is not system. |
| 3286 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3287 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3288 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3289 | throw new SecurityException("Caller must be system"); |
| 3290 | } |
| 3291 | } |
| 3292 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3293 | private void enforceActiveEmergencySessionPermission() { |
| 3294 | mApp.enforceCallingOrSelfPermission( |
| 3295 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3296 | } |
| 3297 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3298 | /** |
| 3299 | * Make sure the caller has the CALL_PHONE permission. |
| 3300 | * |
| 3301 | * @throws SecurityException if the caller does not have the required permission |
| 3302 | */ |
| 3303 | private void enforceCallPermission() { |
| 3304 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3305 | } |
| 3306 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3307 | private void enforceSettingsPermission() { |
| 3308 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3311 | private void enforceRebootPermission() { |
| 3312 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3313 | } |
| 3314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3315 | private String createTelUrl(String number) { |
| 3316 | if (TextUtils.isEmpty(number)) { |
| 3317 | return null; |
| 3318 | } |
| 3319 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3320 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3321 | } |
| 3322 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3323 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3324 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3325 | } |
| 3326 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3327 | private static void logv(String msg) { |
| 3328 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3329 | } |
| 3330 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3331 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3332 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3333 | } |
| 3334 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3335 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3336 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3337 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3340 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3341 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | final long identity = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3345 | if (phone == null) { |
| 3346 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3347 | } else { |
| 3348 | return phone.getPhoneType(); |
| 3349 | } |
| 3350 | } finally { |
| 3351 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3353 | } |
| 3354 | |
| 3355 | /** |
| 3356 | * Returns the CDMA ERI icon index to display |
| 3357 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3358 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3359 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3360 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3361 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3364 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3365 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3366 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3367 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3368 | mApp, subId, callingPackage, callingFeatureId, |
| 3369 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3370 | return -1; |
| 3371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3372 | |
| 3373 | final long identity = Binder.clearCallingIdentity(); |
| 3374 | try { |
| 3375 | final Phone phone = getPhone(subId); |
| 3376 | if (phone != null) { |
| 3377 | return phone.getCdmaEriIconIndex(); |
| 3378 | } else { |
| 3379 | return -1; |
| 3380 | } |
| 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3383 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | /** |
| 3387 | * Returns the CDMA ERI icon mode, |
| 3388 | * 0 - ON |
| 3389 | * 1 - FLASHING |
| 3390 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3391 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3392 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3393 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3394 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3397 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3398 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3399 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3400 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3401 | mApp, subId, callingPackage, callingFeatureId, |
| 3402 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3403 | return -1; |
| 3404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3405 | |
| 3406 | final long identity = Binder.clearCallingIdentity(); |
| 3407 | try { |
| 3408 | final Phone phone = getPhone(subId); |
| 3409 | if (phone != null) { |
| 3410 | return phone.getCdmaEriIconMode(); |
| 3411 | } else { |
| 3412 | return -1; |
| 3413 | } |
| 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | /** |
| 3420 | * Returns the CDMA ERI text, |
| 3421 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3422 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3423 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3424 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3425 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3429 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3430 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3432 | mApp, subId, callingPackage, callingFeatureId, |
| 3433 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3434 | return null; |
| 3435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3436 | |
| 3437 | final long identity = Binder.clearCallingIdentity(); |
| 3438 | try { |
| 3439 | final Phone phone = getPhone(subId); |
| 3440 | if (phone != null) { |
| 3441 | return phone.getCdmaEriText(); |
| 3442 | } else { |
| 3443 | return null; |
| 3444 | } |
| 3445 | } finally { |
| 3446 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
| 3450 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3451 | * Returns the CDMA MDN. |
| 3452 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3453 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3454 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3456 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3457 | |
| 3458 | final long identity = Binder.clearCallingIdentity(); |
| 3459 | try { |
| 3460 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3461 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3462 | return phone.getLine1Number(); |
| 3463 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3464 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | return null; |
| 3466 | } |
| 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3469 | } |
| 3470 | } |
| 3471 | |
| 3472 | /** |
| 3473 | * Returns the CDMA MIN. |
| 3474 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3475 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3476 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3477 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3478 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | |
| 3480 | final long identity = Binder.clearCallingIdentity(); |
| 3481 | try { |
| 3482 | final Phone phone = getPhone(subId); |
| 3483 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3484 | return phone.getCdmaMin(); |
| 3485 | } else { |
| 3486 | return null; |
| 3487 | } |
| 3488 | } finally { |
| 3489 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3490 | } |
| 3491 | } |
| 3492 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3493 | @Override |
| 3494 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3495 | INumberVerificationCallback callback, String callingPackage) { |
| 3496 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3497 | != PERMISSION_GRANTED) { |
| 3498 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3499 | } |
| 3500 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3501 | |
| 3502 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3503 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3504 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3505 | + "calling package: " + callingPackage |
| 3506 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | if (range == null) { |
| 3510 | throw new NullPointerException("Range must be non-null"); |
| 3511 | } |
| 3512 | |
| 3513 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3514 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3515 | |
| 3516 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3517 | } |
| 3518 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3519 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | * Returns true if CDMA provisioning needs to run. |
| 3521 | */ |
| 3522 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | final long identity = Binder.clearCallingIdentity(); |
| 3524 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3525 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3526 | } finally { |
| 3527 | Binder.restoreCallingIdentity(identity); |
| 3528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3532 | * Sets the voice mail number of a given subId. |
| 3533 | */ |
| 3534 | @Override |
| 3535 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3536 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3537 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3538 | |
| 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3542 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3543 | return success; |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3549 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3550 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3551 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3552 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3553 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3554 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3555 | throw new SecurityException("caller must be system dialer"); |
| 3556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3557 | |
| 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3561 | if (phoneAccountHandle == null) { |
| 3562 | return null; |
| 3563 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3564 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | } finally { |
| 3566 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3567 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3571 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3572 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3573 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3574 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3575 | mApp, subId, callingPackage, callingFeatureId, |
| 3576 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3577 | return null; |
| 3578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3582 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
| 3585 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3589 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3590 | VisualVoicemailSmsFilterSettings settings) { |
| 3591 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | |
| 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3596 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3597 | } finally { |
| 3598 | Binder.restoreCallingIdentity(identity); |
| 3599 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3603 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3604 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3605 | |
| 3606 | final long identity = Binder.clearCallingIdentity(); |
| 3607 | try { |
| 3608 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3609 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
| 3612 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3616 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3617 | String callingPackage, int subId) { |
| 3618 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3619 | |
| 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3623 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
| 3626 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3630 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3631 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3632 | |
| 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
| 3635 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3636 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
| 3639 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3643 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3644 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3645 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3646 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3647 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3648 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3649 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3650 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3651 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3652 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3653 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3654 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3655 | * Sets the voice activation state of a given subId. |
| 3656 | */ |
| 3657 | @Override |
| 3658 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3660 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | |
| 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | final Phone phone = getPhone(subId); |
| 3665 | if (phone != null) { |
| 3666 | phone.setVoiceActivationState(activationState); |
| 3667 | } else { |
| 3668 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3669 | } |
| 3670 | } finally { |
| 3671 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * Sets the data activation state of a given subId. |
| 3677 | */ |
| 3678 | @Override |
| 3679 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3681 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | |
| 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | final Phone phone = getPhone(subId); |
| 3686 | if (phone != null) { |
| 3687 | phone.setDataActivationState(activationState); |
| 3688 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3689 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | } |
| 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | /** |
| 3697 | * Returns the voice activation state of a given subId. |
| 3698 | */ |
| 3699 | @Override |
| 3700 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3701 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3702 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3703 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3704 | final long identity = Binder.clearCallingIdentity(); |
| 3705 | try { |
| 3706 | if (phone != null) { |
| 3707 | return phone.getVoiceActivationState(); |
| 3708 | } else { |
| 3709 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3710 | } |
| 3711 | } finally { |
| 3712 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | /** |
| 3717 | * Returns the data activation state of a given subId. |
| 3718 | */ |
| 3719 | @Override |
| 3720 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3721 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3723 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3724 | final long identity = Binder.clearCallingIdentity(); |
| 3725 | try { |
| 3726 | if (phone != null) { |
| 3727 | return phone.getDataActivationState(); |
| 3728 | } else { |
| 3729 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3730 | } |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | |
| 3736 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3737 | * Returns the unread count of voicemails for a subId |
| 3738 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3740 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3741 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3742 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3743 | mApp, subId, callingPackage, callingFeatureId, |
| 3744 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3745 | return 0; |
| 3746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3747 | final long identity = Binder.clearCallingIdentity(); |
| 3748 | try { |
| 3749 | final Phone phone = getPhone(subId); |
| 3750 | if (phone != null) { |
| 3751 | return phone.getVoiceMessageCount(); |
| 3752 | } else { |
| 3753 | return 0; |
| 3754 | } |
| 3755 | } finally { |
| 3756 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3757 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3761 | * returns true, if the device is in a state where both voice and data |
| 3762 | * are supported simultaneously. This can change based on location or network condition. |
| 3763 | */ |
| 3764 | @Override |
| 3765 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | final long identity = Binder.clearCallingIdentity(); |
| 3767 | try { |
| 3768 | final Phone phone = getPhone(subId); |
| 3769 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3770 | } finally { |
| 3771 | Binder.restoreCallingIdentity(identity); |
| 3772 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3776 | * Send the dialer code if called from the current default dialer or the caller has |
| 3777 | * carrier privilege. |
| 3778 | * @param inputCode The dialer code to send |
| 3779 | */ |
| 3780 | @Override |
| 3781 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3782 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3783 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3784 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3785 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3786 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3787 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3788 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | |
| 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3793 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3794 | } finally { |
| 3795 | Binder.restoreCallingIdentity(identity); |
| 3796 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3797 | } |
| 3798 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3799 | @Override |
| 3800 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3801 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3802 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3803 | mApp, subId, "getNetworkSelectionMode"); |
| 3804 | final long identity = Binder.clearCallingIdentity(); |
| 3805 | try { |
| 3806 | if (!isActiveSubscription(subId)) { |
| 3807 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3808 | } |
| 3809 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3812 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3815 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3816 | public boolean isInEmergencySmsMode() { |
| 3817 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3818 | final long identity = Binder.clearCallingIdentity(); |
| 3819 | try { |
| 3820 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3821 | if (phone.isInEmergencySmsMode()) { |
| 3822 | return true; |
| 3823 | } |
| 3824 | } |
| 3825 | } finally { |
| 3826 | Binder.restoreCallingIdentity(identity); |
| 3827 | } |
| 3828 | return false; |
| 3829 | } |
| 3830 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3831 | /** |
| 3832 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3833 | * @param subId The subscription to use to check the configuration. |
| 3834 | * @param c The callback that will be used to send the result. |
| 3835 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3836 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3837 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3838 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3839 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3840 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3841 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3842 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3843 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3844 | "IMS not available on device."); |
| 3845 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3846 | final long token = Binder.clearCallingIdentity(); |
| 3847 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3848 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3849 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3850 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3851 | } catch (ImsException e) { |
| 3852 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | } finally { |
| 3854 | Binder.restoreCallingIdentity(token); |
| 3855 | } |
| 3856 | } |
| 3857 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3858 | /** |
| 3859 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3860 | * @param subId The subscription to use to check the configuration. |
| 3861 | * @param c The callback that will be used to send the result. |
| 3862 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3863 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3864 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3865 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3866 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3867 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3868 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3869 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3870 | final long token = Binder.clearCallingIdentity(); |
| 3871 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3872 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3873 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3874 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3875 | } catch (ImsException e) { |
| 3876 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3877 | + "is inactive, ignoring unregister."); |
| 3878 | // If the subscription is no longer active, just return, since the callback |
| 3879 | // will already have been removed internally. |
| 3880 | } finally { |
| 3881 | Binder.restoreCallingIdentity(token); |
| 3882 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3883 | } |
| 3884 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3885 | /** |
| 3886 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3887 | */ |
| 3888 | @Override |
| 3889 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3890 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3891 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3892 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3893 | "IMS not available on device."); |
| 3894 | } |
| 3895 | final long token = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | Phone phone = getPhone(subId); |
| 3898 | if (phone == null) { |
| 3899 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3900 | + subId + "'"); |
| 3901 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3902 | } |
| 3903 | phone.getImsRegistrationState(regState -> { |
| 3904 | try { |
| 3905 | consumer.accept((regState == null) |
| 3906 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3907 | } catch (RemoteException e) { |
| 3908 | // Ignore if the remote process is no longer available to call back. |
| 3909 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3910 | } |
| 3911 | }); |
| 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(token); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | /** |
| 3918 | * Get the transport type for the IMS service registration state. |
| 3919 | */ |
| 3920 | @Override |
| 3921 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3922 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3923 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3924 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3925 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3926 | "IMS not available on device."); |
| 3927 | } |
| 3928 | final long token = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | Phone phone = getPhone(subId); |
| 3931 | if (phone == null) { |
| 3932 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3933 | + subId + "'"); |
| 3934 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3935 | } |
| 3936 | phone.getImsRegistrationTech(regTech -> { |
| 3937 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3938 | int regTechConverted = (regTech == null) |
| 3939 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3940 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3941 | regTechConverted); |
| 3942 | try { |
| 3943 | consumer.accept(regTechConverted); |
| 3944 | } catch (RemoteException e) { |
| 3945 | // Ignore if the remote process is no longer available to call back. |
| 3946 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3947 | } |
| 3948 | }); |
| 3949 | } finally { |
| 3950 | Binder.restoreCallingIdentity(token); |
| 3951 | } |
| 3952 | } |
| 3953 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3954 | /** |
| 3955 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3956 | * @param subId The subscription to use to check the configuration. |
| 3957 | * @param c The callback that will be used to send the result. |
| 3958 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3960 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3961 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3962 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3963 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3964 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3965 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3966 | "IMS not available on device."); |
| 3967 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3969 | final long token = Binder.clearCallingIdentity(); |
| 3970 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3973 | } catch (ImsException e) { |
| 3974 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(token); |
| 3977 | } |
| 3978 | } |
| 3979 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3980 | /** |
| 3981 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3982 | * @param subId The subscription to use to check the configuration. |
| 3983 | * @param c The callback that will be used to send the result. |
| 3984 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3986 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3987 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3988 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3989 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3990 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3991 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3992 | |
| 3993 | final long token = Binder.clearCallingIdentity(); |
| 3994 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3995 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3996 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3997 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3998 | } catch (ImsException e) { |
| 3999 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4000 | + "is inactive, ignoring unregister."); |
| 4001 | // If the subscription is no longer active, just return, since the callback |
| 4002 | // will already have been removed internally. |
| 4003 | } finally { |
| 4004 | Binder.restoreCallingIdentity(token); |
| 4005 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
| 4008 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4009 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4010 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4012 | final long token = Binder.clearCallingIdentity(); |
| 4013 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4014 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4015 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4016 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4017 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4018 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4019 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4020 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4021 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4022 | } finally { |
| 4023 | Binder.restoreCallingIdentity(token); |
| 4024 | } |
| 4025 | } |
| 4026 | |
| 4027 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4028 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4029 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4030 | final long token = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | Phone phone = getPhone(subId); |
| 4033 | if (phone == null) return false; |
| 4034 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4035 | } catch (com.android.ims.ImsException e) { |
| 4036 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4037 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4038 | } finally { |
| 4039 | Binder.restoreCallingIdentity(token); |
| 4040 | } |
| 4041 | } |
| 4042 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4043 | /** |
| 4044 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4045 | * subscription. |
| 4046 | * @param subId The subscription to use to check the configuration. |
| 4047 | * @param callback The callback that will be used to send the result. |
| 4048 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4049 | * @param transportType The transport type of the MmTelFeature capability. |
| 4050 | */ |
| 4051 | @Override |
| 4052 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4053 | int transportType) { |
| 4054 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4055 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4056 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4057 | "IMS not available on device."); |
| 4058 | } |
| 4059 | final long token = Binder.clearCallingIdentity(); |
| 4060 | try { |
| 4061 | int slotId = getSlotIndex(subId); |
| 4062 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4063 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4064 | + subId + "'"); |
| 4065 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4066 | } |
| 4067 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4068 | transportType, aBoolean -> { |
| 4069 | try { |
| 4070 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4071 | } catch (RemoteException e) { |
| 4072 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4073 | + "running. Ignore"); |
| 4074 | } |
| 4075 | }); |
| 4076 | } finally { |
| 4077 | Binder.restoreCallingIdentity(token); |
| 4078 | } |
| 4079 | } |
| 4080 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4081 | /** |
| 4082 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4083 | * @param subId The subscription to use to check the configuration. |
| 4084 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4085 | @Override |
| 4086 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4087 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4088 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4089 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4091 | final long token = Binder.clearCallingIdentity(); |
| 4092 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4093 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4095 | } catch (ImsException e) { |
| 4096 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(token); |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4103 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4105 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4109 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4110 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4111 | } catch (ImsException e) { |
| 4112 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4118 | /** |
| 4119 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4120 | * @param subId The subscription to use to check the configuration. |
| 4121 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4123 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4124 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4125 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4129 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4130 | } catch (ImsException e) { |
| 4131 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4138 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4140 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4145 | } catch (ImsException e) { |
| 4146 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4147 | } finally { |
| 4148 | Binder.restoreCallingIdentity(identity); |
| 4149 | } |
| 4150 | } |
| 4151 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4152 | /** |
| 4153 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4154 | * @param subId The subscription to use to check the configuration. |
| 4155 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4156 | @Override |
| 4157 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4158 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4159 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | final long identity = Binder.clearCallingIdentity(); |
| 4161 | try { |
| 4162 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4163 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4164 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4165 | } catch (ImsException e) { |
| 4166 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4167 | } finally { |
| 4168 | Binder.restoreCallingIdentity(identity); |
| 4169 | } |
| 4170 | } |
| 4171 | |
| 4172 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4173 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4175 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4176 | final long identity = Binder.clearCallingIdentity(); |
| 4177 | try { |
| 4178 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4179 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4180 | } catch (ImsException e) { |
| 4181 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
| 4184 | } |
| 4185 | } |
| 4186 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4187 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4188 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4189 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4190 | * @param subId The subscription to use to check the configuration. |
| 4191 | */ |
| 4192 | @Override |
| 4193 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4194 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4195 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4196 | final long identity = Binder.clearCallingIdentity(); |
| 4197 | try { |
| 4198 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4199 | return ImsManager.getInstance(mApp, |
| 4200 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4201 | } catch (ImsException e) { |
| 4202 | throw new ServiceSpecificException(e.getCode()); |
| 4203 | } finally { |
| 4204 | Binder.restoreCallingIdentity(identity); |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | /** |
| 4209 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4210 | * Requires MODIFY_PHONE_STATE permission. |
| 4211 | * @param subId The subscription to use to check the configuration. |
| 4212 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4213 | * false otherwise |
| 4214 | */ |
| 4215 | @Override |
| 4216 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4217 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4218 | "setCrossSimCallingEnabled"); |
| 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
| 4221 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4222 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4223 | .setCrossSimCallingEnabled(isEnabled); |
| 4224 | } catch (ImsException e) { |
| 4225 | throw new ServiceSpecificException(e.getCode()); |
| 4226 | } finally { |
| 4227 | Binder.restoreCallingIdentity(identity); |
| 4228 | } |
| 4229 | } |
| 4230 | |
| 4231 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4232 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4233 | * @param subId The subscription to use to check the configuration. |
| 4234 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4235 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4236 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4237 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4238 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4239 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4240 | final long identity = Binder.clearCallingIdentity(); |
| 4241 | try { |
| 4242 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4243 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4244 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4245 | } catch (ImsException e) { |
| 4246 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4247 | } finally { |
| 4248 | Binder.restoreCallingIdentity(identity); |
| 4249 | } |
| 4250 | } |
| 4251 | |
| 4252 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4253 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4254 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4255 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4256 | final long identity = Binder.clearCallingIdentity(); |
| 4257 | try { |
| 4258 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4259 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4260 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4261 | } catch (ImsException e) { |
| 4262 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | @Override |
| 4269 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4271 | "setVoWiFiNonPersistent"); |
| 4272 | final long identity = Binder.clearCallingIdentity(); |
| 4273 | try { |
| 4274 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4275 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4276 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4277 | } catch (ImsException e) { |
| 4278 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
| 4282 | } |
| 4283 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4284 | /** |
| 4285 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4286 | * @param subId The subscription to use to check the configuration. |
| 4287 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4288 | @Override |
| 4289 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4290 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4291 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4292 | final long identity = Binder.clearCallingIdentity(); |
| 4293 | try { |
| 4294 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4295 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4296 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4297 | } catch (ImsException e) { |
| 4298 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | @Override |
| 4305 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4307 | "setVoWiFiModeSetting"); |
| 4308 | final long identity = Binder.clearCallingIdentity(); |
| 4309 | try { |
| 4310 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4311 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4312 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4313 | } catch (ImsException e) { |
| 4314 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4315 | } finally { |
| 4316 | Binder.restoreCallingIdentity(identity); |
| 4317 | } |
| 4318 | } |
| 4319 | |
| 4320 | @Override |
| 4321 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4322 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4323 | final long identity = Binder.clearCallingIdentity(); |
| 4324 | try { |
| 4325 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4326 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4327 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4328 | } catch (ImsException e) { |
| 4329 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4330 | } finally { |
| 4331 | Binder.restoreCallingIdentity(identity); |
| 4332 | } |
| 4333 | } |
| 4334 | |
| 4335 | @Override |
| 4336 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4338 | "setVoWiFiRoamingModeSetting"); |
| 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
| 4341 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4342 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4343 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4344 | } catch (ImsException e) { |
| 4345 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | @Override |
| 4352 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4354 | "setRttCapabilityEnabled"); |
| 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
| 4357 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4358 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4359 | } catch (ImsException e) { |
| 4360 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4361 | } finally { |
| 4362 | Binder.restoreCallingIdentity(identity); |
| 4363 | } |
| 4364 | } |
| 4365 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4366 | /** |
| 4367 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4368 | * @param subId The subscription to use to check the configuration. |
| 4369 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4370 | @Override |
| 4371 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4373 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
| 4376 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4377 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4378 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4379 | } catch (ImsException e) { |
| 4380 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
| 4383 | } |
| 4384 | } |
| 4385 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4386 | @Override |
| 4387 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4388 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4391 | if (!isImsAvailableOnDevice()) { |
| 4392 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4393 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4394 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4395 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4396 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4397 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4398 | } catch (ImsException e) { |
| 4399 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4400 | } finally { |
| 4401 | Binder.restoreCallingIdentity(identity); |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | @Override |
| 4406 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4407 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4408 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4409 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4410 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4411 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4412 | try { |
| 4413 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4414 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4415 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4416 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4417 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4418 | + "is inactive, ignoring unregister."); |
| 4419 | // If the subscription is no longer active, just return, since the callback will already |
| 4420 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4421 | } finally { |
| 4422 | Binder.restoreCallingIdentity(identity); |
| 4423 | } |
| 4424 | } |
| 4425 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4426 | |
| 4427 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4429 | message); |
| 4430 | } |
| 4431 | |
| 4432 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4433 | boolean isMmtelCapability) { |
| 4434 | Phone phone = getPhone(subId); |
| 4435 | if (phone == null) { |
| 4436 | loge("phone instance null for subid " + subId); |
| 4437 | return false; |
| 4438 | } |
| 4439 | if (isMmtelCapability) { |
| 4440 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4441 | return false; |
| 4442 | } |
| 4443 | } else { |
| 4444 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4445 | return false; |
| 4446 | } |
| 4447 | } |
| 4448 | return true; |
| 4449 | } |
| 4450 | |
| 4451 | @Override |
| 4452 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4453 | boolean isProvisioned) { |
| 4454 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4455 | |
| 4456 | final long identity = Binder.clearCallingIdentity(); |
| 4457 | try { |
| 4458 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4459 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4460 | return; |
| 4461 | } |
| 4462 | |
| 4463 | // this capability requires provisioning, route to the correct API. |
| 4464 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4465 | switch (capability) { |
| 4466 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4467 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4468 | ims.setEabProvisioned(isProvisioned); |
| 4469 | break; |
| 4470 | default: { |
| 4471 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4472 | + "rcs capability '" + capability + "', which does not require " |
| 4473 | + "provisioning."); |
| 4474 | } |
| 4475 | } |
| 4476 | } finally { |
| 4477 | Binder.restoreCallingIdentity(identity); |
| 4478 | } |
| 4479 | |
| 4480 | } |
| 4481 | |
| 4482 | |
| 4483 | @Override |
| 4484 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4485 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4486 | final long identity = Binder.clearCallingIdentity(); |
| 4487 | try { |
| 4488 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4489 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4490 | return true; |
| 4491 | } |
| 4492 | |
| 4493 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4494 | switch (capability) { |
| 4495 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4496 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4497 | return ims.isEabProvisionedOnDevice(); |
| 4498 | |
| 4499 | default: { |
| 4500 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4501 | + "capability '" + capability + "', which does not require " |
| 4502 | + "provisioning."); |
| 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
| 4509 | } |
| 4510 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4511 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4512 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4513 | boolean isProvisioned) { |
| 4514 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4515 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4516 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4517 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4518 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4519 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4520 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4521 | final long identity = Binder.clearCallingIdentity(); |
| 4522 | try { |
| 4523 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4524 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4525 | return; |
| 4526 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4527 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4528 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4529 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4530 | + "not support provisioning - " + tech); |
| 4531 | return; |
| 4532 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4533 | |
| 4534 | // this capability requires provisioning, route to the correct API. |
| 4535 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4536 | switch (capability) { |
| 4537 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4538 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4539 | ims.setVolteProvisioned(isProvisioned); |
| 4540 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4541 | ims.setWfcProvisioned(isProvisioned); |
| 4542 | } |
| 4543 | break; |
| 4544 | } |
| 4545 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4546 | // There is currently no difference in VT provisioning type. |
| 4547 | ims.setVtProvisioned(isProvisioned); |
| 4548 | break; |
| 4549 | } |
| 4550 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4551 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4552 | // change the capability of the feature instead if needed. |
| 4553 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4554 | == isProvisioned) { |
| 4555 | // No change in provisioning. |
| 4556 | return; |
| 4557 | } |
| 4558 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4559 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4560 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4561 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4562 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4563 | + ", Exception" + e.getMessage()); |
| 4564 | } |
| 4565 | break; |
| 4566 | } |
| 4567 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4568 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4569 | + "MmTel capability '" + capability + "', which does not require " |
| 4570 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4571 | } |
| 4572 | } |
| 4573 | |
| 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(identity); |
| 4576 | } |
| 4577 | } |
| 4578 | |
| 4579 | @Override |
| 4580 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4581 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4582 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4583 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4584 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4585 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4586 | } |
| 4587 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4588 | final long identity = Binder.clearCallingIdentity(); |
| 4589 | try { |
| 4590 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4591 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4592 | return true; |
| 4593 | } |
| 4594 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4595 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4596 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4597 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4598 | + "not support provisioning - " + tech); |
| 4599 | return true; |
| 4600 | } |
| 4601 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4602 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4603 | switch (capability) { |
| 4604 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4605 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4606 | return ims.isVolteProvisionedOnDevice(); |
| 4607 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4608 | return ims.isWfcProvisionedOnDevice(); |
| 4609 | } |
| 4610 | // This should never happen, since we are checking tech above to make sure it |
| 4611 | // is either LTE or IWLAN. |
| 4612 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4613 | + "capability."); |
| 4614 | } |
| 4615 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4616 | // There is currently no difference in VT provisioning type. |
| 4617 | return ims.isVtProvisionedOnDevice(); |
| 4618 | } |
| 4619 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4620 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4621 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4622 | } |
| 4623 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4624 | throw new IllegalArgumentException( |
| 4625 | "Tried to get provisioning for MmTel capability '" + capability |
| 4626 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | } finally { |
| 4631 | Binder.restoreCallingIdentity(identity); |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | @Override |
| 4636 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4637 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4638 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4639 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4640 | } |
| 4641 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4642 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4643 | return (provisionedBits & capability) > 0; |
| 4644 | } |
| 4645 | |
| 4646 | @Override |
| 4647 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4648 | boolean isProvisioned) { |
| 4649 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4650 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4651 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4652 | } |
| 4653 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4654 | "setProvisioningStatusForCapability"); |
| 4655 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4656 | // If the current provisioning status for capability already matches isProvisioned, |
| 4657 | // do nothing. |
| 4658 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4659 | return; |
| 4660 | } |
| 4661 | if (isProvisioned) { |
| 4662 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4663 | } else { |
| 4664 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | /** |
| 4669 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4670 | * technology. The bitfield should mirror the bitfield defined by |
| 4671 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4672 | */ |
| 4673 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4674 | String key = getMmTelProvisioningKey(subId, tech); |
| 4675 | // Default is no capabilities are provisioned. |
| 4676 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4677 | } |
| 4678 | |
| 4679 | /** |
| 4680 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4681 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4682 | * technology specified. |
| 4683 | * |
| 4684 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4685 | */ |
| 4686 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4687 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4688 | String key = getMmTelProvisioningKey(subId, tech); |
| 4689 | editor.putInt(key, newField); |
| 4690 | editor.commit(); |
| 4691 | } |
| 4692 | |
| 4693 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4694 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4695 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4696 | } |
| 4697 | |
| 4698 | /** |
| 4699 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4700 | * carrier associated with the subscription id. |
| 4701 | */ |
| 4702 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4703 | int capability) { |
| 4704 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4705 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4706 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4707 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4708 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4709 | false); |
| 4710 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4711 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4712 | |
| 4713 | // First check to make sure that the capability requires provisioning. |
| 4714 | switch (capability) { |
| 4715 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4716 | // intentional fallthrough |
| 4717 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4718 | if (requireVoiceVtProvisioning) { |
| 4719 | // Voice and Video requires provisioning |
| 4720 | return true; |
| 4721 | } |
| 4722 | break; |
| 4723 | } |
| 4724 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4725 | if (requireUtProvisioning) { |
| 4726 | // UT requires provisioning |
| 4727 | return true; |
| 4728 | } |
| 4729 | break; |
| 4730 | } |
| 4731 | } |
| 4732 | return false; |
| 4733 | } |
| 4734 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4735 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4736 | int capability) { |
| 4737 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4738 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4739 | |
| 4740 | boolean requireRcsProvisioning = c.getBoolean( |
| 4741 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4742 | |
| 4743 | // First check to make sure that the capability requires provisioning. |
| 4744 | switch (capability) { |
| 4745 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4746 | // intentional fallthrough |
| 4747 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4748 | if (requireRcsProvisioning) { |
| 4749 | // OPTION or PRESENCE requires provisioning |
| 4750 | return true; |
| 4751 | } |
| 4752 | break; |
| 4753 | } |
| 4754 | } |
| 4755 | return false; |
| 4756 | } |
| 4757 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4758 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4759 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4760 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4761 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4762 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4763 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4764 | final long identity = Binder.clearCallingIdentity(); |
| 4765 | try { |
| 4766 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4767 | int slotId = getSlotIndex(subId); |
| 4768 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4769 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4770 | + subId + "' for key:" + key); |
| 4771 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4772 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4773 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4774 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4775 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4776 | + subId + "' for key:" + key); |
| 4777 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
| 4780 | } |
| 4781 | } |
| 4782 | |
| 4783 | @Override |
| 4784 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4786 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4787 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4788 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4789 | final long identity = Binder.clearCallingIdentity(); |
| 4790 | try { |
| 4791 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4792 | int slotId = getSlotIndex(subId); |
| 4793 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4794 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4795 | + subId + "' for key:" + key); |
| 4796 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4797 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4798 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4799 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4800 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4801 | + subId + "' for key:" + key); |
| 4802 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4803 | } finally { |
| 4804 | Binder.restoreCallingIdentity(identity); |
| 4805 | } |
| 4806 | } |
| 4807 | |
| 4808 | @Override |
| 4809 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4810 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4811 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4812 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4814 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4815 | final long identity = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4818 | int slotId = getSlotIndex(subId); |
| 4819 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4820 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4821 | + subId + "' for key:" + key); |
| 4822 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4823 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4824 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4825 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4826 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4827 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4828 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
| 4834 | @Override |
| 4835 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4836 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4837 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4838 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4840 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4841 | final long identity = Binder.clearCallingIdentity(); |
| 4842 | try { |
| 4843 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4844 | int slotId = getSlotIndex(subId); |
| 4845 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4846 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4847 | + subId + "' for key:" + key); |
| 4848 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4849 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4850 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4851 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4852 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4853 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4854 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4855 | } finally { |
| 4856 | Binder.restoreCallingIdentity(identity); |
| 4857 | } |
| 4858 | } |
| 4859 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4860 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4861 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4862 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4863 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4864 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4865 | } |
| 4866 | return slotId; |
| 4867 | } |
| 4868 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4869 | private int getSlotIndex(int subId) { |
| 4870 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4871 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4872 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4873 | } |
| 4874 | return slotId; |
| 4875 | } |
| 4876 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4877 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4878 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4879 | */ |
| 4880 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4881 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4882 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4883 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4884 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4885 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4886 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4887 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4888 | mApp, subId, callingPackage, callingFeatureId, |
| 4889 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4890 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4891 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4892 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | final Phone phone = getPhone(subId); |
| 4896 | if (phone != null) { |
| 4897 | return phone.getServiceState().getDataNetworkType(); |
| 4898 | } else { |
| 4899 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4900 | } |
| 4901 | } finally { |
| 4902 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4903 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | /** |
| 4907 | * Returns the data network type |
| 4908 | */ |
| 4909 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4910 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4911 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4912 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | /** |
| 4916 | * Returns the data network type for a subId |
| 4917 | */ |
| 4918 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4919 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4920 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4921 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4922 | mApp, subId, callingPackage, callingFeatureId, |
| 4923 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4924 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4925 | } |
| 4926 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
| 4929 | final Phone phone = getPhone(subId); |
| 4930 | if (phone != null) { |
| 4931 | return phone.getServiceState().getDataNetworkType(); |
| 4932 | } else { |
| 4933 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4934 | } |
| 4935 | } finally { |
| 4936 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4937 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4941 | * Returns the Voice network type for a subId |
| 4942 | */ |
| 4943 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4944 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4945 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4946 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4947 | mApp, subId, callingPackage, callingFeatureId, |
| 4948 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4949 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4950 | } |
| 4951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4952 | final long identity = Binder.clearCallingIdentity(); |
| 4953 | try { |
| 4954 | final Phone phone = getPhone(subId); |
| 4955 | if (phone != null) { |
| 4956 | return phone.getServiceState().getVoiceNetworkType(); |
| 4957 | } else { |
| 4958 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4959 | } |
| 4960 | } finally { |
| 4961 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4962 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | /** |
| 4966 | * @return true if a ICC card is present |
| 4967 | */ |
| 4968 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4969 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4970 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4971 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4972 | } |
| 4973 | |
| 4974 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4975 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4976 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4977 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4978 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4979 | final long identity = Binder.clearCallingIdentity(); |
| 4980 | try { |
| 4981 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4982 | if (phone != null) { |
| 4983 | return phone.getIccCard().hasIccCard(); |
| 4984 | } else { |
| 4985 | return false; |
| 4986 | } |
| 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | /** |
| 4993 | * Return if the current radio is LTE on CDMA. This |
| 4994 | * is a tri-state return value as for a period of time |
| 4995 | * the mode may be unknown. |
| 4996 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4997 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4998 | * @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] | 4999 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5000 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5001 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5002 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5003 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5004 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5005 | } |
| 5006 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5007 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5008 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5009 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5010 | try { |
| 5011 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5012 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5013 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5014 | } |
| 5015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | final Phone phone = getPhone(subId); |
| 5019 | if (phone == null) { |
| 5020 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5021 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5022 | return TelephonyProperties.lte_on_cdma_device() |
| 5023 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5024 | } |
| 5025 | } finally { |
| 5026 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5027 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5028 | } |
| 5029 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5030 | /** |
| 5031 | * {@hide} |
| 5032 | * Returns Default subId, 0 in the case of single standby. |
| 5033 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5034 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5035 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5038 | private int getSlotForDefaultSubscription() { |
| 5039 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5040 | } |
| 5041 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5042 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5043 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5044 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5045 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5046 | private boolean isActiveSubscription(int subId) { |
| 5047 | return mSubscriptionController.isActiveSubId(subId); |
| 5048 | } |
| 5049 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5050 | /** |
| 5051 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5052 | */ |
| 5053 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5056 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5058 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
| 5061 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | /** |
| 5065 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5066 | */ |
| 5067 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | final long identity = Binder.clearCallingIdentity(); |
| 5069 | try { |
| 5070 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5071 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5073 | } finally { |
| 5074 | Binder.restoreCallingIdentity(identity); |
| 5075 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5076 | } |
| 5077 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5078 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5079 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5080 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5081 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5082 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5083 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5084 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5085 | if (phoneId == -1) { |
| 5086 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5087 | + " does not correspond to an active phone"); |
| 5088 | } |
| 5089 | return PhoneFactory.getPhone(phoneId); |
| 5090 | } |
| 5091 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5092 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5093 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5094 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5095 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5096 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5098 | if (DBG) { |
| 5099 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5100 | } |
| 5101 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5102 | p2); |
| 5103 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5104 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5105 | |
| 5106 | @Override |
| 5107 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5108 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5109 | enforceModifyPermission(); |
| 5110 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5111 | if (DBG) { |
| 5112 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5113 | } |
| 5114 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5115 | callingPackage, aid, p2); |
| 5116 | } |
| 5117 | |
| 5118 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5119 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
| 5122 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5123 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5124 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5125 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5126 | if (bestComponent == null |
| 5127 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5128 | loge("The calling package is not allowed to access ISD-R."); |
| 5129 | throw new SecurityException( |
| 5130 | "The calling package is not allowed to access ISD-R."); |
| 5131 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5132 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5133 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5135 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5136 | null /* workSource */); |
| 5137 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | return response; |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
| 5141 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5145 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5147 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5148 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5149 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5150 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5151 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5152 | @Override |
| 5153 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5154 | enforceModifyPermission(); |
| 5155 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5156 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5157 | channel); |
| 5158 | } |
| 5159 | |
| 5160 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | final long identity = Binder.clearCallingIdentity(); |
| 5162 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | if (channel < 0) { |
| 5164 | return false; |
| 5165 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5166 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5167 | null /* workSource */); |
| 5168 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | return success; |
| 5170 | } finally { |
| 5171 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5172 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5176 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5177 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5178 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5179 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5180 | if (DBG) { |
| 5181 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5182 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5183 | + p3 + " data=" + data); |
| 5184 | } |
| 5185 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5186 | command, p1, p2, p3, data); |
| 5187 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5188 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5189 | @Override |
| 5190 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5191 | int command, int p1, int p2, int p3, String data) { |
| 5192 | enforceModifyPermission(); |
| 5193 | if (DBG) { |
| 5194 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5195 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5196 | + p3 + " data=" + data); |
| 5197 | } |
| 5198 | return iccTransmitApduLogicalChannelWithPermission( |
| 5199 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5200 | data); |
| 5201 | } |
| 5202 | |
| 5203 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5204 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5207 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | return ""; |
| 5209 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5212 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5213 | null /* workSource */); |
| 5214 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | // Append the returned status code to the end of the response payload. |
| 5217 | String s = Integer.toHexString( |
| 5218 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5219 | if (response.payload != null) { |
| 5220 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5221 | } |
| 5222 | return s; |
| 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5225 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5226 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5227 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5228 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5229 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5230 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5231 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5232 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5234 | if (DBG) { |
| 5235 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5236 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5237 | } |
| 5238 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5239 | cla, command, p1, p2, p3, data); |
| 5240 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5241 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5242 | @Override |
| 5243 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5244 | int command, int p1, int p2, int p3, String data) { |
| 5245 | enforceModifyPermission(); |
| 5246 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5247 | if (DBG) { |
| 5248 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5249 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5250 | + " data=" + data); |
| 5251 | } |
| 5252 | |
| 5253 | return iccTransmitApduBasicChannelWithPermission( |
| 5254 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5255 | p2, p3, data); |
| 5256 | } |
| 5257 | |
| 5258 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5259 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5260 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
| 5263 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5264 | && TextUtils.equals(ISDR_AID, data)) { |
| 5265 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5266 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5267 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | if (bestComponent == null |
| 5269 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5270 | loge("The calling package is not allowed to select ISD-R."); |
| 5271 | throw new SecurityException( |
| 5272 | "The calling package is not allowed to select ISD-R."); |
| 5273 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5274 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5277 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5278 | null /* workSource */); |
| 5279 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5280 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | // Append the returned status code to the end of the response payload. |
| 5282 | String s = Integer.toHexString( |
| 5283 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5284 | if (response.payload != null) { |
| 5285 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5286 | } |
| 5287 | return s; |
| 5288 | } finally { |
| 5289 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5290 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5294 | 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] | 5295 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5297 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | final long identity = Binder.clearCallingIdentity(); |
| 5300 | try { |
| 5301 | if (DBG) { |
| 5302 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5303 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5304 | } |
| 5305 | |
| 5306 | IccIoResult response = |
| 5307 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5308 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5309 | subId); |
| 5310 | |
| 5311 | if (DBG) { |
| 5312 | log("Exchange SIM_IO [R]" + response); |
| 5313 | } |
| 5314 | |
| 5315 | byte[] result = null; |
| 5316 | int length = 2; |
| 5317 | if (response.payload != null) { |
| 5318 | length = 2 + response.payload.length; |
| 5319 | result = new byte[length]; |
| 5320 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5321 | } else { |
| 5322 | result = new byte[length]; |
| 5323 | } |
| 5324 | |
| 5325 | result[length - 1] = (byte) response.sw2; |
| 5326 | result[length - 2] = (byte) response.sw1; |
| 5327 | return result; |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5330 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5331 | } |
| 5332 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5333 | /** |
| 5334 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5335 | * on a particular subscription |
| 5336 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5337 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5338 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5339 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5340 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5341 | return null; |
| 5342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5347 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5348 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5349 | return null; |
| 5350 | } |
| 5351 | Object response = sendRequest( |
| 5352 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5353 | if (response instanceof String[]) { |
| 5354 | return (String[]) response; |
| 5355 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5356 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5358 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | } finally { |
| 5360 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5361 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5362 | } |
| 5363 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5364 | /** |
| 5365 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5366 | * subscription. |
| 5367 | * |
| 5368 | * @param subId the id of the subscription. |
| 5369 | * @param appType the uicc app type, must be USIM or SIM. |
| 5370 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5371 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5372 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5373 | * @return number of fplmns that is successfully written to the SIM. |
| 5374 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5375 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5376 | String callingFeatureId) { |
| 5377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5378 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5379 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5380 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5381 | } |
| 5382 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5383 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5384 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5385 | } |
| 5386 | if (fplmns == null) { |
| 5387 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5388 | } |
| 5389 | for (String fplmn : fplmns) { |
| 5390 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5391 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5392 | } |
| 5393 | } |
| 5394 | final long identity = Binder.clearCallingIdentity(); |
| 5395 | try { |
| 5396 | Object response = sendRequest( |
| 5397 | CMD_SET_FORBIDDEN_PLMNS, |
| 5398 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5399 | subId); |
| 5400 | return (int) response; |
| 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
| 5403 | } |
| 5404 | } |
| 5405 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5406 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5407 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5409 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5410 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | final long identity = Binder.clearCallingIdentity(); |
| 5412 | try { |
| 5413 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5414 | if (response.payload == null) { |
| 5415 | return ""; |
| 5416 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5417 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | // Append the returned status code to the end of the response payload. |
| 5419 | String s = Integer.toHexString( |
| 5420 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5421 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5422 | return s; |
| 5423 | } finally { |
| 5424 | Binder.restoreCallingIdentity(identity); |
| 5425 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5426 | } |
| 5427 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5428 | /** |
| 5429 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5430 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5431 | * |
| 5432 | * @param itemID the ID of the item to read |
| 5433 | * @return the NV item as a String, or null on error. |
| 5434 | */ |
| 5435 | @Override |
| 5436 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5437 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5439 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5440 | |
| 5441 | final long identity = Binder.clearCallingIdentity(); |
| 5442 | try { |
| 5443 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5444 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5446 | return value; |
| 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
| 5449 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5450 | } |
| 5451 | |
| 5452 | /** |
| 5453 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5454 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5455 | * |
| 5456 | * @param itemID the ID of the item to read |
| 5457 | * @param itemValue the value to write, as a String |
| 5458 | * @return true on success; false on any failure |
| 5459 | */ |
| 5460 | @Override |
| 5461 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5462 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5464 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | |
| 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
| 5468 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5469 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5470 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5472 | return success; |
| 5473 | } finally { |
| 5474 | Binder.restoreCallingIdentity(identity); |
| 5475 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | /** |
| 5479 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5480 | * Used for device configuration by some CDMA operators. |
| 5481 | * |
| 5482 | * @param preferredRoamingList byte array containing the new PRL |
| 5483 | * @return true on success; false on any failure |
| 5484 | */ |
| 5485 | @Override |
| 5486 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5488 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | |
| 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5493 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5494 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5495 | return success; |
| 5496 | } finally { |
| 5497 | Binder.restoreCallingIdentity(identity); |
| 5498 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5502 | * 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] | 5503 | * Used for device configuration by some CDMA operators. |
| 5504 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5505 | * @param slotIndex - device slot. |
| 5506 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5507 | * @return true on success; false on any failure |
| 5508 | */ |
| 5509 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5510 | public boolean resetModemConfig(int slotIndex) { |
| 5511 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5512 | if (phone != null) { |
| 5513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5514 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
| 5518 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5519 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5520 | return success; |
| 5521 | } finally { |
| 5522 | Binder.restoreCallingIdentity(identity); |
| 5523 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5525 | return false; |
| 5526 | } |
| 5527 | |
| 5528 | /** |
| 5529 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5530 | * |
| 5531 | * @param slotIndex - device slot. |
| 5532 | * |
| 5533 | * @return true on success; false on any failure |
| 5534 | */ |
| 5535 | @Override |
| 5536 | public boolean rebootModem(int slotIndex) { |
| 5537 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5538 | if (phone != null) { |
| 5539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5540 | mApp, phone.getSubId(), "rebootModem"); |
| 5541 | |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
| 5544 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5545 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5546 | return success; |
| 5547 | } finally { |
| 5548 | Binder.restoreCallingIdentity(identity); |
| 5549 | } |
| 5550 | } |
| 5551 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5552 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5553 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5554 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5555 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5556 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5557 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5558 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5559 | return new String[0]; |
| 5560 | } |
| 5561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5564 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
| 5567 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5568 | } |
| 5569 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5570 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5571 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5572 | * {@link #disableIms(int)}. |
| 5573 | * @param slotIndex device slot. |
| 5574 | */ |
| 5575 | public void resetIms(int slotIndex) { |
| 5576 | enforceModifyPermission(); |
| 5577 | |
| 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
| 5580 | if (mImsResolver == null) { |
| 5581 | // may happen if the does not support IMS. |
| 5582 | return; |
| 5583 | } |
| 5584 | mImsResolver.disableIms(slotIndex); |
| 5585 | mImsResolver.enableIms(slotIndex); |
| 5586 | } finally { |
| 5587 | Binder.restoreCallingIdentity(identity); |
| 5588 | } |
| 5589 | } |
| 5590 | |
| 5591 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5592 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5593 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5594 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5595 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5596 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | |
| 5598 | final long identity = Binder.clearCallingIdentity(); |
| 5599 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5600 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5601 | // may happen if the device does not support IMS. |
| 5602 | return; |
| 5603 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5604 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5605 | } finally { |
| 5606 | Binder.restoreCallingIdentity(identity); |
| 5607 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5611 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5612 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5613 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5614 | public void disableIms(int slotId) { |
| 5615 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5616 | |
| 5617 | final long identity = Binder.clearCallingIdentity(); |
| 5618 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5619 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5620 | // may happen if the device does not support IMS. |
| 5621 | return; |
| 5622 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5623 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(identity); |
| 5626 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5630 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5631 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5632 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5633 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5634 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5635 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5636 | |
| 5637 | final long identity = Binder.clearCallingIdentity(); |
| 5638 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5639 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5640 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5641 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5642 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5643 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | } finally { |
| 5645 | Binder.restoreCallingIdentity(identity); |
| 5646 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5647 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5648 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5649 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5650 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5651 | @Override |
| 5652 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5653 | enforceModifyPermission(); |
| 5654 | |
| 5655 | final long identity = Binder.clearCallingIdentity(); |
| 5656 | try { |
| 5657 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5658 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5659 | } finally { |
| 5660 | Binder.restoreCallingIdentity(identity); |
| 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5665 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5666 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5667 | */ |
| 5668 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5669 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | |
| 5671 | final long identity = Binder.clearCallingIdentity(); |
| 5672 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5673 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5674 | // may happen if the device does not support IMS. |
| 5675 | return null; |
| 5676 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5677 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5678 | } finally { |
| 5679 | Binder.restoreCallingIdentity(identity); |
| 5680 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5681 | } |
| 5682 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5683 | /** |
| 5684 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5685 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5686 | */ |
| 5687 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5688 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | |
| 5690 | final long identity = Binder.clearCallingIdentity(); |
| 5691 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5692 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5693 | // may happen if the device does not support IMS. |
| 5694 | return null; |
| 5695 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5696 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5700 | } |
| 5701 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5702 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5703 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5704 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5705 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5706 | * @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] | 5707 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5708 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5709 | * @param packageName The name of the package that the current configuration will be replaced |
| 5710 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5711 | * @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] | 5712 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5713 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5714 | int[] featureTypes, String packageName) { |
| 5715 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5716 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5718 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5719 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5720 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5723 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5724 | // may happen if the device does not support IMS. |
| 5725 | return false; |
| 5726 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5727 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5728 | for (int featureType : featureTypes) { |
| 5729 | featureConfig.put(featureType, packageName); |
| 5730 | } |
| 5731 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5732 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
| 5735 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5739 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5740 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5741 | * |
| 5742 | * This should only be used for testing. |
| 5743 | * |
| 5744 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5745 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5746 | */ |
| 5747 | @Override |
| 5748 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5749 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5750 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5751 | "clearCarrierImsServiceOverride"); |
| 5752 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5753 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5754 | "clearCarrierImsServiceOverride"); |
| 5755 | |
| 5756 | final long identity = Binder.clearCallingIdentity(); |
| 5757 | try { |
| 5758 | if (mImsResolver == null) { |
| 5759 | // may happen if the device does not support IMS. |
| 5760 | return false; |
| 5761 | } |
| 5762 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5763 | } finally { |
| 5764 | Binder.restoreCallingIdentity(identity); |
| 5765 | } |
| 5766 | } |
| 5767 | |
| 5768 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5769 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5770 | * |
| 5771 | * @param slotId The slot that the ImsService is associated with. |
| 5772 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5773 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5774 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5775 | * @return the package name of the ImsService configuration. |
| 5776 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5777 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5778 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5779 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5780 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5781 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5782 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5783 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | final long identity = Binder.clearCallingIdentity(); |
| 5786 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5787 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5788 | // may happen if the device does not support IMS. |
| 5789 | return ""; |
| 5790 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5791 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5792 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5793 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5797 | } |
| 5798 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5799 | /** |
| 5800 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5801 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5802 | * @param callback A callback with an integer containing the |
| 5803 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5804 | */ |
| 5805 | @Override |
| 5806 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5807 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5808 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5809 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5810 | "IMS not available on device."); |
| 5811 | } |
| 5812 | final long token = Binder.clearCallingIdentity(); |
| 5813 | try { |
| 5814 | int slotId = getSlotIndex(subId); |
| 5815 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5816 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5817 | + subId + "'"); |
| 5818 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5819 | } |
| 5820 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5821 | try { |
| 5822 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5823 | } catch (RemoteException e) { |
| 5824 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5825 | + "Ignore"); |
| 5826 | } |
| 5827 | }); |
| 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(token); |
| 5830 | } |
| 5831 | } |
| 5832 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5833 | /** |
| 5834 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5835 | */ |
| 5836 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5837 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | |
| 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5841 | // NOTE: Before S, this method only set the default phone. |
| 5842 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5843 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5844 | phone.setImsRegistrationState(registered); |
| 5845 | } |
| 5846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5853 | * Set the network selection mode to automatic. |
| 5854 | * |
| 5855 | */ |
| 5856 | @Override |
| 5857 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5859 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5860 | |
| 5861 | final long identity = Binder.clearCallingIdentity(); |
| 5862 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5863 | if (!isActiveSubscription(subId)) { |
| 5864 | return; |
| 5865 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5867 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5868 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5869 | } finally { |
| 5870 | Binder.restoreCallingIdentity(identity); |
| 5871 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5874 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5875 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5876 | * |
| 5877 | * @param subId the id of the subscription. |
| 5878 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5879 | * the operator to attach to. |
| 5880 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5881 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5882 | * normal network selection next time. |
| 5883 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5884 | */ |
| 5885 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5886 | public boolean setNetworkSelectionModeManual( |
| 5887 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5889 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5890 | |
| 5891 | if (!isActiveSubscription(subId)) { |
| 5892 | return false; |
| 5893 | } |
| 5894 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | final long identity = Binder.clearCallingIdentity(); |
| 5896 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5897 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5899 | if (DBG) { |
| 5900 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5901 | + " operator: " + operatorInfo); |
| 5902 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5904 | } finally { |
| 5905 | Binder.restoreCallingIdentity(identity); |
| 5906 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5907 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5908 | /** |
| 5909 | * Get the manual network selection |
| 5910 | * |
| 5911 | * @param subId the id of the subscription. |
| 5912 | * |
| 5913 | * @return the previously saved user selected PLMN |
| 5914 | */ |
| 5915 | @Override |
| 5916 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5917 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5918 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5919 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5920 | |
| 5921 | final long identity = Binder.clearCallingIdentity(); |
| 5922 | try { |
| 5923 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5924 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | final Phone phone = getPhone(subId); |
| 5928 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5929 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5930 | } |
| 5931 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5932 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5933 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5934 | } finally { |
| 5935 | Binder.restoreCallingIdentity(identity); |
| 5936 | } |
| 5937 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5938 | |
| 5939 | /** |
| 5940 | * Scans for available networks. |
| 5941 | */ |
| 5942 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5943 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5944 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5945 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5946 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5947 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5948 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5949 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5950 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5951 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5952 | .setCallingPid(Binder.getCallingPid()) |
| 5953 | .setCallingUid(Binder.getCallingUid()) |
| 5954 | .setMethod("getCellNetworkScanResults") |
| 5955 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5956 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5957 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5958 | .build()); |
| 5959 | switch (locationResult) { |
| 5960 | case DENIED_HARD: |
| 5961 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5962 | case DENIED_SOFT: |
| 5963 | return null; |
| 5964 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5966 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5967 | try { |
| 5968 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5969 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(identity); |
| 5973 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5977 | * Get the call forwarding info, given the call forwarding reason. |
| 5978 | */ |
| 5979 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5980 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5981 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5982 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5983 | long identity = Binder.clearCallingIdentity(); |
| 5984 | try { |
| 5985 | if (DBG) { |
| 5986 | log("getCallForwarding: subId " + subId |
| 5987 | + " callForwardingReason" + callForwardingReason); |
| 5988 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5989 | |
| 5990 | Phone phone = getPhone(subId); |
| 5991 | if (phone == null) { |
| 5992 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5993 | callback.onError( |
| 5994 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5995 | } catch (RemoteException e) { |
| 5996 | // ignore |
| 5997 | } |
| 5998 | return; |
| 5999 | } |
| 6000 | |
| 6001 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6002 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6003 | @Override |
| 6004 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6005 | try { |
| 6006 | callback.onCallForwardingInfoAvailable(info); |
| 6007 | } catch (RemoteException e) { |
| 6008 | // ignore |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | @Override |
| 6013 | public void onError(int error) { |
| 6014 | try { |
| 6015 | callback.onError(error); |
| 6016 | } catch (RemoteException e) { |
| 6017 | // ignore |
| 6018 | } |
| 6019 | } |
| 6020 | }); |
| 6021 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
| 6028 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6029 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6030 | */ |
| 6031 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6032 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6033 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6034 | enforceModifyPermission(); |
| 6035 | long identity = Binder.clearCallingIdentity(); |
| 6036 | try { |
| 6037 | if (DBG) { |
| 6038 | log("setCallForwarding: subId " + subId |
| 6039 | + " callForwardingInfo" + callForwardingInfo); |
| 6040 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6041 | |
| 6042 | Phone phone = getPhone(subId); |
| 6043 | if (phone == null) { |
| 6044 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6045 | callback.accept( |
| 6046 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6047 | } catch (RemoteException e) { |
| 6048 | // ignore |
| 6049 | } |
| 6050 | return; |
| 6051 | } |
| 6052 | |
| 6053 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6054 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6055 | |
| 6056 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6057 | } finally { |
| 6058 | Binder.restoreCallingIdentity(identity); |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6063 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6064 | */ |
| 6065 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6066 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6067 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6068 | long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6070 | Phone phone = getPhone(subId); |
| 6071 | if (phone == null) { |
| 6072 | try { |
| 6073 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6074 | } catch (RemoteException e) { |
| 6075 | // ignore |
| 6076 | } |
| 6077 | return; |
| 6078 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6079 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6080 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6081 | boolean requireUssd = c.getBoolean( |
| 6082 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6083 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6084 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6085 | if (requireUssd) { |
| 6086 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6087 | getSubscriptionCarrierId(subId)); |
| 6088 | String newUssdCommand = ""; |
| 6089 | try { |
| 6090 | newUssdCommand = carrierXmlParser.getFeature( |
| 6091 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6092 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6093 | } catch (NullPointerException e) { |
| 6094 | loge("Failed to generate USSD number" + e); |
| 6095 | } |
| 6096 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6097 | mMainThreadHandler, callback, carrierXmlParser, |
| 6098 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6099 | final String ussdCommand = newUssdCommand; |
| 6100 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6101 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6102 | }); |
| 6103 | } else { |
| 6104 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6105 | callback::accept); |
| 6106 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6107 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6108 | } finally { |
| 6109 | Binder.restoreCallingIdentity(identity); |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6114 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6115 | */ |
| 6116 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6117 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6118 | enforceModifyPermission(); |
| 6119 | long identity = Binder.clearCallingIdentity(); |
| 6120 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6121 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6122 | |
| 6123 | Phone phone = getPhone(subId); |
| 6124 | if (phone == null) { |
| 6125 | try { |
| 6126 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6127 | } catch (RemoteException e) { |
| 6128 | // ignore |
| 6129 | } |
| 6130 | return; |
| 6131 | } |
| 6132 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6133 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6134 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6135 | boolean requireUssd = c.getBoolean( |
| 6136 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6137 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6138 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6139 | if (requireUssd) { |
| 6140 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6141 | getSubscriptionCarrierId(subId)); |
| 6142 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6143 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6144 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6145 | String newUssdCommand = ""; |
| 6146 | try { |
| 6147 | newUssdCommand = carrierXmlParser.getFeature( |
| 6148 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6149 | .makeCommand(ssAction, null); |
| 6150 | } catch (NullPointerException e) { |
| 6151 | loge("Failed to generate USSD number" + e); |
| 6152 | } |
| 6153 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6154 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6155 | final String ussdCommand = newUssdCommand; |
| 6156 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6157 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6158 | }); |
| 6159 | } else { |
| 6160 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6161 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6162 | |
| 6163 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6164 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6171 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6172 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6173 | * @param subId id of the subscription |
| 6174 | * @param request contains the radio access networks with bands/channels to scan |
| 6175 | * @param messenger callback messenger for scan results or errors |
| 6176 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6177 | * @return the id of the requested scan which can be used to stop the scan. |
| 6178 | */ |
| 6179 | @Override |
| 6180 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6181 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6183 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6184 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6185 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6186 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6187 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6188 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6189 | .setCallingPid(Binder.getCallingPid()) |
| 6190 | .setCallingUid(Binder.getCallingUid()) |
| 6191 | .setMethod("requestNetworkScan") |
| 6192 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6193 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6194 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6195 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6196 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6197 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6198 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6199 | if (e != null) { |
| 6200 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6201 | throw e; |
| 6202 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6203 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6204 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6205 | } |
| 6206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6208 | int callingUid = Binder.getCallingUid(); |
| 6209 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6210 | final long identity = Binder.clearCallingIdentity(); |
| 6211 | try { |
| 6212 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6213 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6214 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6215 | } finally { |
| 6216 | Binder.restoreCallingIdentity(identity); |
| 6217 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6218 | } |
| 6219 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6220 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6221 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6222 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6223 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6224 | boolean hasNetworkScanPermission = |
| 6225 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6226 | == PERMISSION_GRANTED; |
| 6227 | |
| 6228 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6229 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6230 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6234 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6235 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6236 | return new SecurityException("Specific channels must not be" |
| 6237 | + " scanned without location access."); |
| 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6242 | return null; |
| 6243 | } |
| 6244 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6245 | /** |
| 6246 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6247 | * |
| 6248 | * @param subId id of the subscription |
| 6249 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6250 | */ |
| 6251 | @Override |
| 6252 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6254 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6256 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6257 | final long identity = Binder.clearCallingIdentity(); |
| 6258 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6259 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | } finally { |
| 6261 | Binder.restoreCallingIdentity(identity); |
| 6262 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6266 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6267 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6268 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6269 | */ |
| 6270 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6271 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6272 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6273 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6274 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6275 | |
| 6276 | final long identity = Binder.clearCallingIdentity(); |
| 6277 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6278 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6279 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6280 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6281 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6282 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | } finally { |
| 6284 | Binder.restoreCallingIdentity(identity); |
| 6285 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6289 | * Get the allowed network types for certain reason. |
| 6290 | * |
| 6291 | * @param subId the id of the subscription. |
| 6292 | * @param reason the reason the allowed network type change is taking place |
| 6293 | * @return the allowed network types. |
| 6294 | */ |
| 6295 | @Override |
| 6296 | public long getAllowedNetworkTypesForReason(int subId, |
| 6297 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6298 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6299 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6300 | final long identity = Binder.clearCallingIdentity(); |
| 6301 | try { |
| 6302 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6303 | } finally { |
| 6304 | Binder.restoreCallingIdentity(identity); |
| 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6309 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6310 | * @param subId subscription id of the sim card |
| 6311 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6312 | * This can be passed following states |
| 6313 | * <ol> |
| 6314 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6315 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6316 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6317 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6318 | * </ol> |
| 6319 | * @return operation result. |
| 6320 | */ |
| 6321 | @Override |
| 6322 | public int setNrDualConnectivityState(int subId, |
| 6323 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6325 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6326 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6327 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6328 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6329 | } |
| 6330 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6331 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6332 | final long identity = Binder.clearCallingIdentity(); |
| 6333 | try { |
| 6334 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6335 | nrDualConnectivityState, subId, |
| 6336 | workSource); |
| 6337 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6338 | return result; |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | /** |
| 6345 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6346 | * @return true if dual connectivity is enabled else false |
| 6347 | */ |
| 6348 | @Override |
| 6349 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6350 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6351 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6352 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6353 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6354 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6355 | return false; |
| 6356 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6357 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
| 6360 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6361 | null, subId, workSource); |
| 6362 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6363 | return isEnabled; |
| 6364 | } finally { |
| 6365 | Binder.restoreCallingIdentity(identity); |
| 6366 | } |
| 6367 | } |
| 6368 | |
| 6369 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6370 | * Set the allowed network types of the device and |
| 6371 | * provide the reason triggering the allowed network change. |
| 6372 | * |
| 6373 | * @param subId the id of the subscription. |
| 6374 | * @param reason the reason the allowed network type change is taking place |
| 6375 | * @param allowedNetworkTypes the allowed network types. |
| 6376 | * @return true on success; false on any failure. |
| 6377 | */ |
| 6378 | @Override |
| 6379 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6380 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6381 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6383 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6384 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6385 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6386 | return false; |
| 6387 | } |
| 6388 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6389 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6390 | return false; |
| 6391 | } |
| 6392 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6393 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6394 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6395 | |
| 6396 | |
| 6397 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6398 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6399 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6400 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6401 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6402 | final long identity = Binder.clearCallingIdentity(); |
| 6403 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6404 | Boolean success = (Boolean) sendRequest( |
| 6405 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6406 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6407 | |
| 6408 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6409 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6416 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6417 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6418 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6419 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6420 | * @hide |
| 6421 | */ |
| 6422 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6423 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6424 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6425 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6426 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6427 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6428 | if (phone != null) { |
| 6429 | return phone.hasMatchedTetherApnSetting(); |
| 6430 | } else { |
| 6431 | return false; |
| 6432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6435 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6439 | * Enable or disable always reporting signal strength changes from radio. |
| 6440 | * |
| 6441 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6442 | */ |
| 6443 | @Override |
| 6444 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6445 | enforceModifyPermission(); |
| 6446 | enforceSystemCaller(); |
| 6447 | |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | final Phone phone = getPhone(subId); |
| 6450 | try { |
| 6451 | if (phone != null) { |
| 6452 | if (DBG) { |
| 6453 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6454 | + " isEnable=" + isEnable); |
| 6455 | } |
| 6456 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6457 | } else { |
| 6458 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6459 | + subId); |
| 6460 | } |
| 6461 | } finally { |
| 6462 | Binder.restoreCallingIdentity(identity); |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6467 | * Get the user enabled state of Mobile Data. |
| 6468 | * |
| 6469 | * TODO: remove and use isUserDataEnabled. |
| 6470 | * This can't be removed now because some vendor codes |
| 6471 | * calls through ITelephony directly while they should |
| 6472 | * use TelephonyManager. |
| 6473 | * |
| 6474 | * @return true on enabled |
| 6475 | */ |
| 6476 | @Override |
| 6477 | public boolean getDataEnabled(int subId) { |
| 6478 | return isUserDataEnabled(subId); |
| 6479 | } |
| 6480 | |
| 6481 | /** |
| 6482 | * Get whether mobile data is enabled per user setting. |
| 6483 | * |
| 6484 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6485 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6486 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6487 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6488 | * |
| 6489 | * @return {@code true} if data is enabled else {@code false} |
| 6490 | */ |
| 6491 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6492 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6493 | try { |
| 6494 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6495 | null); |
| 6496 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6498 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6499 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6500 | |
| 6501 | final long identity = Binder.clearCallingIdentity(); |
| 6502 | try { |
| 6503 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6504 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6505 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6506 | if (phone != null) { |
| 6507 | boolean retVal = phone.isUserDataEnabled(); |
| 6508 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6509 | return retVal; |
| 6510 | } else { |
| 6511 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6512 | return false; |
| 6513 | } |
| 6514 | } finally { |
| 6515 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6516 | } |
| 6517 | } |
| 6518 | |
| 6519 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6520 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6521 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6522 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6523 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6524 | * @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] | 6525 | */ |
| 6526 | @Override |
| 6527 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6528 | try { |
| 6529 | try { |
| 6530 | mApp.enforceCallingOrSelfPermission( |
| 6531 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6532 | null); |
| 6533 | } catch (Exception e) { |
| 6534 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6535 | "isDataEnabled"); |
| 6536 | } |
| 6537 | } catch (Exception e) { |
| 6538 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6540 | |
| 6541 | final long identity = Binder.clearCallingIdentity(); |
| 6542 | try { |
| 6543 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6544 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6545 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6546 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6547 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6548 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6549 | return retVal; |
| 6550 | } else { |
| 6551 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6552 | return false; |
| 6553 | } |
| 6554 | } finally { |
| 6555 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6556 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6557 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6558 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6559 | /** |
| 6560 | * Check if data is enabled for a specific reason |
| 6561 | * @param subId Subscription index |
| 6562 | * @param reason the reason the data enable change is taking place |
| 6563 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6564 | */ |
| 6565 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6566 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6567 | @TelephonyManager.DataEnabledReason int reason) { |
| 6568 | try { |
| 6569 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6570 | null); |
| 6571 | } catch (Exception e) { |
| 6572 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6573 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | |
| 6577 | final long identity = Binder.clearCallingIdentity(); |
| 6578 | try { |
| 6579 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6580 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6581 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6582 | + " reason=" + reason); |
| 6583 | } |
| 6584 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6585 | if (phone != null) { |
| 6586 | boolean retVal; |
| 6587 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6588 | retVal = phone.isUserDataEnabled(); |
| 6589 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6590 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6591 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6592 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6593 | return retVal; |
| 6594 | } else { |
| 6595 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6596 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6597 | + subId + " retVal=false"); |
| 6598 | } |
| 6599 | return false; |
| 6600 | } |
| 6601 | } finally { |
| 6602 | Binder.restoreCallingIdentity(identity); |
| 6603 | } |
| 6604 | } |
| 6605 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6606 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6607 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6608 | if (uid == Process.PHONE_UID) { |
| 6609 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6610 | // 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] | 6611 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6612 | } |
| 6613 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6614 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6615 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6616 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6617 | || subController == null) return privilegeFromSim; |
| 6618 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6619 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6620 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6621 | |
| 6622 | final long identity = Binder.clearCallingIdentity(); |
| 6623 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6624 | int subId = phone.getSubId(); |
| 6625 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6626 | // A test override is in place for the privileges for this subId, so don't try to |
| 6627 | // read the subscription privileges. |
| 6628 | return privilegeFromSim; |
| 6629 | } |
| 6630 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6631 | SubscriptionManager subManager = (SubscriptionManager) |
| 6632 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6633 | for (String pkg : packages) { |
| 6634 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6635 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6636 | } |
| 6637 | } |
| 6638 | return privilegeFromSim; |
| 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6645 | String pkgName) { |
| 6646 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6647 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6648 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6649 | || subController == null) return privilegeFromSim; |
| 6650 | |
| 6651 | final long identity = Binder.clearCallingIdentity(); |
| 6652 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6653 | int subId = phone.getSubId(); |
| 6654 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6655 | // A test override is in place for the privileges for this subId, so don't try to |
| 6656 | // read the subscription privileges. |
| 6657 | return privilegeFromSim; |
| 6658 | } |
| 6659 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6660 | SubscriptionManager subManager = (SubscriptionManager) |
| 6661 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6662 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6663 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6664 | } finally { |
| 6665 | Binder.restoreCallingIdentity(identity); |
| 6666 | } |
| 6667 | } |
| 6668 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6669 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6670 | public int getCarrierPrivilegeStatus(int subId) { |
| 6671 | final Phone phone = getPhone(subId); |
| 6672 | if (phone == null) { |
| 6673 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6674 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6675 | } |
| 6676 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6677 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6678 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6679 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6680 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6681 | |
| 6682 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6683 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6684 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6685 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6686 | |
| 6687 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6688 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6689 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6690 | final Phone phone = getPhone(subId); |
| 6691 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6692 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6693 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6694 | } |
| 6695 | UiccProfile profile = |
| 6696 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6697 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6698 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6699 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6700 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6701 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6702 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6703 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6704 | } |
| 6705 | |
| 6706 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6707 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6708 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6709 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6710 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6714 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6715 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6716 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6717 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6718 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6719 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6720 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6721 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6722 | } |
| 6723 | |
| 6724 | @Override |
| 6725 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6726 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6727 | if (TextUtils.isEmpty(pkgName)) |
| 6728 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6729 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6730 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6731 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6732 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6733 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6734 | continue; |
| 6735 | } |
| 6736 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6737 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6738 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6739 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6740 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6741 | break; |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6746 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6747 | |
| 6748 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6749 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6750 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6751 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6752 | loge("phoneId " + phoneId + " is not valid."); |
| 6753 | return null; |
| 6754 | } |
| 6755 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6756 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6757 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6758 | return null ; |
| 6759 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6760 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6761 | } |
| 6762 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6763 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6764 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6765 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6766 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6767 | List<String> privilegedPackages = new ArrayList<>(); |
| 6768 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6769 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6770 | // has UICC in that slot. |
| 6771 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6772 | if (card.hasCarrierPrivilegeRules()) { |
| 6773 | if (packages == null) { |
| 6774 | // Only check packages in user 0 for now |
| 6775 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6776 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6777 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6778 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6779 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6780 | } |
| 6781 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6782 | PackageInfo pkgInfo = packages.get(p); |
| 6783 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6784 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6785 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6786 | privilegedPackages.add(pkgInfo.packageName); |
| 6787 | } |
| 6788 | } |
| 6789 | } |
| 6790 | } |
| 6791 | return privilegedPackages; |
| 6792 | } |
| 6793 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6794 | @Override |
| 6795 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6796 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6797 | |
| 6798 | final long identity = Binder.clearCallingIdentity(); |
| 6799 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6800 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6801 | try { |
| 6802 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6803 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6804 | } |
| 6805 | } finally { |
| 6806 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6807 | } |
| 6808 | return privilegedPackages; |
| 6809 | } |
| 6810 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6811 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6812 | final Phone phone = getPhone(subId); |
| 6813 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6814 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6815 | return null; |
| 6816 | } |
| 6817 | String iccId = card.getIccId(); |
| 6818 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6819 | return null; |
| 6820 | } |
| 6821 | return iccId; |
| 6822 | } |
| 6823 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6824 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6825 | public void setCallComposerStatus(int subId, int status) { |
| 6826 | enforceModifyPermission(); |
| 6827 | |
| 6828 | final long identity = Binder.clearCallingIdentity(); |
| 6829 | try { |
| 6830 | Phone phone = getPhone(subId); |
| 6831 | if (phone != null) { |
| 6832 | Phone defaultPhone = phone.getImsPhone(); |
| 6833 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6834 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6835 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6836 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6837 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6838 | } |
| 6839 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6840 | } catch (ImsException e) { |
| 6841 | throw new ServiceSpecificException(e.getCode()); |
| 6842 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6843 | Binder.restoreCallingIdentity(identity); |
| 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | @Override |
| 6848 | public int getCallComposerStatus(int subId) { |
| 6849 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6850 | |
| 6851 | final long identity = Binder.clearCallingIdentity(); |
| 6852 | try { |
| 6853 | Phone phone = getPhone(subId); |
| 6854 | if (phone != null) { |
| 6855 | Phone defaultPhone = phone.getImsPhone(); |
| 6856 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6857 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6858 | return imsPhone.getCallComposerStatus(); |
| 6859 | } |
| 6860 | } |
| 6861 | } finally { |
| 6862 | Binder.restoreCallingIdentity(identity); |
| 6863 | } |
| 6864 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6865 | } |
| 6866 | |
| 6867 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6868 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6869 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6870 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6871 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6872 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6873 | final long identity = Binder.clearCallingIdentity(); |
| 6874 | try { |
| 6875 | final String iccId = getIccId(subId); |
| 6876 | final Phone phone = getPhone(subId); |
| 6877 | if (phone == null) { |
| 6878 | return false; |
| 6879 | } |
| 6880 | final String subscriberId = phone.getSubscriberId(); |
| 6881 | |
| 6882 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6883 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6884 | + subscriberId + " to " + number); |
| 6885 | } |
| 6886 | |
| 6887 | if (TextUtils.isEmpty(iccId)) { |
| 6888 | return false; |
| 6889 | } |
| 6890 | |
| 6891 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6892 | |
| 6893 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6894 | if (alphaTag == null) { |
| 6895 | editor.remove(alphaTagPrefKey); |
| 6896 | } else { |
| 6897 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6898 | } |
| 6899 | |
| 6900 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6901 | // track all merged IMSIs based on line number |
| 6902 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6903 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6904 | if (number == null) { |
| 6905 | editor.remove(numberPrefKey); |
| 6906 | editor.remove(subscriberPrefKey); |
| 6907 | } else { |
| 6908 | editor.putString(numberPrefKey, number); |
| 6909 | editor.putString(subscriberPrefKey, subscriberId); |
| 6910 | } |
| 6911 | |
| 6912 | editor.commit(); |
| 6913 | return true; |
| 6914 | } finally { |
| 6915 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6916 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6917 | } |
| 6918 | |
| 6919 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6920 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6921 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6922 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6923 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6924 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6925 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6926 | return null; |
| 6927 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6928 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6929 | final long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
| 6931 | String iccId = getIccId(subId); |
| 6932 | if (iccId != null) { |
| 6933 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6934 | if (DBG_MERGE) { |
| 6935 | log("getLine1NumberForDisplay returning " |
| 6936 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6937 | } |
| 6938 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6941 | return null; |
| 6942 | } finally { |
| 6943 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6944 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6948 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6949 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6950 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6951 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6952 | return null; |
| 6953 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | final long identity = Binder.clearCallingIdentity(); |
| 6956 | try { |
| 6957 | String iccId = getIccId(subId); |
| 6958 | if (iccId != null) { |
| 6959 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6960 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6961 | } |
| 6962 | return null; |
| 6963 | } finally { |
| 6964 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6965 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6966 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6967 | |
| 6968 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6969 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6970 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6971 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6972 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6974 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6975 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6976 | return null; |
| 6977 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6978 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6979 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6980 | // the process, where TelephonyManager was instantiated. |
| 6981 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6984 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6986 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6987 | |
| 6988 | // Figure out what subscribers are currently active |
| 6989 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6991 | // Only consider subs which match the current subId |
| 6992 | // This logic can be simplified. See b/131189269 for progress. |
| 6993 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6994 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | |
| 6997 | // First pass, find a number override for an active subscriber |
| 6998 | String mergeNumber = null; |
| 6999 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7000 | for (String key : prefs.keySet()) { |
| 7001 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7002 | final String subscriberId = (String) prefs.get(key); |
| 7003 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7004 | final String iccId = key.substring( |
| 7005 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7006 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7007 | mergeNumber = (String) prefs.get(numberKey); |
| 7008 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7009 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7010 | + " for active subscriber " + subscriberId); |
| 7011 | } |
| 7012 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7013 | break; |
| 7014 | } |
| 7015 | } |
| 7016 | } |
| 7017 | } |
| 7018 | |
| 7019 | // Shortcut when no active merged subscribers |
| 7020 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7021 | return null; |
| 7022 | } |
| 7023 | |
| 7024 | // Second pass, find all subscribers under that line override |
| 7025 | final ArraySet<String> result = new ArraySet<>(); |
| 7026 | for (String key : prefs.keySet()) { |
| 7027 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7028 | final String number = (String) prefs.get(key); |
| 7029 | if (mergeNumber.equals(number)) { |
| 7030 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7031 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7032 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7033 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7034 | result.add(subscriberId); |
| 7035 | } |
| 7036 | } |
| 7037 | } |
| 7038 | } |
| 7039 | |
| 7040 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7041 | Arrays.sort(resultArray); |
| 7042 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7043 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7044 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7045 | } |
| 7046 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7047 | } finally { |
| 7048 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7049 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7050 | } |
| 7051 | |
| 7052 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7053 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7054 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7055 | |
| 7056 | final long identity = Binder.clearCallingIdentity(); |
| 7057 | try { |
| 7058 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7059 | TelephonyManager.class); |
| 7060 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7061 | if (subscriberId == null) { |
| 7062 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7063 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7064 | + subId); |
| 7065 | } |
| 7066 | return null; |
| 7067 | } |
| 7068 | |
| 7069 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7070 | .getSubscriptionInfo(subId); |
| 7071 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7072 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7073 | if (groupUuid == null) { |
| 7074 | return new String[]{subscriberId}; |
| 7075 | } |
| 7076 | |
| 7077 | // Get all subscriberIds from the group. |
| 7078 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7079 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7080 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7081 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7082 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7083 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7084 | if (subscriberId != null) { |
| 7085 | mergedSubscriberIds.add(subscriberId); |
| 7086 | } |
| 7087 | } |
| 7088 | |
| 7089 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
| 7092 | |
| 7093 | } |
| 7094 | } |
| 7095 | |
| 7096 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7097 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7098 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7099 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7100 | |
| 7101 | final long identity = Binder.clearCallingIdentity(); |
| 7102 | try { |
| 7103 | final Phone phone = getPhone(subId); |
| 7104 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7105 | } finally { |
| 7106 | Binder.restoreCallingIdentity(identity); |
| 7107 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7108 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7109 | |
| 7110 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7111 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7112 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7113 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7114 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7115 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | |
| 7117 | final long identity = Binder.clearCallingIdentity(); |
| 7118 | try { |
| 7119 | final Phone phone = getPhone(subId); |
| 7120 | if (phone == null) { |
| 7121 | return false; |
| 7122 | } |
| 7123 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7124 | cdmaNonRoamingList); |
| 7125 | } finally { |
| 7126 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7127 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7131 | @Deprecated |
| 7132 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7133 | enforceModifyPermission(); |
| 7134 | |
| 7135 | int returnValue = 0; |
| 7136 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7137 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7138 | if(result.exception == null) { |
| 7139 | if (result.result != null) { |
| 7140 | byte[] responseData = (byte[])(result.result); |
| 7141 | if(responseData.length > oemResp.length) { |
| 7142 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7143 | responseData.length + "bytes. Buffer Size is " + |
| 7144 | oemResp.length + "bytes."); |
| 7145 | } |
| 7146 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7147 | returnValue = responseData.length; |
| 7148 | } |
| 7149 | } else { |
| 7150 | CommandException ex = (CommandException) result.exception; |
| 7151 | returnValue = ex.getCommandError().ordinal(); |
| 7152 | if(returnValue > 0) returnValue *= -1; |
| 7153 | } |
| 7154 | } catch (RuntimeException e) { |
| 7155 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7156 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7157 | if(returnValue > 0) returnValue *= -1; |
| 7158 | } |
| 7159 | |
| 7160 | return returnValue; |
| 7161 | } |
| 7162 | |
| 7163 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7164 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7165 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7166 | try { |
| 7167 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7168 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7169 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7170 | } catch (SecurityException e) { |
| 7171 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7172 | throw e; |
| 7173 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7174 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7175 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7176 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7177 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7180 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7181 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7182 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7183 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7187 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7188 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7189 | |
| 7190 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7191 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7192 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7193 | try { |
| 7194 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7195 | Binder.getCallingUid())) { |
| 7196 | throw new SecurityException("Package uid and package name do not match: " |
| 7197 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7198 | } |
| 7199 | } catch (PackageManager.NameNotFoundException e) { |
| 7200 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7201 | } |
| 7202 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7203 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7204 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7205 | throw new SecurityException("App must be the dialer role holder to" |
| 7206 | + " upload a call composer pic"); |
| 7207 | } |
| 7208 | |
| 7209 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7210 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7211 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7212 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7213 | boolean readUntilEnd = false; |
| 7214 | int totalBytesRead = 0; |
| 7215 | byte[] buffer = new byte[16 * 1024]; |
| 7216 | while (true) { |
| 7217 | int numRead; |
| 7218 | try { |
| 7219 | numRead = input.read(buffer); |
| 7220 | } catch (IOException e) { |
| 7221 | try { |
| 7222 | fd.checkError(); |
| 7223 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7224 | null); |
| 7225 | } catch (IOException e1) { |
| 7226 | // This means that the other side closed explicitly with an error. If this |
| 7227 | // happens, log and ignore. |
| 7228 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7229 | } |
| 7230 | break; |
| 7231 | } |
| 7232 | if (numRead == -1) { |
| 7233 | readUntilEnd = true; |
| 7234 | break; |
| 7235 | } |
| 7236 | totalBytesRead += numRead; |
| 7237 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7238 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7239 | try { |
| 7240 | input.close(); |
| 7241 | } catch (IOException e) { |
| 7242 | // ignore |
| 7243 | } |
| 7244 | break; |
| 7245 | } |
| 7246 | output.write(buffer, 0, numRead); |
| 7247 | } |
| 7248 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7249 | // close is above, where the picture size is too big. |
| 7250 | |
| 7251 | try { |
| 7252 | fd.checkError(); |
| 7253 | } catch (IOException e) { |
| 7254 | loge("Remote end for call composer closed with an error: " + e); |
| 7255 | return; |
| 7256 | } |
| 7257 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7258 | if (!readUntilEnd) { |
| 7259 | loge("Did not finish reading entire image; aborting"); |
| 7260 | return; |
| 7261 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7262 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7263 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7264 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7265 | new CallComposerPictureTransfer.Factory() {}, |
| 7266 | imageData, |
| 7267 | (result) -> { |
| 7268 | if (result.first != null) { |
| 7269 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7270 | Bundle outputResult = new Bundle(); |
| 7271 | outputResult.putParcelable( |
| 7272 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7273 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7274 | outputResult); |
| 7275 | } else { |
| 7276 | callback.send(result.second, null); |
| 7277 | } |
| 7278 | } |
| 7279 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7280 | }); |
| 7281 | } |
| 7282 | |
| 7283 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7284 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7285 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7286 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7287 | |
| 7288 | final long identity = Binder.clearCallingIdentity(); |
| 7289 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7290 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7291 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7292 | } finally { |
| 7293 | Binder.restoreCallingIdentity(identity); |
| 7294 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7295 | } |
| 7296 | |
| 7297 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7298 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7299 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7300 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7301 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7302 | return false; |
| 7303 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7308 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7309 | // In the long run, we may instead need to check if there exists a connection service |
| 7310 | // which can support video calling. |
| 7311 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7312 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | return imsManager.isVtEnabledByPlatform() |
| 7314 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7315 | && imsManager.isVtEnabledByUser(); |
| 7316 | } finally { |
| 7317 | Binder.restoreCallingIdentity(identity); |
| 7318 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7319 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7320 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7321 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7322 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7323 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7324 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7325 | mApp, subId, callingPackage, callingFeatureId, |
| 7326 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | return false; |
| 7328 | } |
| 7329 | |
| 7330 | final long identity = Binder.clearCallingIdentity(); |
| 7331 | try { |
| 7332 | CarrierConfigManager configManager = |
| 7333 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7334 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7336 | } finally { |
| 7337 | Binder.restoreCallingIdentity(identity); |
| 7338 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7339 | } |
| 7340 | |
| 7341 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7342 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7344 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7345 | return false; |
| 7346 | } |
| 7347 | |
| 7348 | final long identity = Binder.clearCallingIdentity(); |
| 7349 | try { |
| 7350 | CarrierConfigManager configManager = |
| 7351 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7352 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7353 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7357 | } |
| 7358 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7359 | @Override |
| 7360 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7361 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7362 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7363 | } |
| 7364 | |
| 7365 | @Override |
| 7366 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7367 | final long identity = Binder.clearCallingIdentity(); |
| 7368 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7369 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7370 | } finally { |
| 7371 | Binder.restoreCallingIdentity(identity); |
| 7372 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7373 | } |
| 7374 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7375 | /** |
| 7376 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7377 | * support for the feature and device firmware support. |
| 7378 | * |
| 7379 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7380 | */ |
| 7381 | @Override |
| 7382 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7383 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7384 | final Phone phone = getPhone(subscriptionId); |
| 7385 | if (phone == null) { |
| 7386 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7387 | return false; |
| 7388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7390 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7392 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7393 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7394 | return isCarrierSupported && isDeviceSupported; |
| 7395 | } finally { |
| 7396 | Binder.restoreCallingIdentity(identity); |
| 7397 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7398 | } |
| 7399 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7400 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7401 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7402 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7403 | * 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] | 7404 | */ |
| 7405 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | final long identity = Binder.clearCallingIdentity(); |
| 7407 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7408 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7409 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7410 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7411 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7412 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7413 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7414 | } finally { |
| 7415 | Binder.restoreCallingIdentity(identity); |
| 7416 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7417 | } |
| 7418 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7419 | @Deprecated |
| 7420 | @Override |
| 7421 | public String getDeviceId(String callingPackage) { |
| 7422 | return getDeviceIdWithFeature(callingPackage, null); |
| 7423 | } |
| 7424 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7425 | /** |
| 7426 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7427 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7428 | * |
| 7429 | * <p>Requires Permission: |
| 7430 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7431 | */ |
| 7432 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7433 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7434 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7435 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7436 | return null; |
| 7437 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7438 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7439 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7440 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7441 | return null; |
| 7442 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | |
| 7444 | final long identity = Binder.clearCallingIdentity(); |
| 7445 | try { |
| 7446 | return phone.getDeviceId(); |
| 7447 | } finally { |
| 7448 | Binder.restoreCallingIdentity(identity); |
| 7449 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7450 | } |
| 7451 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7452 | /** |
| 7453 | * {@hide} |
| 7454 | * Returns the IMS Registration Status on a particular subid |
| 7455 | * |
| 7456 | * @param subId |
| 7457 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7458 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7459 | Phone phone = getPhone(subId); |
| 7460 | if (phone != null) { |
| 7461 | return phone.isImsRegistered(); |
| 7462 | } else { |
| 7463 | return false; |
| 7464 | } |
| 7465 | } |
| 7466 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7467 | @Override |
| 7468 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | final long identity = Binder.clearCallingIdentity(); |
| 7470 | try { |
| 7471 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7472 | } finally { |
| 7473 | Binder.restoreCallingIdentity(identity); |
| 7474 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7475 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7476 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7477 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7478 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7479 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7480 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7481 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7482 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7483 | } |
| 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
| 7486 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
| 7490 | } |
| 7491 | |
| 7492 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7493 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7494 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7495 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7496 | mApp, |
| 7497 | subscriptionId, |
| 7498 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7499 | final long identity = Binder.clearCallingIdentity(); |
| 7500 | try { |
| 7501 | Phone phone = getPhone(subscriptionId); |
| 7502 | if (phone == null) { |
| 7503 | return null; |
| 7504 | } |
| 7505 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7506 | } finally { |
| 7507 | Binder.restoreCallingIdentity(identity); |
| 7508 | } |
| 7509 | } |
| 7510 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7511 | /** |
| 7512 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7513 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7514 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
| 7517 | Phone phone = getPhone(subId); |
| 7518 | if (phone != null) { |
| 7519 | return phone.isWifiCallingEnabled(); |
| 7520 | } else { |
| 7521 | return false; |
| 7522 | } |
| 7523 | } finally { |
| 7524 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7525 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7526 | } |
| 7527 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7528 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7529 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7530 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7531 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7532 | final long identity = Binder.clearCallingIdentity(); |
| 7533 | try { |
| 7534 | Phone phone = getPhone(subId); |
| 7535 | if (phone != null) { |
| 7536 | return phone.isVideoEnabled(); |
| 7537 | } else { |
| 7538 | return false; |
| 7539 | } |
| 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7542 | } |
| 7543 | } |
| 7544 | |
| 7545 | /** |
| 7546 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7547 | * defined in {@link ImsRegistrationImplBase}. |
| 7548 | */ |
| 7549 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | final long identity = Binder.clearCallingIdentity(); |
| 7551 | try { |
| 7552 | Phone phone = getPhone(subId); |
| 7553 | if (phone != null) { |
| 7554 | return phone.getImsRegistrationTech(); |
| 7555 | } else { |
| 7556 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7557 | } |
| 7558 | } finally { |
| 7559 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7560 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7561 | } |
| 7562 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7563 | @Override |
| 7564 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7565 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7566 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7567 | return; |
| 7568 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7569 | Phone defaultPhone = getDefaultPhone(); |
| 7570 | if (defaultPhone != null) { |
| 7571 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7572 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7573 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7574 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7575 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7576 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7577 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7578 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7579 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7580 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7581 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7582 | Phone phone = getPhone(subId); |
| 7583 | if (phone != null) { |
| 7584 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7585 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7586 | "user=" + RadioAccessFamily.getRafFromNetworkType( |
| 7587 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 7588 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7589 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7590 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7591 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7592 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7593 | // There has been issues when Sms raw table somehow stores orphan |
| 7594 | // fragments. They lead to garbled message when new fragments come |
| 7595 | // in and combined with those stale ones. In case this happens again, |
| 7596 | // user can reset all network settings which will clean up this table. |
| 7597 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7598 | // Clean up IMS settings as well here. |
| 7599 | int slotId = getSlotIndex(subId); |
| 7600 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7601 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7602 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7603 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7604 | if (defaultPhone == null) { |
| 7605 | return; |
| 7606 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7607 | // Erase modem config if erase modem on network setting is enabled. |
| 7608 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7609 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7610 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7611 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7612 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7613 | |
| 7614 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7615 | } finally { |
| 7616 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7617 | } |
| 7618 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7619 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7620 | private void cleanUpSmsRawTable(Context context) { |
| 7621 | ContentResolver resolver = context.getContentResolver(); |
| 7622 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7623 | resolver.delete(uri, null, null); |
| 7624 | } |
| 7625 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7626 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7627 | public String getSimLocaleForSubscriber(int subId) { |
| 7628 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7629 | final Phone phone = getPhone(subId); |
| 7630 | if (phone == null) { |
| 7631 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7632 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7633 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | final long identity = Binder.clearCallingIdentity(); |
| 7635 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7636 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7637 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7638 | if (info == null) { |
| 7639 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7640 | return null; |
| 7641 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7643 | // preferences (EF-PL and EF-LI)... |
| 7644 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7646 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7647 | if (localeFromDefaultSim != null) { |
| 7648 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7649 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7650 | + localeFromDefaultSim); |
| 7651 | return localeFromDefaultSim.toLanguageTag(); |
| 7652 | } else { |
| 7653 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | } |
| 7655 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7658 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7659 | // the SIM and carrier preferences does not include a country we add the country |
| 7660 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7661 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7662 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7663 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7664 | return mccLocale.toLanguageTag(); |
| 7665 | } |
| 7666 | |
| 7667 | if (DBG) log("No locale found - returning null"); |
| 7668 | return null; |
| 7669 | } finally { |
| 7670 | Binder.restoreCallingIdentity(identity); |
| 7671 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7672 | } |
| 7673 | |
| 7674 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7675 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7676 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7677 | } |
| 7678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7679 | /** |
| 7680 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7681 | */ |
| 7682 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7683 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7684 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7685 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7686 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7687 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7688 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7689 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7690 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7691 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7692 | * representing the state of the modem. |
| 7693 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7694 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7695 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7696 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7697 | */ |
| 7698 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7699 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7700 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7701 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7702 | |
| 7703 | final long identity = Binder.clearCallingIdentity(); |
| 7704 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7705 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7706 | } finally { |
| 7707 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7708 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7709 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7710 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7711 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7712 | // less than total activity duration. |
| 7713 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7714 | if (info == null) { |
| 7715 | return false; |
| 7716 | } |
| 7717 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7718 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7719 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7720 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7721 | return (info.isValid() |
| 7722 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7723 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7724 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7725 | && (totalTxTimeMs <= activityDurationMs)); |
| 7726 | } |
| 7727 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7728 | /** |
| 7729 | * {@hide} |
| 7730 | * Returns the service state information on specified subscription. |
| 7731 | */ |
| 7732 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7733 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7734 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7736 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7737 | return null; |
| 7738 | } |
| 7739 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7740 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7741 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7742 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7743 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7744 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7745 | .setCallingPid(Binder.getCallingPid()) |
| 7746 | .setCallingUid(Binder.getCallingUid()) |
| 7747 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7748 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7749 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7750 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7751 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7752 | .build()); |
| 7753 | |
| 7754 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7755 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7756 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7757 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7758 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7759 | .setCallingPid(Binder.getCallingPid()) |
| 7760 | .setCallingUid(Binder.getCallingUid()) |
| 7761 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7762 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7763 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7764 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7765 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7766 | .build()); |
| 7767 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7768 | boolean hasFinePermission = |
| 7769 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7770 | boolean hasCoarsePermission = |
| 7771 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7772 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7773 | final Phone phone = getPhone(subId); |
| 7774 | if (phone == null) { |
| 7775 | return null; |
| 7776 | } |
| 7777 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7778 | final long identity = Binder.clearCallingIdentity(); |
| 7779 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7780 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7781 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7783 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7784 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7785 | Rlog.d(LOG_TAG, |
| 7786 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7787 | return null; |
| 7788 | } |
| 7789 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7790 | ServiceState ss = phone.getServiceState(); |
| 7791 | |
| 7792 | // Scrub out the location info in ServiceState depending on what level of access |
| 7793 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7794 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7795 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7796 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | } finally { |
| 7798 | Binder.restoreCallingIdentity(identity); |
| 7799 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7800 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7801 | |
| 7802 | /** |
| 7803 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7804 | * |
| 7805 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7806 | * voicemail ringtone. |
| 7807 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7808 | * PhoneAccount. |
| 7809 | */ |
| 7810 | @Override |
| 7811 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | final long identity = Binder.clearCallingIdentity(); |
| 7813 | try { |
| 7814 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7815 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7816 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7817 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7818 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(identity); |
| 7822 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7823 | } |
| 7824 | |
| 7825 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7826 | * Sets the per-account voicemail ringtone. |
| 7827 | * |
| 7828 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7829 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7830 | * |
| 7831 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7832 | * voicemail ringtone. |
| 7833 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7834 | * PhoneAccount. |
| 7835 | */ |
| 7836 | @Override |
| 7837 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7838 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7839 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7840 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7841 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7842 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7843 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7844 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7845 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7847 | |
| 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
| 7850 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7851 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7852 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7853 | } |
| 7854 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7855 | } finally { |
| 7856 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7857 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7858 | } |
| 7859 | |
| 7860 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7861 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7862 | * |
| 7863 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7864 | * voicemail vibration setting. |
| 7865 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7866 | */ |
| 7867 | @Override |
| 7868 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7869 | final long identity = Binder.clearCallingIdentity(); |
| 7870 | try { |
| 7871 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7872 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7873 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7874 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7875 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7877 | } finally { |
| 7878 | Binder.restoreCallingIdentity(identity); |
| 7879 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7880 | } |
| 7881 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7882 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7883 | * Sets the per-account voicemail vibration. |
| 7884 | * |
| 7885 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7886 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7887 | * |
| 7888 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7889 | * voicemail vibration setting. |
| 7890 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7891 | * specific PhoneAccount. |
| 7892 | */ |
| 7893 | @Override |
| 7894 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7895 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7896 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7897 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7898 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7899 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7901 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7902 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7903 | } |
| 7904 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
| 7907 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7908 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7909 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | } |
| 7911 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7914 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7915 | } |
| 7916 | |
| 7917 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7918 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7919 | * |
| 7920 | * @throws SecurityException if the caller does not have the required permission |
| 7921 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7922 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7923 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7924 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7925 | } |
| 7926 | |
| 7927 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7928 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7929 | * permission. |
| 7930 | * |
| 7931 | * @throws SecurityException if the caller does not have the required permission |
| 7932 | */ |
| 7933 | private void enforceSendSmsPermission() { |
| 7934 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7935 | } |
| 7936 | |
| 7937 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7938 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7939 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7940 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7941 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7942 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7943 | final long identity = Binder.clearCallingIdentity(); |
| 7944 | try { |
| 7945 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7946 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7947 | if (componentName == null) { |
| 7948 | throw new SecurityException( |
| 7949 | "Caller not current active visual voicemail package[null]"); |
| 7950 | } |
| 7951 | String vvmPackage = componentName.getPackageName(); |
| 7952 | if (!callingPackage.equals(vvmPackage)) { |
| 7953 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7954 | + vvmPackage + "]"); |
| 7955 | } |
| 7956 | } finally { |
| 7957 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7958 | } |
| 7959 | } |
| 7960 | |
| 7961 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7962 | * Return the application ID for the app type. |
| 7963 | * |
| 7964 | * @param subId the subscription ID that this request applies to. |
| 7965 | * @param appType the uicc app type. |
| 7966 | * @return Application ID for specificied app type, or null if no uicc. |
| 7967 | */ |
| 7968 | @Override |
| 7969 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7970 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7971 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7972 | |
| 7973 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7974 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | if (phone == null) { |
| 7976 | return null; |
| 7977 | } |
| 7978 | String aid = null; |
| 7979 | try { |
| 7980 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7981 | .getApplicationByType(appType).getAid(); |
| 7982 | } catch (Exception e) { |
| 7983 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7984 | } |
| 7985 | return aid; |
| 7986 | } finally { |
| 7987 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7988 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7989 | } |
| 7990 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7991 | /** |
| 7992 | * Return the Electronic Serial Number. |
| 7993 | * |
| 7994 | * @param subId the subscription ID that this request applies to. |
| 7995 | * @return ESN or null if error. |
| 7996 | */ |
| 7997 | @Override |
| 7998 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7999 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8000 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | |
| 8002 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8003 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8004 | if (phone == null) { |
| 8005 | return null; |
| 8006 | } |
| 8007 | String esn = null; |
| 8008 | try { |
| 8009 | esn = phone.getEsn(); |
| 8010 | } catch (Exception e) { |
| 8011 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8012 | } |
| 8013 | return esn; |
| 8014 | } finally { |
| 8015 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8016 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8017 | } |
| 8018 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8019 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8020 | * Return the Preferred Roaming List Version. |
| 8021 | * |
| 8022 | * @param subId the subscription ID that this request applies to. |
| 8023 | * @return PRLVersion or null if error. |
| 8024 | */ |
| 8025 | @Override |
| 8026 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8027 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8028 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8029 | |
| 8030 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8031 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | if (phone == null) { |
| 8033 | return null; |
| 8034 | } |
| 8035 | String cdmaPrlVersion = null; |
| 8036 | try { |
| 8037 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8038 | } catch (Exception e) { |
| 8039 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8040 | } |
| 8041 | return cdmaPrlVersion; |
| 8042 | } finally { |
| 8043 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8044 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8045 | } |
| 8046 | |
| 8047 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8048 | * Get snapshot of Telephony histograms |
| 8049 | * @return List of Telephony histograms |
| 8050 | * @hide |
| 8051 | */ |
| 8052 | @Override |
| 8053 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8055 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | |
| 8057 | final long identity = Binder.clearCallingIdentity(); |
| 8058 | try { |
| 8059 | return RIL.getTelephonyRILTimingHistograms(); |
| 8060 | } finally { |
| 8061 | Binder.restoreCallingIdentity(identity); |
| 8062 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8063 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8064 | |
| 8065 | /** |
| 8066 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8067 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8068 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8069 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8070 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8071 | * @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] | 8072 | */ |
| 8073 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8074 | @TelephonyManager.SetCarrierRestrictionResult |
| 8075 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8076 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8077 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8078 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8079 | if (carrierRestrictionRules == null) { |
| 8080 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8081 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | final long identity = Binder.clearCallingIdentity(); |
| 8084 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8085 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8086 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | } finally { |
| 8088 | Binder.restoreCallingIdentity(identity); |
| 8089 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8090 | } |
| 8091 | |
| 8092 | /** |
| 8093 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8094 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8095 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8096 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8097 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8098 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8099 | */ |
| 8100 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8101 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8102 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8103 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8104 | |
| 8105 | final long identity = Binder.clearCallingIdentity(); |
| 8106 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8107 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8108 | if (response instanceof CarrierRestrictionRules) { |
| 8109 | return (CarrierRestrictionRules) response; |
| 8110 | } |
| 8111 | // Response is an Exception of some kind, |
| 8112 | // which is signalled to the user as a NULL retval |
| 8113 | return null; |
| 8114 | } catch (Exception e) { |
| 8115 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8116 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8117 | } finally { |
| 8118 | Binder.restoreCallingIdentity(identity); |
| 8119 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8120 | } |
| 8121 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8122 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8123 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8124 | * @param subId the subscription ID that this action applies to. |
| 8125 | * @param enabled control enable or disable radio. |
| 8126 | * {@hide} |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8130 | enforceModifyPermission(); |
| 8131 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | |
| 8133 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8134 | if (phone == null) { |
| 8135 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8136 | return; |
| 8137 | } |
| 8138 | try { |
| 8139 | phone.carrierActionSetRadioEnabled(enabled); |
| 8140 | } catch (Exception e) { |
| 8141 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8144 | } |
| 8145 | } |
| 8146 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8147 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8148 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8149 | * network status based on which carrier apps could apply actions accordingly, |
| 8150 | * enable/disable default url handler for example. |
| 8151 | * |
| 8152 | * @param subId the subscription ID that this action applies to. |
| 8153 | * @param report control start/stop reporting the default network status. |
| 8154 | * {@hide} |
| 8155 | */ |
| 8156 | @Override |
| 8157 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8158 | enforceModifyPermission(); |
| 8159 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8160 | |
| 8161 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8162 | if (phone == null) { |
| 8163 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8164 | return; |
| 8165 | } |
| 8166 | try { |
| 8167 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8168 | } catch (Exception e) { |
| 8169 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8170 | } finally { |
| 8171 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8172 | } |
| 8173 | } |
| 8174 | |
| 8175 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8176 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8177 | * @param subId the subscription ID that this action applies to. |
| 8178 | * {@hide} |
| 8179 | */ |
| 8180 | @Override |
| 8181 | public void carrierActionResetAll(int subId) { |
| 8182 | enforceModifyPermission(); |
| 8183 | final Phone phone = getPhone(subId); |
| 8184 | if (phone == null) { |
| 8185 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8186 | return; |
| 8187 | } |
| 8188 | try { |
| 8189 | phone.carrierActionResetAll(); |
| 8190 | } catch (Exception e) { |
| 8191 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8192 | } |
| 8193 | } |
| 8194 | |
| 8195 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8196 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8197 | * bug report is being generated. |
| 8198 | */ |
| 8199 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8200 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8201 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8202 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8203 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8204 | + Binder.getCallingPid() |
| 8205 | + ", uid=" + Binder.getCallingUid() |
| 8206 | + "without permission " |
| 8207 | + android.Manifest.permission.DUMP); |
| 8208 | return; |
| 8209 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8210 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8211 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8212 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8213 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8214 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8215 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8216 | @NonNull String[] args) { |
| 8217 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8218 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8219 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8220 | } |
| 8221 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8222 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8223 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8224 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8225 | * @param reason the reason the data enable change is taking place |
| 8226 | * @param enabled True if enabling the data, otherwise disabling. |
| 8227 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8228 | */ |
| 8229 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8230 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8231 | boolean enabled) { |
| 8232 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8233 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8234 | try { |
| 8235 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8236 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8237 | } catch (SecurityException se) { |
| 8238 | enforceModifyPermission(); |
| 8239 | } |
| 8240 | } else { |
| 8241 | enforceModifyPermission(); |
| 8242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | |
| 8244 | final long identity = Binder.clearCallingIdentity(); |
| 8245 | try { |
| 8246 | Phone phone = getPhone(subId); |
| 8247 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8248 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8249 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8250 | } else { |
| 8251 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8252 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8253 | } |
| 8254 | } finally { |
| 8255 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8256 | } |
| 8257 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8258 | |
| 8259 | /** |
| 8260 | * Get Client request stats |
| 8261 | * @return List of Client Request Stats |
| 8262 | * @hide |
| 8263 | */ |
| 8264 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8265 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8266 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8267 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8268 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8269 | return null; |
| 8270 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8271 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8272 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
| 8275 | if (phone != null) { |
| 8276 | return phone.getClientRequestStats(); |
| 8277 | } |
| 8278 | |
| 8279 | return null; |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
| 8282 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8283 | } |
| 8284 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8285 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8286 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8287 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8288 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8289 | |
| 8290 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8291 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8292 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8293 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8294 | * @param state State of SIM (power down, power up, pass through) |
| 8295 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8296 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8297 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8298 | * |
| 8299 | **/ |
| 8300 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8301 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8302 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8303 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8304 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8305 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8307 | final long identity = Binder.clearCallingIdentity(); |
| 8308 | try { |
| 8309 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8310 | phone.setSimPowerState(state, null, workSource); |
| 8311 | } |
| 8312 | } finally { |
| 8313 | Binder.restoreCallingIdentity(identity); |
| 8314 | } |
| 8315 | } |
| 8316 | |
| 8317 | /** |
| 8318 | * Set SIM card power state. |
| 8319 | * |
| 8320 | * @param slotIndex SIM slot id. |
| 8321 | * @param state State of SIM (power down, power up, pass through) |
| 8322 | * @param callback callback to trigger after success or failure |
| 8323 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8324 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8325 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8326 | * |
| 8327 | **/ |
| 8328 | @Override |
| 8329 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8330 | IIntegerConsumer callback) { |
| 8331 | enforceModifyPermission(); |
| 8332 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8333 | |
| 8334 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8335 | |
| 8336 | final long identity = Binder.clearCallingIdentity(); |
| 8337 | try { |
| 8338 | if (phone != null) { |
| 8339 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8340 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | } |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8344 | } |
| 8345 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8346 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8347 | private boolean isUssdApiAllowed(int subId) { |
| 8348 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8349 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8350 | if (configManager == null) { |
| 8351 | return false; |
| 8352 | } |
| 8353 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8354 | if (pb == null) { |
| 8355 | return false; |
| 8356 | } |
| 8357 | return pb.getBoolean( |
| 8358 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8359 | } |
| 8360 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8361 | /** |
| 8362 | * Check if phone is in emergency callback mode |
| 8363 | * @return true if phone is in emergency callback mode |
| 8364 | * @param subId sub id |
| 8365 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8366 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8367 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8368 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8369 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8370 | |
| 8371 | final long identity = Binder.clearCallingIdentity(); |
| 8372 | try { |
| 8373 | if (phone != null) { |
| 8374 | return phone.isInEcm(); |
| 8375 | } else { |
| 8376 | return false; |
| 8377 | } |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8380 | } |
| 8381 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8382 | |
| 8383 | /** |
| 8384 | * Get the current signal strength information for the given subscription. |
| 8385 | * Because this information is not updated when the device is in a low power state |
| 8386 | * it should not be relied-upon to be current. |
| 8387 | * @param subId Subscription index |
| 8388 | * @return the most recent cached signal strength info from the modem |
| 8389 | */ |
| 8390 | @Override |
| 8391 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | final long identity = Binder.clearCallingIdentity(); |
| 8393 | try { |
| 8394 | Phone p = getPhone(subId); |
| 8395 | if (p == null) { |
| 8396 | return null; |
| 8397 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8398 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8399 | return p.getSignalStrength(); |
| 8400 | } finally { |
| 8401 | Binder.restoreCallingIdentity(identity); |
| 8402 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8403 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8404 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8405 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8406 | * Get the current modem radio state for the given slot. |
| 8407 | * @param slotIndex slot index. |
| 8408 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8409 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8410 | * @return the current radio power state from the modem |
| 8411 | */ |
| 8412 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8413 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8414 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8415 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8417 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8418 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8419 | } |
| 8420 | |
| 8421 | final long identity = Binder.clearCallingIdentity(); |
| 8422 | try { |
| 8423 | return phone.getRadioPowerState(); |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
| 8426 | } |
| 8427 | } |
| 8428 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8429 | } |
| 8430 | |
| 8431 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8432 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8433 | * |
| 8434 | * <p>Requires one of the following permissions: |
| 8435 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8436 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8437 | * privileges. |
| 8438 | * |
| 8439 | * @param subId subscription id |
| 8440 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8441 | * {@code false}. |
| 8442 | */ |
| 8443 | @Override |
| 8444 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8445 | try { |
| 8446 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8447 | null); |
| 8448 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8449 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8450 | mApp, subId, "isDataRoamingEnabled"); |
| 8451 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8452 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8453 | boolean isEnabled = false; |
| 8454 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8455 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8456 | Phone phone = getPhone(subId); |
| 8457 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8458 | } finally { |
| 8459 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8460 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8461 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | |
| 8465 | /** |
| 8466 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8467 | * |
| 8468 | * <p> Requires permission: |
| 8469 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8470 | * privileges. |
| 8471 | * |
| 8472 | * @param subId subscription id |
| 8473 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8474 | */ |
| 8475 | @Override |
| 8476 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8477 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8478 | mApp, subId, "setDataRoamingEnabled"); |
| 8479 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8480 | final long identity = Binder.clearCallingIdentity(); |
| 8481 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8482 | Phone phone = getPhone(subId); |
| 8483 | if (phone != null) { |
| 8484 | phone.setDataRoamingEnabled(isEnabled); |
| 8485 | } |
| 8486 | } finally { |
| 8487 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8488 | } |
| 8489 | } |
| 8490 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8491 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8492 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8493 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8494 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8495 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8496 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8497 | boolean isAllowed = true; |
| 8498 | final long identity = Binder.clearCallingIdentity(); |
| 8499 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8500 | Phone phone = getPhone(subId); |
| 8501 | if (phone != null) { |
| 8502 | isAllowed = phone.isCspPlmnEnabled(); |
| 8503 | } |
| 8504 | } finally { |
| 8505 | Binder.restoreCallingIdentity(identity); |
| 8506 | } |
| 8507 | return isAllowed; |
| 8508 | } |
| 8509 | |
| 8510 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8511 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8512 | // Verify that tha callingPackage belongs to the calling UID |
| 8513 | mApp.getSystemService(AppOpsManager.class) |
| 8514 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8515 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8516 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8517 | try { |
| 8518 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8519 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8520 | } catch (SecurityException e) { |
| 8521 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8522 | // has carrier privileges on an active UICC |
| 8523 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8524 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8525 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8526 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8527 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8528 | |
| 8529 | final long identity = Binder.clearCallingIdentity(); |
| 8530 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8531 | UiccController uiccController = UiccController.getInstance(); |
| 8532 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8533 | if (hasReadPermission) { |
| 8534 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8535 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8536 | |
| 8537 | // Remove private info if the caller doesn't have access |
| 8538 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8539 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8540 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8541 | // is available |
| 8542 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8543 | if (card == null || card.getUiccProfile() == null) { |
| 8544 | // assume no access if the card or profile is unavailable |
| 8545 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8546 | continue; |
| 8547 | } |
| 8548 | UiccProfile profile = card.getUiccProfile(); |
| 8549 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8550 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8551 | filteredInfos.add(cardInfo); |
| 8552 | } else { |
| 8553 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8554 | } |
| 8555 | } |
| 8556 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8563 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8564 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8565 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8569 | if (slots == null) { |
| 8570 | Rlog.i(LOG_TAG, "slots is null."); |
| 8571 | return null; |
| 8572 | } |
| 8573 | |
| 8574 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8575 | for (int i = 0; i < slots.length; i++) { |
| 8576 | UiccSlot slot = slots[i]; |
| 8577 | if (slot == null) { |
| 8578 | continue; |
| 8579 | } |
| 8580 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8581 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8582 | UiccCard card = slot.getUiccCard(); |
| 8583 | if (card != null) { |
| 8584 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8585 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8586 | cardId = slot.getEid(); |
| 8587 | if (TextUtils.isEmpty(cardId)) { |
| 8588 | cardId = slot.getIccId(); |
| 8589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8590 | } |
| 8591 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8592 | if (cardId != null) { |
| 8593 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8594 | // if cardId is an EID, it's all digits so this is fine |
| 8595 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8596 | } |
| 8597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | int cardState = 0; |
| 8599 | switch (slot.getCardState()) { |
| 8600 | case CARDSTATE_ABSENT: |
| 8601 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8602 | break; |
| 8603 | case CARDSTATE_PRESENT: |
| 8604 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8605 | break; |
| 8606 | case CARDSTATE_ERROR: |
| 8607 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8608 | break; |
| 8609 | case CARDSTATE_RESTRICTED: |
| 8610 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8611 | break; |
| 8612 | default: |
| 8613 | break; |
| 8614 | |
| 8615 | } |
| 8616 | |
| 8617 | infos[i] = new UiccSlotInfo( |
| 8618 | slot.isActive(), |
| 8619 | slot.isEuicc(), |
| 8620 | cardId, |
| 8621 | cardState, |
| 8622 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8623 | slot.isExtendedApduSupported(), |
| 8624 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8625 | } |
| 8626 | return infos; |
| 8627 | } finally { |
| 8628 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8629 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8630 | } |
| 8631 | |
| 8632 | @Override |
| 8633 | public boolean switchSlots(int[] physicalSlots) { |
| 8634 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8635 | |
| 8636 | final long identity = Binder.clearCallingIdentity(); |
| 8637 | try { |
| 8638 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
| 8641 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8642 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8643 | |
| 8644 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8645 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8646 | final long identity = Binder.clearCallingIdentity(); |
| 8647 | try { |
| 8648 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8649 | } finally { |
| 8650 | Binder.restoreCallingIdentity(identity); |
| 8651 | } |
| 8652 | } |
| 8653 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8654 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8655 | * A test API to reload the UICC profile. |
| 8656 | * |
| 8657 | * <p>Requires that the calling app has permission |
| 8658 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8659 | * @hide |
| 8660 | */ |
| 8661 | @Override |
| 8662 | public void refreshUiccProfile(int subId) { |
| 8663 | enforceModifyPermission(); |
| 8664 | |
| 8665 | final long identity = Binder.clearCallingIdentity(); |
| 8666 | try { |
| 8667 | Phone phone = getPhone(subId); |
| 8668 | if (phone == null) { |
| 8669 | return; |
| 8670 | } |
| 8671 | UiccCard uiccCard = phone.getUiccCard(); |
| 8672 | if (uiccCard == null) { |
| 8673 | return; |
| 8674 | } |
| 8675 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8676 | if (uiccProfile == null) { |
| 8677 | return; |
| 8678 | } |
| 8679 | uiccProfile.refresh(); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8686 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8687 | */ |
| 8688 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8689 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8690 | } |
| 8691 | |
| 8692 | /** |
| 8693 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8694 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8695 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8696 | */ |
| 8697 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8698 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8699 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8700 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8701 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8702 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8703 | return isDataRoamingEnabled; |
| 8704 | } |
| 8705 | |
| 8706 | /** |
| 8707 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8708 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8709 | */ |
| 8710 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8711 | List<Integer> list = TelephonyProperties.default_network(); |
| 8712 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8713 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8714 | return list.get(phoneId); |
| 8715 | } |
| 8716 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8717 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8718 | |
| 8719 | @Override |
| 8720 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8721 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8722 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8723 | |
| 8724 | final long identity = Binder.clearCallingIdentity(); |
| 8725 | try { |
| 8726 | final Phone phone = getPhone(subId); |
| 8727 | if (phone == null) { |
| 8728 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8729 | return; |
| 8730 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8731 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8732 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8733 | if (carrierPrivilegeRules == null) { |
| 8734 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8735 | } else { |
| 8736 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8737 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8738 | } finally { |
| 8739 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8740 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8741 | } |
| 8742 | |
| 8743 | @Override |
| 8744 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8745 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8746 | |
| 8747 | final long identity = Binder.clearCallingIdentity(); |
| 8748 | try { |
| 8749 | final Phone phone = getPhone(subId); |
| 8750 | if (phone == null) { |
| 8751 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8752 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8753 | } |
| 8754 | return phone.getCarrierIdListVersion(); |
| 8755 | } finally { |
| 8756 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8757 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8758 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8759 | |
| 8760 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8761 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8762 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8764 | mApp, subId, callingPackage, callingFeatureId, |
| 8765 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8766 | return -1; |
| 8767 | } |
| 8768 | |
| 8769 | final long identity = Binder.clearCallingIdentity(); |
| 8770 | try { |
| 8771 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
| 8775 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8776 | |
| 8777 | @Override |
| 8778 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8779 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8780 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8781 | mApp, subId, "getCdmaRoamingMode"); |
| 8782 | |
| 8783 | final long identity = Binder.clearCallingIdentity(); |
| 8784 | try { |
| 8785 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8786 | } finally { |
| 8787 | Binder.restoreCallingIdentity(identity); |
| 8788 | } |
| 8789 | } |
| 8790 | |
| 8791 | @Override |
| 8792 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8793 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8794 | mApp, subId, "setCdmaRoamingMode"); |
| 8795 | |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8799 | } finally { |
| 8800 | Binder.restoreCallingIdentity(identity); |
| 8801 | } |
| 8802 | } |
| 8803 | |
| 8804 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8805 | public int getCdmaSubscriptionMode(int subId) { |
| 8806 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8807 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8808 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8809 | |
| 8810 | final long identity = Binder.clearCallingIdentity(); |
| 8811 | try { |
| 8812 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8813 | } finally { |
| 8814 | Binder.restoreCallingIdentity(identity); |
| 8815 | } |
| 8816 | } |
| 8817 | |
| 8818 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8819 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8821 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8822 | |
| 8823 | final long identity = Binder.clearCallingIdentity(); |
| 8824 | try { |
| 8825 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8826 | } finally { |
| 8827 | Binder.restoreCallingIdentity(identity); |
| 8828 | } |
| 8829 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8830 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8831 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8832 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8833 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8835 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8836 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8837 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8838 | } |
| 8839 | final long identity = Binder.clearCallingIdentity(); |
| 8840 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8841 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8842 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8843 | if (phone.getEmergencyNumberTracker() != null |
| 8844 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8845 | emergencyNumberListInternal.put( |
| 8846 | phone.getSubId(), |
| 8847 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8848 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8849 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8850 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8851 | } finally { |
| 8852 | Binder.restoreCallingIdentity(identity); |
| 8853 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8854 | } |
| 8855 | |
| 8856 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8857 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8858 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8859 | if (!exactMatch) { |
| 8860 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8861 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8862 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8863 | } |
| 8864 | final long identity = Binder.clearCallingIdentity(); |
| 8865 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8866 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8867 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8868 | && phone.getEmergencyNumberTracker() |
| 8869 | .isEmergencyNumber(number, exactMatch)) { |
| 8870 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8871 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8872 | } |
| 8873 | return false; |
| 8874 | } finally { |
| 8875 | Binder.restoreCallingIdentity(identity); |
| 8876 | } |
| 8877 | } |
| 8878 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8879 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8880 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8881 | */ |
| 8882 | @Override |
| 8883 | public void startEmergencyCallbackMode() { |
| 8884 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8885 | "startEmergencyCallbackMode"); |
| 8886 | enforceModifyPermission(); |
| 8887 | final long identity = Binder.clearCallingIdentity(); |
| 8888 | try { |
| 8889 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8890 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8891 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8892 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8893 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8894 | gsmCdmaPhone.obtainMessage( |
| 8895 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8896 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8897 | } |
| 8898 | } |
| 8899 | } finally { |
| 8900 | Binder.restoreCallingIdentity(identity); |
| 8901 | } |
| 8902 | } |
| 8903 | |
| 8904 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8905 | * Update emergency number list for test mode. |
| 8906 | */ |
| 8907 | @Override |
| 8908 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8909 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8910 | "updateEmergencyNumberListTestMode"); |
| 8911 | |
| 8912 | final long identity = Binder.clearCallingIdentity(); |
| 8913 | try { |
| 8914 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8915 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8916 | if (tracker != null) { |
| 8917 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8918 | } |
| 8919 | } |
| 8920 | } finally { |
| 8921 | Binder.restoreCallingIdentity(identity); |
| 8922 | } |
| 8923 | } |
| 8924 | |
| 8925 | /** |
| 8926 | * Get the full emergency number list for test mode. |
| 8927 | */ |
| 8928 | @Override |
| 8929 | public List<String> getEmergencyNumberListTestMode() { |
| 8930 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8931 | "getEmergencyNumberListTestMode"); |
| 8932 | |
| 8933 | final long identity = Binder.clearCallingIdentity(); |
| 8934 | try { |
| 8935 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8936 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8937 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8938 | if (tracker != null) { |
| 8939 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8940 | emergencyNumbers.add(num.getNumber()); |
| 8941 | } |
| 8942 | } |
| 8943 | } |
| 8944 | return new ArrayList<>(emergencyNumbers); |
| 8945 | } finally { |
| 8946 | Binder.restoreCallingIdentity(identity); |
| 8947 | } |
| 8948 | } |
| 8949 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8950 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8951 | public int getEmergencyNumberDbVersion(int subId) { |
| 8952 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8953 | |
| 8954 | final long identity = Binder.clearCallingIdentity(); |
| 8955 | try { |
| 8956 | final Phone phone = getPhone(subId); |
| 8957 | if (phone == null) { |
| 8958 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8959 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8960 | } |
| 8961 | return phone.getEmergencyNumberDbVersion(); |
| 8962 | } finally { |
| 8963 | Binder.restoreCallingIdentity(identity); |
| 8964 | } |
| 8965 | } |
| 8966 | |
| 8967 | @Override |
| 8968 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8969 | enforceModifyPermission(); |
| 8970 | |
| 8971 | final long identity = Binder.clearCallingIdentity(); |
| 8972 | try { |
| 8973 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8974 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8975 | if (tracker != null) { |
| 8976 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8977 | } |
| 8978 | } |
| 8979 | } finally { |
| 8980 | Binder.restoreCallingIdentity(identity); |
| 8981 | } |
| 8982 | } |
| 8983 | |
| 8984 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8985 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8986 | enforceActiveEmergencySessionPermission(); |
| 8987 | |
| 8988 | final long identity = Binder.clearCallingIdentity(); |
| 8989 | try { |
| 8990 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8991 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8992 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8993 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8994 | } |
| 8995 | } |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
| 8998 | } |
| 8999 | } |
| 9000 | |
| 9001 | @Override |
| 9002 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9003 | enforceActiveEmergencySessionPermission(); |
| 9004 | |
| 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
| 9007 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9008 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9009 | if (tracker != null) { |
| 9010 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9011 | } |
| 9012 | } |
| 9013 | } finally { |
| 9014 | Binder.restoreCallingIdentity(identity); |
| 9015 | } |
| 9016 | } |
| 9017 | |
| 9018 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9019 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9020 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9021 | Phone phone = getPhone(subId); |
| 9022 | if (phone == null) { |
| 9023 | return null; |
| 9024 | } |
| 9025 | final long identity = Binder.clearCallingIdentity(); |
| 9026 | try { |
| 9027 | UiccProfile profile = UiccController.getInstance() |
| 9028 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9029 | if (profile != null) { |
| 9030 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9031 | } |
| 9032 | } finally { |
| 9033 | Binder.restoreCallingIdentity(identity); |
| 9034 | } |
| 9035 | return null; |
| 9036 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9037 | |
| 9038 | /** |
| 9039 | * Enable or disable a modem stack. |
| 9040 | */ |
| 9041 | @Override |
| 9042 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9043 | enforceModifyPermission(); |
| 9044 | |
| 9045 | final long identity = Binder.clearCallingIdentity(); |
| 9046 | try { |
| 9047 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9048 | if (phone == null) { |
| 9049 | return false; |
| 9050 | } else { |
| 9051 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9052 | } |
| 9053 | } finally { |
| 9054 | Binder.restoreCallingIdentity(identity); |
| 9055 | } |
| 9056 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9057 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9058 | /** |
| 9059 | * Whether a modem stack is enabled or not. |
| 9060 | */ |
| 9061 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9062 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9063 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9064 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9065 | if (phone == null) return false; |
| 9066 | |
| 9067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9068 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9069 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9070 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9071 | } |
| 9072 | |
| 9073 | final long identity = Binder.clearCallingIdentity(); |
| 9074 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9075 | try { |
| 9076 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9077 | } catch (NoSuchElementException ex) { |
| 9078 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9079 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9080 | } finally { |
| 9081 | Binder.restoreCallingIdentity(identity); |
| 9082 | } |
| 9083 | } |
| 9084 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9085 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9086 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9087 | enforceModifyPermission(); |
| 9088 | |
| 9089 | final long identity = Binder.clearCallingIdentity(); |
| 9090 | try { |
| 9091 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9092 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9093 | .commit(); |
| 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
| 9096 | } |
| 9097 | } |
| 9098 | |
| 9099 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9100 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9101 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9102 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9103 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9104 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9105 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9106 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9107 | |
| 9108 | final long identity = Binder.clearCallingIdentity(); |
| 9109 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9110 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9111 | } finally { |
| 9112 | Binder.restoreCallingIdentity(identity); |
| 9113 | } |
| 9114 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9115 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9116 | @TelephonyManager.IsMultiSimSupportedResult |
| 9117 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9118 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9119 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9120 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9121 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9122 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9123 | } |
| 9124 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9125 | // supported by the modem, indicate that it is restricted. |
| 9126 | PhoneCapability staticCapability = |
| 9127 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9128 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9129 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9130 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9131 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9132 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9133 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9134 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9135 | } |
| 9136 | // Check if support of multiple SIMs is restricted by carrier |
| 9137 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9138 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9139 | } |
| 9140 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9141 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9142 | } |
| 9143 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9144 | /** |
| 9145 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9146 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9147 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9148 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9149 | * @param numOfSims number of active sims we want to switch to |
| 9150 | */ |
| 9151 | @Override |
| 9152 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9153 | if (numOfSims == 1) { |
| 9154 | enforceModifyPermission(); |
| 9155 | } else { |
| 9156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9157 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9158 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9159 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9160 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9161 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9162 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9163 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9164 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9165 | return; |
| 9166 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9167 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9168 | } finally { |
| 9169 | Binder.restoreCallingIdentity(identity); |
| 9170 | } |
| 9171 | } |
| 9172 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9173 | @Override |
| 9174 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9175 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9176 | Phone phone = getPhone(subId); |
| 9177 | if (phone == null) { |
| 9178 | return false; |
| 9179 | } |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
| 9182 | UiccCard uiccCard = phone.getUiccCard(); |
| 9183 | if (uiccCard == null) { |
| 9184 | return false; |
| 9185 | } |
| 9186 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9187 | if (uiccProfile == null) { |
| 9188 | return false; |
| 9189 | } |
| 9190 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9191 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9192 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9193 | } |
| 9194 | return false; |
| 9195 | } finally { |
| 9196 | Binder.restoreCallingIdentity(identity); |
| 9197 | } |
| 9198 | } |
| 9199 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9200 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9201 | * Get whether making changes to modem configurations will trigger reboot. |
| 9202 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9203 | */ |
| 9204 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9205 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9206 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9207 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9208 | mApp, subId, callingPackage, callingFeatureId, |
| 9209 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9210 | return false; |
| 9211 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9212 | final long identity = Binder.clearCallingIdentity(); |
| 9213 | try { |
| 9214 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9215 | } finally { |
| 9216 | Binder.restoreCallingIdentity(identity); |
| 9217 | } |
| 9218 | } |
| 9219 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9220 | private void updateModemStateMetrics() { |
| 9221 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9222 | // TODO: check the state for each modem if the api is ready. |
| 9223 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9224 | } |
| 9225 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9226 | @Override |
| 9227 | public int[] getSlotsMapping() { |
| 9228 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9229 | |
| 9230 | final long identity = Binder.clearCallingIdentity(); |
| 9231 | try { |
| 9232 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9233 | // All logical slots should have a mapping to a physical slot. |
| 9234 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9235 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9236 | for (int i = 0; i < slotInfos.length; i++) { |
| 9237 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9238 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9239 | } |
| 9240 | } |
| 9241 | return logicalSlotsMapping; |
| 9242 | } finally { |
| 9243 | Binder.restoreCallingIdentity(identity); |
| 9244 | } |
| 9245 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9246 | |
| 9247 | /** |
| 9248 | * Get the IRadio HAL Version |
| 9249 | */ |
| 9250 | @Override |
| 9251 | public int getRadioHalVersion() { |
| 9252 | Phone phone = getDefaultPhone(); |
| 9253 | if (phone == null) return -1; |
| 9254 | HalVersion hv = phone.getHalVersion(); |
| 9255 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9256 | return hv.major * 100 + hv.minor; |
| 9257 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9258 | |
| 9259 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9260 | * Get the current calling package name. |
| 9261 | * @return the current calling package name |
| 9262 | */ |
| 9263 | @Override |
| 9264 | public String getCurrentPackageName() { |
| 9265 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9266 | } |
| 9267 | |
| 9268 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9269 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9270 | * corresponding network requests on a subId. |
| 9271 | * |
| 9272 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9273 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9274 | * 2) APN is un-metered for this subscription, or |
| 9275 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9276 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9277 | * |
| 9278 | * @return whether data is allowed for a apn type. |
| 9279 | * |
| 9280 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9281 | */ |
| 9282 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9283 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9284 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9285 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9286 | |
| 9287 | // Now that all security checks passes, perform the operation as ourselves. |
| 9288 | final long identity = Binder.clearCallingIdentity(); |
| 9289 | try { |
| 9290 | Phone phone = getPhone(subId); |
| 9291 | if (phone == null) return false; |
| 9292 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9293 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9294 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9295 | } finally { |
| 9296 | Binder.restoreCallingIdentity(identity); |
| 9297 | } |
| 9298 | } |
| 9299 | |
| 9300 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9301 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9302 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9303 | |
| 9304 | // Now that all security checks passes, perform the operation as ourselves. |
| 9305 | final long identity = Binder.clearCallingIdentity(); |
| 9306 | try { |
| 9307 | Phone phone = getPhone(subId); |
| 9308 | if (phone == null) return true; // By default return true. |
| 9309 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9310 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9311 | } finally { |
| 9312 | Binder.restoreCallingIdentity(identity); |
| 9313 | } |
| 9314 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9315 | |
| 9316 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9317 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9318 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9319 | enforceModifyPermission(); |
| 9320 | long token = Binder.clearCallingIdentity(); |
| 9321 | try { |
| 9322 | Phone phone = getPhone(subscriptionId); |
| 9323 | if (phone == null) { |
| 9324 | try { |
| 9325 | if (resultCallback != null) { |
| 9326 | resultCallback.accept(false); |
| 9327 | } |
| 9328 | } catch (RemoteException e) { |
| 9329 | // ignore |
| 9330 | } |
| 9331 | return; |
| 9332 | } |
| 9333 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9334 | Pair.create(specifiers, (x) -> { |
| 9335 | try { |
| 9336 | if (resultCallback != null) { |
| 9337 | resultCallback.accept(x); |
| 9338 | } |
| 9339 | } catch (RemoteException e) { |
| 9340 | // ignore |
| 9341 | } |
| 9342 | }); |
| 9343 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9344 | } finally { |
| 9345 | Binder.restoreCallingIdentity(token); |
| 9346 | } |
| 9347 | } |
| 9348 | |
| 9349 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9350 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9351 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9352 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9353 | mApp, subId, "getSystemSelectionChannels"); |
| 9354 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9355 | final long identity = Binder.clearCallingIdentity(); |
| 9356 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9357 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9358 | if (result instanceof IllegalStateException) { |
| 9359 | throw (IllegalStateException) result; |
| 9360 | } |
| 9361 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9362 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9363 | return specifiers; |
| 9364 | } finally { |
| 9365 | Binder.restoreCallingIdentity(identity); |
| 9366 | } |
| 9367 | } |
| 9368 | |
| 9369 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9370 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9371 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9372 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9373 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9374 | if (iccRecords == null) { |
| 9375 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9376 | return false; |
| 9377 | } |
| 9378 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9379 | } |
| 9380 | |
| 9381 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9382 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9383 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9384 | if (callingPackage == null) { |
| 9385 | callingPackage = getCurrentPackageName(); |
| 9386 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9387 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9388 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9389 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9390 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9391 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9392 | } |
| 9393 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9394 | Intent intent = new Intent(); |
| 9395 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9396 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9397 | // Bring up choose default SMS subscription dialog right now |
| 9398 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9399 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9400 | mApp.startActivity(intent); |
| 9401 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9402 | |
| 9403 | @Override |
| 9404 | public String getMmsUAProfUrl(int subId) { |
| 9405 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9406 | final long identity = Binder.clearCallingIdentity(); |
| 9407 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9408 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9409 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9410 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9411 | return carrierUAProfUrl; |
| 9412 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9413 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9414 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9415 | } finally { |
| 9416 | Binder.restoreCallingIdentity(identity); |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | @Override |
| 9421 | public String getMmsUserAgent(int subId) { |
| 9422 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9423 | final long identity = Binder.clearCallingIdentity(); |
| 9424 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9425 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9426 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9427 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9428 | return carrierUserAgent; |
| 9429 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9430 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9431 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9432 | } finally { |
| 9433 | Binder.restoreCallingIdentity(identity); |
| 9434 | } |
| 9435 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9436 | |
| 9437 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9438 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9439 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9440 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9441 | final long identity = Binder.clearCallingIdentity(); |
| 9442 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9443 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9444 | if (phone == null) return false; |
| 9445 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9446 | switch (policy) { |
| 9447 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9448 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9449 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9450 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9451 | default: |
| 9452 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9453 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9454 | } finally { |
| 9455 | Binder.restoreCallingIdentity(identity); |
| 9456 | } |
| 9457 | } |
| 9458 | |
| 9459 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9460 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9461 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9462 | enforceModifyPermission(); |
| 9463 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9464 | final long identity = Binder.clearCallingIdentity(); |
| 9465 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9466 | Phone phone = getPhone(subscriptionId); |
| 9467 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9468 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9469 | switch (policy) { |
| 9470 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9471 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9472 | break; |
| 9473 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9474 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9475 | break; |
| 9476 | default: |
| 9477 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9478 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9479 | } finally { |
| 9480 | Binder.restoreCallingIdentity(identity); |
| 9481 | } |
| 9482 | } |
| 9483 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9484 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9485 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9486 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9487 | * otherwise. |
| 9488 | */ |
| 9489 | @Override |
| 9490 | public void setCepEnabled(boolean isCepEnabled) { |
| 9491 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9492 | |
| 9493 | final long identity = Binder.clearCallingIdentity(); |
| 9494 | try { |
| 9495 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9496 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9497 | Phone defaultPhone = phone.getImsPhone(); |
| 9498 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9499 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9500 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9501 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9502 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9503 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9504 | + imsPhone.getMsisdn()); |
| 9505 | } |
| 9506 | } |
| 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
| 9510 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9511 | |
| 9512 | /** |
| 9513 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9514 | * |
| 9515 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9516 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9517 | * before being read. |
| 9518 | */ |
| 9519 | @Override |
| 9520 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9521 | isCompressed) { |
| 9522 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9523 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9524 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9525 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9526 | } |
| 9527 | if (!isImsAvailableOnDevice()) { |
| 9528 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9529 | "IMS not available on device."); |
| 9530 | } |
| 9531 | |
| 9532 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9533 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9534 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9535 | } finally { |
| 9536 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9537 | } |
| 9538 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9539 | |
| 9540 | @Override |
| 9541 | public boolean isIccLockEnabled(int subId) { |
| 9542 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9543 | |
| 9544 | // Now that all security checks passes, perform the operation as ourselves. |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | Phone phone = getPhone(subId); |
| 9548 | if (phone != null && phone.getIccCard() != null) { |
| 9549 | return phone.getIccCard().getIccLockEnabled(); |
| 9550 | } else { |
| 9551 | return false; |
| 9552 | } |
| 9553 | } finally { |
| 9554 | Binder.restoreCallingIdentity(identity); |
| 9555 | } |
| 9556 | } |
| 9557 | |
| 9558 | /** |
| 9559 | * Set the ICC pin lock enabled or disabled. |
| 9560 | * |
| 9561 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9562 | * three cases: |
| 9563 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9564 | * successfully. |
| 9565 | * - Positive number and zero for remaining password attempts. |
| 9566 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9567 | * |
| 9568 | */ |
| 9569 | @Override |
| 9570 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9571 | enforceModifyPermission(); |
| 9572 | |
| 9573 | Phone phone = getPhone(subId); |
| 9574 | if (phone == null) { |
| 9575 | return 0; |
| 9576 | } |
| 9577 | // Now that all security checks passes, perform the operation as ourselves. |
| 9578 | final long identity = Binder.clearCallingIdentity(); |
| 9579 | try { |
| 9580 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9581 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9582 | return attemptsRemaining; |
| 9583 | |
| 9584 | } catch (Exception e) { |
| 9585 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9586 | } finally { |
| 9587 | Binder.restoreCallingIdentity(identity); |
| 9588 | } |
| 9589 | return 0; |
| 9590 | } |
| 9591 | |
| 9592 | /** |
| 9593 | * Change the ICC password used in ICC pin lock. |
| 9594 | * |
| 9595 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9596 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9597 | * - Positive number and zero for remaining password attempts. |
| 9598 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9599 | * |
| 9600 | */ |
| 9601 | @Override |
| 9602 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9603 | enforceModifyPermission(); |
| 9604 | |
| 9605 | Phone phone = getPhone(subId); |
| 9606 | if (phone == null) { |
| 9607 | return 0; |
| 9608 | } |
| 9609 | // Now that all security checks passes, perform the operation as ourselves. |
| 9610 | final long identity = Binder.clearCallingIdentity(); |
| 9611 | try { |
| 9612 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9613 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9614 | return attemptsRemaining; |
| 9615 | |
| 9616 | } catch (Exception e) { |
| 9617 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9618 | } finally { |
| 9619 | Binder.restoreCallingIdentity(identity); |
| 9620 | } |
| 9621 | return 0; |
| 9622 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9623 | |
| 9624 | /** |
| 9625 | * Request for receiving user activity notification |
| 9626 | */ |
| 9627 | @Override |
| 9628 | public void requestUserActivityNotification() { |
| 9629 | if (!mNotifyUserActivity.get() |
| 9630 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9631 | mNotifyUserActivity.set(true); |
| 9632 | } |
| 9633 | } |
| 9634 | |
| 9635 | /** |
| 9636 | * Called when userActivity is signalled in the power manager. |
| 9637 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9638 | */ |
| 9639 | @Override |
| 9640 | public void userActivity() { |
| 9641 | // *************************************** |
| 9642 | // * Inherited from PhoneWindowManager * |
| 9643 | // *************************************** |
| 9644 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9645 | // WITH ITS LOCKS HELD. |
| 9646 | // |
| 9647 | // This code must be VERY careful about the locks |
| 9648 | // it acquires. |
| 9649 | // In fact, the current code acquires way too many, |
| 9650 | // and probably has lurking deadlocks. |
| 9651 | |
| 9652 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9653 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9654 | } |
| 9655 | |
| 9656 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9657 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9658 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9659 | } |
| 9660 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9661 | |
| 9662 | @Override |
| 9663 | public boolean canConnectTo5GInDsdsMode() { |
| 9664 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9665 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9666 | |
| 9667 | @Override |
| 9668 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9669 | String callingFeatureId) { |
| 9670 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9671 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9672 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9673 | } |
| 9674 | |
| 9675 | Phone phone = getPhone(subId); |
| 9676 | if (phone == null) { |
| 9677 | throw new RuntimeException("phone is not available"); |
| 9678 | } |
| 9679 | // Now that all security checks passes, perform the operation as ourselves. |
| 9680 | final long identity = Binder.clearCallingIdentity(); |
| 9681 | try { |
| 9682 | return phone.getEquivalentHomePlmns(); |
| 9683 | } finally { |
| 9684 | Binder.restoreCallingIdentity(identity); |
| 9685 | } |
| 9686 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9687 | |
| 9688 | @Override |
| 9689 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9690 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9691 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9692 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9693 | if (radioInterfaceCapabilities == null) { |
| 9694 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9695 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9696 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9697 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9698 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9699 | @Override |
| 9700 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9701 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9702 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9703 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9704 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9705 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9706 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9707 | if (DBG) { |
| 9708 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9709 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9710 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9711 | } |
| 9712 | |
| 9713 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9714 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9715 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9716 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9717 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9718 | if (callback != null) { |
| 9719 | try { |
| 9720 | callback.onAuthenticationFailure( |
| 9721 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9722 | } catch (RemoteException exception) { |
| 9723 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9724 | } |
| 9725 | return; |
| 9726 | } |
| 9727 | } |
| 9728 | |
| 9729 | final long token = Binder.clearCallingIdentity(); |
| 9730 | try { |
| 9731 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9732 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9733 | forceBootStrapping, callback)); |
| 9734 | } finally { |
| 9735 | Binder.restoreCallingIdentity(token); |
| 9736 | } |
| 9737 | } |
| 9738 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9739 | /** |
| 9740 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9741 | * requested radio power state will actually be set. See {@link |
| 9742 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9743 | * |
| 9744 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9745 | * @param enable {@code true} if trying to turn radio on. |
| 9746 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9747 | * false}. |
| 9748 | */ |
| 9749 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9750 | Phone phone = getPhone(subId); |
| 9751 | if (phone != null) { |
| 9752 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9753 | return true; |
| 9754 | } |
| 9755 | return false; |
| 9756 | } |
| 9757 | |
| 9758 | private int handleDataThrottlingRequest(int subId, |
| 9759 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9760 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9761 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9762 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9763 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9764 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9765 | } |
| 9766 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9767 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9768 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9769 | if (!setRadioPowerForThermal(subId, true)) { |
| 9770 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9771 | } |
| 9772 | |
| 9773 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9774 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9775 | if (isDataThrottlingSupported) { |
| 9776 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9777 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9778 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9779 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9780 | } else if (thermalMitigationResult |
| 9781 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
| 9782 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9783 | } |
| 9784 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9785 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9786 | |
| 9787 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9788 | } |
| 9789 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9790 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 9791 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 9792 | for (String pckg : context.getResources() |
| 9793 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 9794 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 9795 | } |
| 9796 | } |
| 9797 | |
| 9798 | return sThermalMitigationAllowlistedPackages; |
| 9799 | } |
| 9800 | |
| 9801 | /** |
| 9802 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 9803 | * @param packageName name of package to be allowlisted |
| 9804 | * @param context |
| 9805 | */ |
| 9806 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 9807 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9808 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 9809 | } |
| 9810 | |
| 9811 | /** |
| 9812 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 9813 | * @param packageName name of package to remove from allowlist |
| 9814 | * @param context |
| 9815 | */ |
| 9816 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 9817 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9818 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 9819 | } |
| 9820 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9821 | /** |
| 9822 | * Thermal mitigation request to control functionalities at modem. |
| 9823 | * |
| 9824 | * @param subId the id of the subscription. |
| 9825 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9826 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9827 | * |
| 9828 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9829 | */ |
| 9830 | @Override |
| 9831 | @ThermalMitigationResult |
| 9832 | public int sendThermalMitigationRequest( |
| 9833 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9834 | ThermalMitigationRequest thermalMitigationRequest, |
| 9835 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9836 | enforceModifyPermission(); |
| 9837 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9838 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 9839 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 9840 | .contains(callingPackage)) { |
| 9841 | throw new SecurityException("Calling package must be configured in the device config. " |
| 9842 | + "calling package: " + callingPackage); |
| 9843 | } |
| 9844 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9845 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9846 | final long identity = Binder.clearCallingIdentity(); |
| 9847 | |
| 9848 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9849 | try { |
| 9850 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9851 | switch (thermalMitigationAction) { |
| 9852 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9853 | thermalMitigationResult = |
| 9854 | handleDataThrottlingRequest(subId, |
| 9855 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9856 | break; |
| 9857 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9858 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9859 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9860 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9861 | } |
| 9862 | |
| 9863 | // Ensure that radio is on. If not able to power on due to phone being |
| 9864 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9865 | if (!setRadioPowerForThermal(subId, true)) { |
| 9866 | thermalMitigationResult = |
| 9867 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9868 | break; |
| 9869 | } |
| 9870 | |
| 9871 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9872 | false); |
| 9873 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9874 | break; |
| 9875 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9876 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9877 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9878 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9879 | } |
| 9880 | |
| 9881 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9882 | if (registry != null) { |
| 9883 | TelephonyConnectionService service = |
| 9884 | registry.getTelephonyConnectionService(); |
| 9885 | Phone phone = getPhone(subId); |
| 9886 | if (phone == null) { |
| 9887 | thermalMitigationResult = |
| 9888 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9889 | break; |
| 9890 | } |
| 9891 | |
| 9892 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9893 | != TelephonyManager.CALL_STATE_IDLE |
| 9894 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9895 | || (service != null && service.isEmergencyCallPending())) { |
| 9896 | String errorMessage = "Phone state is not valid. call state = " |
| 9897 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9898 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9899 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9900 | errorMessage += service == null |
| 9901 | ? " TelephonyConnectionService is null" |
| 9902 | : " isEmergencyCallPending = " |
| 9903 | + service.isEmergencyCallPending(); |
| 9904 | Log.e(LOG_TAG, errorMessage); |
| 9905 | thermalMitigationResult = |
| 9906 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9907 | break; |
| 9908 | } |
| 9909 | } else { |
| 9910 | thermalMitigationResult = |
| 9911 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9912 | break; |
| 9913 | } |
| 9914 | |
| 9915 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9916 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9917 | if (!setRadioPowerForThermal(subId, false)) { |
| 9918 | thermalMitigationResult = |
| 9919 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9920 | break; |
| 9921 | } |
| 9922 | thermalMitigationResult = |
| 9923 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9924 | break; |
| 9925 | default: |
| 9926 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9927 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9928 | } |
| 9929 | } catch (IllegalArgumentException e) { |
| 9930 | throw e; |
| 9931 | } catch (Exception e) { |
| 9932 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9933 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9934 | } finally { |
| 9935 | Binder.restoreCallingIdentity(identity); |
| 9936 | } |
| 9937 | |
| 9938 | if (DBG) { |
| 9939 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9940 | + thermalMitigationResult); |
| 9941 | } |
| 9942 | |
| 9943 | return thermalMitigationResult; |
| 9944 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9945 | |
| 9946 | /** |
| 9947 | * Set the GbaService Package Name that Telephony will bind to. |
| 9948 | * |
| 9949 | * @param subId The sim that the GbaService is associated with. |
| 9950 | * @param packageName The name of the package to be replaced with. |
| 9951 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9952 | */ |
| 9953 | @Override |
| 9954 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9955 | enforceModifyPermission(); |
| 9956 | |
| 9957 | final long identity = Binder.clearCallingIdentity(); |
| 9958 | try { |
| 9959 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9960 | } finally { |
| 9961 | Binder.restoreCallingIdentity(identity); |
| 9962 | } |
| 9963 | } |
| 9964 | |
| 9965 | /** |
| 9966 | * Return the package name of the currently bound GbaService. |
| 9967 | * |
| 9968 | * @param subId The sim that the GbaService is associated with. |
| 9969 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9970 | */ |
| 9971 | @Override |
| 9972 | public String getBoundGbaService(int subId) { |
| 9973 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9974 | |
| 9975 | final long identity = Binder.clearCallingIdentity(); |
| 9976 | try { |
| 9977 | return getGbaManager(subId).getServicePackage(); |
| 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(identity); |
| 9980 | } |
| 9981 | } |
| 9982 | |
| 9983 | /** |
| 9984 | * Set the release time for telephony to unbind GbaService. |
| 9985 | * |
| 9986 | * @param subId The sim that the GbaService is associated with. |
| 9987 | * @param interval The release time to unbind GbaService by millisecond. |
| 9988 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9989 | */ |
| 9990 | @Override |
| 9991 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9992 | enforceModifyPermission(); |
| 9993 | |
| 9994 | final long identity = Binder.clearCallingIdentity(); |
| 9995 | try { |
| 9996 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9997 | } finally { |
| 9998 | Binder.restoreCallingIdentity(identity); |
| 9999 | } |
| 10000 | } |
| 10001 | |
| 10002 | /** |
| 10003 | * Return the release time for telephony to unbind GbaService. |
| 10004 | * |
| 10005 | * @param subId The sim that the GbaService is associated with. |
| 10006 | * @return The release time to unbind GbaService by millisecond. |
| 10007 | */ |
| 10008 | @Override |
| 10009 | public int getGbaReleaseTime(int subId) { |
| 10010 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10011 | |
| 10012 | final long identity = Binder.clearCallingIdentity(); |
| 10013 | try { |
| 10014 | return getGbaManager(subId).getReleaseTime(); |
| 10015 | } finally { |
| 10016 | Binder.restoreCallingIdentity(identity); |
| 10017 | } |
| 10018 | } |
| 10019 | |
| 10020 | private GbaManager getGbaManager(int subId) { |
| 10021 | GbaManager instance = GbaManager.getInstance(subId); |
| 10022 | if (instance == null) { |
| 10023 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10024 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10025 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10026 | } |
| 10027 | return instance; |
| 10028 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10029 | |
| 10030 | /** |
| 10031 | * indicate whether the device and the carrier can support |
| 10032 | * RCS VoLTE single registration. |
| 10033 | */ |
| 10034 | @Override |
| 10035 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10036 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10037 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10038 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10039 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10040 | |
| 10041 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10042 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10043 | } |
| 10044 | |
| 10045 | final long identity = Binder.clearCallingIdentity(); |
| 10046 | try { |
| 10047 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10048 | if (rpm != null) { |
| 10049 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10050 | } |
| 10051 | return false; |
| 10052 | } finally { |
| 10053 | Binder.restoreCallingIdentity(identity); |
| 10054 | } |
| 10055 | } |
| 10056 | |
| 10057 | /** |
| 10058 | * Register RCS provisioning callback. |
| 10059 | */ |
| 10060 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10061 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10062 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10063 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10064 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10065 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10066 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10067 | |
| 10068 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10069 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10070 | } |
| 10071 | if (!isImsAvailableOnDevice()) { |
| 10072 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10073 | "IMS not available on device."); |
| 10074 | } |
| 10075 | |
| 10076 | final long identity = Binder.clearCallingIdentity(); |
| 10077 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10078 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10079 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10080 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10081 | "Service not available for the subscription."); |
| 10082 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10083 | } finally { |
| 10084 | Binder.restoreCallingIdentity(identity); |
| 10085 | } |
| 10086 | } |
| 10087 | |
| 10088 | /** |
| 10089 | * Unregister RCS provisioning callback. |
| 10090 | */ |
| 10091 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10092 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10093 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10094 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10095 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10096 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10097 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10098 | |
| 10099 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10100 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10101 | } |
| 10102 | if (!isImsAvailableOnDevice()) { |
| 10103 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10104 | "IMS not available on device."); |
| 10105 | } |
| 10106 | |
| 10107 | final long identity = Binder.clearCallingIdentity(); |
| 10108 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10109 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10110 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10111 | } finally { |
| 10112 | Binder.restoreCallingIdentity(identity); |
| 10113 | } |
| 10114 | } |
| 10115 | |
| 10116 | /** |
| 10117 | * trigger RCS reconfiguration. |
| 10118 | */ |
| 10119 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10120 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10121 | "triggerRcsReconfiguration", |
| 10122 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10123 | |
| 10124 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10125 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10126 | } |
| 10127 | if (!isImsAvailableOnDevice()) { |
| 10128 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10129 | "IMS not available on device."); |
| 10130 | } |
| 10131 | |
| 10132 | final long identity = Binder.clearCallingIdentity(); |
| 10133 | try { |
| 10134 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10135 | } finally { |
| 10136 | Binder.restoreCallingIdentity(identity); |
| 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | /** |
| 10141 | * Provide the client configuration parameters of the RCS application. |
| 10142 | */ |
| 10143 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10144 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10145 | "setRcsClientConfiguration", |
| 10146 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10147 | |
| 10148 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10149 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10150 | } |
| 10151 | if (!isImsAvailableOnDevice()) { |
| 10152 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10153 | "IMS not available on device."); |
| 10154 | } |
| 10155 | |
| 10156 | final long identity = Binder.clearCallingIdentity(); |
| 10157 | |
| 10158 | try { |
| 10159 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10160 | if (configBinder == null) { |
| 10161 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 10162 | } else { |
| 10163 | configBinder.setRcsClientConfiguration(rcc); |
| 10164 | } |
| 10165 | } catch (RemoteException e) { |
| 10166 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 10167 | } finally { |
| 10168 | Binder.restoreCallingIdentity(identity); |
| 10169 | } |
| 10170 | } |
| 10171 | |
| 10172 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10173 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10174 | */ |
| 10175 | @Override |
| 10176 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10178 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10179 | |
| 10180 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10181 | } |
| 10182 | |
| 10183 | /** |
| 10184 | * Gets the test mode for RCS VoLTE single registration. |
| 10185 | */ |
| 10186 | @Override |
| 10187 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10188 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10189 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10190 | |
| 10191 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10192 | } |
| 10193 | |
| 10194 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10195 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10196 | */ |
| 10197 | @Override |
| 10198 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10199 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10200 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10201 | enforceModifyPermission(); |
| 10202 | |
| 10203 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10204 | : Boolean.parseBoolean(enabledStr); |
| 10205 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10206 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10207 | } |
| 10208 | |
| 10209 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10210 | * Sends a device to device communication message. Only usable via shell. |
| 10211 | * @param message message to send. |
| 10212 | * @param value message value. |
| 10213 | */ |
| 10214 | @Override |
| 10215 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10216 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10217 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10218 | enforceModifyPermission(); |
| 10219 | |
| 10220 | final long identity = Binder.clearCallingIdentity(); |
| 10221 | try { |
| 10222 | TelephonyConnectionService service = |
| 10223 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10224 | if (service == null) { |
| 10225 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10226 | return; |
| 10227 | } |
| 10228 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10229 | } finally { |
| 10230 | Binder.restoreCallingIdentity(identity); |
| 10231 | } |
| 10232 | } |
| 10233 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10234 | /** |
| 10235 | * Sets the specified device to device transport active. |
| 10236 | * @param transport The transport to set active. |
| 10237 | */ |
| 10238 | @Override |
| 10239 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10240 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10241 | "setActiveDeviceToDeviceTransport"); |
| 10242 | enforceModifyPermission(); |
| 10243 | |
| 10244 | final long identity = Binder.clearCallingIdentity(); |
| 10245 | try { |
| 10246 | TelephonyConnectionService service = |
| 10247 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10248 | if (service == null) { |
| 10249 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10250 | return; |
| 10251 | } |
| 10252 | service.setActiveDeviceToDeviceTransport(transport); |
| 10253 | } finally { |
| 10254 | Binder.restoreCallingIdentity(identity); |
| 10255 | } |
| 10256 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10257 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10258 | @Override |
| 10259 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10260 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10261 | "setDeviceToDeviceForceEnabled"); |
| 10262 | |
| 10263 | final long identity = Binder.clearCallingIdentity(); |
| 10264 | try { |
| 10265 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10266 | p -> { |
| 10267 | Phone thePhone = p.getImsPhone(); |
| 10268 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10269 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10270 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10271 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10272 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10273 | (ImsPhoneCallTracker) tracker; |
| 10274 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10275 | } |
| 10276 | } |
| 10277 | } |
| 10278 | ); |
| 10279 | } finally { |
| 10280 | Binder.restoreCallingIdentity(identity); |
| 10281 | } |
| 10282 | } |
| 10283 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10284 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10285 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10286 | */ |
| 10287 | @Override |
| 10288 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10289 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10290 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10291 | } |
| 10292 | |
| 10293 | /** |
| 10294 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10295 | */ |
| 10296 | @Override |
| 10297 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10299 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10300 | enforceModifyPermission(); |
| 10301 | |
| 10302 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10303 | : Boolean.parseBoolean(enabledStr); |
| 10304 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10305 | subId, enabled); |
| 10306 | } |
| 10307 | |
| 10308 | /** |
| 10309 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10310 | */ |
| 10311 | @Override |
| 10312 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10313 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10314 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10315 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10316 | |
| 10317 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10318 | * Overrides the ims feature validation result |
| 10319 | */ |
| 10320 | @Override |
| 10321 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10322 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10323 | "setImsFeatureValidationOverride"); |
| 10324 | |
| 10325 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10326 | : Boolean.parseBoolean(enabledStr); |
| 10327 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10328 | subId, enabled); |
| 10329 | } |
| 10330 | |
| 10331 | /** |
| 10332 | * Gets the ims feature validation override value |
| 10333 | */ |
| 10334 | @Override |
| 10335 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10336 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10337 | "getImsFeatureValidationOverride"); |
| 10338 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10339 | } |
| 10340 | |
| 10341 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10342 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10343 | * their mobile plan. |
| 10344 | */ |
| 10345 | @Override |
| 10346 | public String getMobileProvisioningUrl() { |
| 10347 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10348 | final long identity = Binder.clearCallingIdentity(); |
| 10349 | try { |
| 10350 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10351 | } finally { |
| 10352 | Binder.restoreCallingIdentity(identity); |
| 10353 | } |
| 10354 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10355 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10356 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10357 | * Get the EAB contact from the EAB database. |
| 10358 | */ |
| 10359 | @Override |
| 10360 | public String getContactFromEab(String contact) { |
| 10361 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10362 | enforceModifyPermission(); |
| 10363 | final long identity = Binder.clearCallingIdentity(); |
| 10364 | try { |
| 10365 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | } |
| 10370 | |
| 10371 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10372 | * Remove the EAB contacts from the EAB database. |
| 10373 | */ |
| 10374 | @Override |
| 10375 | public int removeContactFromEab(int subId, String contacts) { |
| 10376 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10377 | enforceModifyPermission(); |
| 10378 | final long identity = Binder.clearCallingIdentity(); |
| 10379 | try { |
| 10380 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10381 | } finally { |
| 10382 | Binder.restoreCallingIdentity(identity); |
| 10383 | } |
| 10384 | } |
| 10385 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10386 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10387 | public boolean getDeviceUceEnabled() { |
| 10388 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10389 | final long identity = Binder.clearCallingIdentity(); |
| 10390 | try { |
| 10391 | return mApp.getDeviceUceEnabled(); |
| 10392 | } finally { |
| 10393 | Binder.restoreCallingIdentity(identity); |
| 10394 | } |
| 10395 | } |
| 10396 | |
| 10397 | @Override |
| 10398 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10399 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10400 | final long identity = Binder.clearCallingIdentity(); |
| 10401 | try { |
| 10402 | mApp.setDeviceUceEnabled(isEnabled); |
| 10403 | } finally { |
| 10404 | Binder.restoreCallingIdentity(identity); |
| 10405 | } |
| 10406 | } |
| 10407 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10408 | /** |
| 10409 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10410 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10411 | */ |
| 10412 | // Used for SHELL command only right now. |
| 10413 | @Override |
| 10414 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10415 | List<String> featureTags) { |
| 10416 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10417 | "addUceRegistrationOverrideShell"); |
| 10418 | final long identity = Binder.clearCallingIdentity(); |
| 10419 | try { |
| 10420 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10421 | new ArraySet<>(featureTags)); |
| 10422 | } catch (ImsException e) { |
| 10423 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10424 | } finally { |
| 10425 | Binder.restoreCallingIdentity(identity); |
| 10426 | } |
| 10427 | } |
| 10428 | |
| 10429 | /** |
| 10430 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10431 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10432 | */ |
| 10433 | // Used for SHELL command only right now. |
| 10434 | @Override |
| 10435 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10436 | List<String> featureTags) { |
| 10437 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10438 | "removeUceRegistrationOverrideShell"); |
| 10439 | final long identity = Binder.clearCallingIdentity(); |
| 10440 | try { |
| 10441 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10442 | new ArraySet<>(featureTags)); |
| 10443 | } catch (ImsException e) { |
| 10444 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10445 | } finally { |
| 10446 | Binder.restoreCallingIdentity(identity); |
| 10447 | } |
| 10448 | } |
| 10449 | |
| 10450 | /** |
| 10451 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10452 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10453 | */ |
| 10454 | // Used for SHELL command only right now. |
| 10455 | @Override |
| 10456 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10457 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10458 | "clearUceRegistrationOverrideShell"); |
| 10459 | final long identity = Binder.clearCallingIdentity(); |
| 10460 | try { |
| 10461 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10462 | } catch (ImsException e) { |
| 10463 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10464 | } finally { |
| 10465 | Binder.restoreCallingIdentity(identity); |
| 10466 | } |
| 10467 | } |
| 10468 | |
| 10469 | /** |
| 10470 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10471 | */ |
| 10472 | // Used for SHELL command only right now. |
| 10473 | @Override |
| 10474 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10475 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10476 | "getLatestRcsContactUceCapabilityShell"); |
| 10477 | final long identity = Binder.clearCallingIdentity(); |
| 10478 | try { |
| 10479 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10480 | } catch (ImsException e) { |
| 10481 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10482 | } finally { |
| 10483 | Binder.restoreCallingIdentity(identity); |
| 10484 | } |
| 10485 | } |
| 10486 | |
| 10487 | /** |
| 10488 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10489 | * device does not have an active PUBLISH. |
| 10490 | */ |
| 10491 | // Used for SHELL command only right now. |
| 10492 | @Override |
| 10493 | public String getLastUcePidfXmlShell(int subId) { |
| 10494 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10495 | final long identity = Binder.clearCallingIdentity(); |
| 10496 | try { |
| 10497 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10498 | } catch (ImsException e) { |
| 10499 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10500 | } finally { |
| 10501 | Binder.restoreCallingIdentity(identity); |
| 10502 | } |
| 10503 | } |
| 10504 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10505 | /** |
| 10506 | * Remove UCE requests cannot be sent to the network status. |
| 10507 | */ |
| 10508 | // Used for SHELL command only right now. |
| 10509 | @Override |
| 10510 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10511 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10512 | final long identity = Binder.clearCallingIdentity(); |
| 10513 | try { |
| 10514 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10515 | } catch (ImsException e) { |
| 10516 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10517 | } finally { |
| 10518 | Binder.restoreCallingIdentity(identity); |
| 10519 | } |
| 10520 | } |
| 10521 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10522 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10523 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10524 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10525 | String callingPackage) { |
| 10526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10527 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10528 | |
| 10529 | final int callingUid = Binder.getCallingUid(); |
| 10530 | // Verify that tha callingPackage belongs to the calling UID |
| 10531 | mApp.getSystemService(AppOpsManager.class) |
| 10532 | .checkPackage(callingUid, callingPackage); |
| 10533 | |
| 10534 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10535 | |
| 10536 | final long identity = Binder.clearCallingIdentity(); |
| 10537 | try { |
| 10538 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10539 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10540 | |
| 10541 | if (result instanceof IllegalStateException) { |
| 10542 | throw (IllegalStateException) result; |
| 10543 | } |
| 10544 | } finally { |
| 10545 | Binder.restoreCallingIdentity(identity); |
| 10546 | } |
| 10547 | } |
| 10548 | |
| 10549 | @Override |
| 10550 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10551 | String callingPackage) { |
| 10552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10553 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10554 | |
| 10555 | final int callingUid = Binder.getCallingUid(); |
| 10556 | // Verify that tha callingPackage belongs to the calling UID |
| 10557 | mApp.getSystemService(AppOpsManager.class) |
| 10558 | .checkPackage(callingUid, callingPackage); |
| 10559 | |
| 10560 | final long identity = Binder.clearCallingIdentity(); |
| 10561 | try { |
| 10562 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10563 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10564 | |
| 10565 | if (result instanceof IllegalStateException) { |
| 10566 | throw (IllegalStateException) result; |
| 10567 | } |
| 10568 | } finally { |
| 10569 | Binder.restoreCallingIdentity(identity); |
| 10570 | } |
| 10571 | } |
| 10572 | |
| 10573 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10574 | int callingUid) { |
| 10575 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10576 | // phone/system process do not have further restriction on request |
| 10577 | return; |
| 10578 | } |
| 10579 | |
| 10580 | // Applications has restrictions on how to use the request: |
| 10581 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10582 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10583 | // This is not system caller which has been checked above |
| 10584 | throw new IllegalArgumentException( |
| 10585 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10586 | } |
| 10587 | |
| 10588 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10589 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10590 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10591 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10592 | || info.isEnabled()) { |
| 10593 | throw new IllegalArgumentException( |
| 10594 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10595 | } |
| 10596 | |
| 10597 | // Thresholds length for each RAN need in range. This has been validated in |
| 10598 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10599 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10600 | final int[] thresholds = info.getThresholds(); |
| 10601 | Objects.requireNonNull(thresholds); |
| 10602 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10603 | || thresholds.length |
| 10604 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10605 | throw new IllegalArgumentException( |
| 10606 | "thresholds length is out of range: " + thresholds.length); |
| 10607 | } |
| 10608 | } |
| 10609 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10610 | |
| 10611 | /** |
| 10612 | * Gets the current phone capability. |
| 10613 | * |
| 10614 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10615 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10616 | * It's used to evaluate possible phone config change, for example from single |
| 10617 | * SIM device to multi-SIM device. |
| 10618 | */ |
| 10619 | @Override |
| 10620 | public PhoneCapability getPhoneCapability() { |
| 10621 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10622 | final long identity = Binder.clearCallingIdentity(); |
| 10623 | try { |
| 10624 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10625 | } finally { |
| 10626 | Binder.restoreCallingIdentity(identity); |
| 10627 | } |
| 10628 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10629 | |
| 10630 | /** |
| 10631 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10632 | * required to be done shortly after the API is invoked. |
| 10633 | */ |
| 10634 | @Override |
| 10635 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10636 | public int prepareForUnattendedReboot() { |
| 10637 | enforceRebootPermission(); |
| 10638 | |
| 10639 | final long identity = Binder.clearCallingIdentity(); |
| 10640 | try { |
| 10641 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10642 | } finally { |
| 10643 | Binder.restoreCallingIdentity(identity); |
| 10644 | } |
| 10645 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10646 | |
| 10647 | /** |
| 10648 | * Request to get the current slicing configuration including URSP rules and |
| 10649 | * NSSAIs (configured, allowed and rejected). |
| 10650 | * |
| 10651 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10652 | */ |
| 10653 | @Override |
| 10654 | public void getSlicingConfig(ResultReceiver callback) { |
| 10655 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10656 | |
| 10657 | final long identity = Binder.clearCallingIdentity(); |
| 10658 | try { |
| 10659 | Phone phone = getDefaultPhone(); |
| 10660 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10661 | } finally { |
| 10662 | Binder.restoreCallingIdentity(identity); |
| 10663 | } |
| 10664 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10665 | } |