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; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 167 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 180 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 191 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 192 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 194 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 195 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 196 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 197 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 198 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 199 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 200 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 201 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 202 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 203 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 204 | import com.android.services.telephony.TelecomAccountRegistry; |
| 205 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 206 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 207 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 208 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 209 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 210 | import java.io.IOException; |
| 211 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 212 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 214 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 215 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 216 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 217 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 218 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 219 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 220 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 222 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 224 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 225 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Implementation of the ITelephony interface. |
| 229 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 230 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 231 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 232 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 233 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 234 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | |
| 236 | // Message codes used with mMainThreadHandler |
| 237 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 238 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 239 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 240 | private static final int CMD_OPEN_CHANNEL = 9; |
| 241 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 242 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 243 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 244 | private static final int CMD_NV_READ_ITEM = 13; |
| 245 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 246 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 247 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 248 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 249 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 250 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 251 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 252 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 253 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 254 | private static final int CMD_SEND_ENVELOPE = 25; |
| 255 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 256 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 257 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 258 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 259 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 260 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 261 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 262 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 263 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 265 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 267 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 268 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 269 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 270 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 271 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 272 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 273 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 274 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 275 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 276 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 277 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 278 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 279 | private static final int CMD_SWITCH_SLOTS = 50; |
| 280 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 282 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 283 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 284 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 285 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 286 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 287 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 288 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 289 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 290 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 291 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 292 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 293 | private static final int CMD_MODEM_REBOOT = 64; |
| 294 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 295 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 296 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 297 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 298 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 299 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 300 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 301 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 302 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 303 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 304 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 305 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 306 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 307 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 308 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 310 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 311 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 312 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 313 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 314 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 315 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 316 | private static final int CMD_GET_CALL_WAITING = 87; |
| 317 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 318 | private static final int CMD_SET_CALL_WAITING = 89; |
| 319 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 320 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 321 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 322 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 323 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 325 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 326 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 327 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 328 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 329 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 330 | private static final int CMD_SET_SIM_POWER = 101; |
| 331 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 332 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 333 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 334 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 335 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 336 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 337 | 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] | 338 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 339 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 340 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 341 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 343 | // Parameters of select command. |
| 344 | private static final int SELECT_COMMAND = 0xA4; |
| 345 | private static final int SELECT_P1 = 0x04; |
| 346 | private static final int SELECT_P2 = 0; |
| 347 | private static final int SELECT_P3 = 0x10; |
| 348 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | /** The singleton instance. */ |
| 350 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 351 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 352 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 353 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 354 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 355 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 356 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 357 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 358 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 359 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 360 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 361 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 362 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 363 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 365 | /** User Activity */ |
| 366 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 367 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 368 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 369 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 370 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 371 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 372 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 373 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 374 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 375 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 376 | // String to store multi SIM allowed |
| 377 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 378 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 379 | // The AID of ISD-R. |
| 380 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 381 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 382 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 383 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 384 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 385 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 386 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 387 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 388 | 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] | 389 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 390 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 391 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 392 | */ |
| 393 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 394 | "reset_network_erase_modem_config_enabled"; |
| 395 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 396 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 397 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 398 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 399 | * A request object to use for transmitting data to an ICC. |
| 400 | */ |
| 401 | private static final class IccAPDUArgument { |
| 402 | public int channel, cla, command, p1, p2, p3; |
| 403 | public String data; |
| 404 | |
| 405 | public IccAPDUArgument(int channel, int cla, int command, |
| 406 | int p1, int p2, int p3, String data) { |
| 407 | this.channel = channel; |
| 408 | this.cla = cla; |
| 409 | this.command = command; |
| 410 | this.p1 = p1; |
| 411 | this.p2 = p2; |
| 412 | this.p3 = p3; |
| 413 | this.data = data; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 418 | * A request object to use for transmitting data to an ICC. |
| 419 | */ |
| 420 | private static final class ManualNetworkSelectionArgument { |
| 421 | public OperatorInfo operatorInfo; |
| 422 | public boolean persistSelection; |
| 423 | |
| 424 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 425 | this.operatorInfo = operatorInfo; |
| 426 | this.persistSelection = persistSelection; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 432 | * request after sending. The main thread will notify the request when it is complete. |
| 433 | */ |
| 434 | private static final class MainThreadRequest { |
| 435 | /** The argument to use for the request */ |
| 436 | public Object argument; |
| 437 | /** The result of the request that is run on the main thread */ |
| 438 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 439 | // The subscriber id that this request applies to. Defaults to |
| 440 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 441 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 443 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 444 | public Phone phone; |
| 445 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 446 | public WorkSource workSource; |
| 447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | public MainThreadRequest(Object argument) { |
| 449 | this.argument = argument; |
| 450 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 451 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 452 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 453 | this.argument = argument; |
| 454 | if (phone != null) { |
| 455 | this.phone = phone; |
| 456 | } |
| 457 | this.workSource = workSource; |
| 458 | } |
| 459 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 460 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 461 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 462 | if (subId != null) { |
| 463 | this.subId = subId; |
| 464 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 465 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 466 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 469 | private static final class IncomingThirdPartyCallArgs { |
| 470 | public final ComponentName component; |
| 471 | public final String callId; |
| 472 | public final String callerDisplayName; |
| 473 | |
| 474 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 475 | String callerDisplayName) { |
| 476 | this.component = component; |
| 477 | this.callId = callId; |
| 478 | this.callerDisplayName = callerDisplayName; |
| 479 | } |
| 480 | } |
| 481 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | /** |
| 483 | * A handler that processes messages on the main thread in the phone process. Since many |
| 484 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 485 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 486 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 487 | * on, which will be notified when the operation completes and will contain the result of the |
| 488 | * request. |
| 489 | * |
| 490 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 491 | * note that request.result must be set to something non-null for the calling thread to |
| 492 | * unblock. |
| 493 | */ |
| 494 | private final class MainThreadHandler extends Handler { |
| 495 | @Override |
| 496 | public void handleMessage(Message msg) { |
| 497 | MainThreadRequest request; |
| 498 | Message onCompleted; |
| 499 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 500 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 501 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 502 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 503 | |
| 504 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | case CMD_HANDLE_USSD_REQUEST: { |
| 506 | request = (MainThreadRequest) msg.obj; |
| 507 | final Phone phone = getPhoneFromRequest(request); |
| 508 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 509 | String ussdRequest = ussdObject.first; |
| 510 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 511 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 512 | if (!isUssdApiAllowed(request.subId)) { |
| 513 | // Carrier does not support use of this API, return failure. |
| 514 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 515 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 516 | Bundle returnData = new Bundle(); |
| 517 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 518 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 519 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 520 | request.result = true; |
| 521 | notifyRequester(request); |
| 522 | return; |
| 523 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 524 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | try { |
| 526 | request.result = phone != null |
| 527 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 528 | } catch (CallStateException cse) { |
| 529 | request.result = false; |
| 530 | } |
| 531 | // Wake up the requesting thread |
| 532 | notifyRequester(request); |
| 533 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 536 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 537 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 538 | final Phone phone = getPhoneFromRequest(request); |
| 539 | request.result = phone != null ? |
| 540 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 541 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 546 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 547 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 549 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 550 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 551 | if (uiccCard == null) { |
| 552 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 553 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 554 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 555 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 556 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 557 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 558 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 560 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 561 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 562 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 563 | break; |
| 564 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 565 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 566 | ar = (AsyncResult) msg.obj; |
| 567 | request = (MainThreadRequest) ar.userObj; |
| 568 | if (ar.exception == null && ar.result != null) { |
| 569 | request.result = ar.result; |
| 570 | } else { |
| 571 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 572 | if (ar.result == null) { |
| 573 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 574 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 575 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 576 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 577 | } else { |
| 578 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 579 | } |
| 580 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 582 | break; |
| 583 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 585 | request = (MainThreadRequest) msg.obj; |
| 586 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 587 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | if (uiccCard == null) { |
| 589 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 590 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | } else { |
| 593 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 594 | request); |
| 595 | uiccCard.iccTransmitApduBasicChannel( |
| 596 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 597 | iccArgument.p3, iccArgument.data, onCompleted); |
| 598 | } |
| 599 | break; |
| 600 | |
| 601 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 602 | ar = (AsyncResult) msg.obj; |
| 603 | request = (MainThreadRequest) ar.userObj; |
| 604 | if (ar.exception == null && ar.result != null) { |
| 605 | request.result = ar.result; |
| 606 | } else { |
| 607 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 608 | if (ar.result == null) { |
| 609 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 610 | } else if (ar.exception instanceof CommandException) { |
| 611 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 612 | ar.exception); |
| 613 | } else { |
| 614 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 615 | } |
| 616 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | break; |
| 619 | |
| 620 | case CMD_EXCHANGE_SIM_IO: |
| 621 | request = (MainThreadRequest) msg.obj; |
| 622 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 623 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | if (uiccCard == null) { |
| 625 | loge("iccExchangeSimIO: No UICC"); |
| 626 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | } else { |
| 629 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 630 | request); |
| 631 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 632 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 633 | iccArgument.data, onCompleted); |
| 634 | } |
| 635 | break; |
| 636 | |
| 637 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 638 | ar = (AsyncResult) msg.obj; |
| 639 | request = (MainThreadRequest) ar.userObj; |
| 640 | if (ar.exception == null && ar.result != null) { |
| 641 | request.result = ar.result; |
| 642 | } else { |
| 643 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 644 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 645 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | break; |
| 647 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 648 | case CMD_SEND_ENVELOPE: |
| 649 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 650 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | if (uiccCard == null) { |
| 652 | loge("sendEnvelopeWithStatus: No UICC"); |
| 653 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 655 | } else { |
| 656 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 657 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 658 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 659 | break; |
| 660 | |
| 661 | case EVENT_SEND_ENVELOPE_DONE: |
| 662 | ar = (AsyncResult) msg.obj; |
| 663 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 664 | if (ar.exception == null && ar.result != null) { |
| 665 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 666 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 667 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 668 | if (ar.result == null) { |
| 669 | loge("sendEnvelopeWithStatus: Empty response"); |
| 670 | } else if (ar.exception instanceof CommandException) { |
| 671 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 672 | ar.exception); |
| 673 | } else { |
| 674 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 675 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 676 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 678 | break; |
| 679 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | case CMD_OPEN_CHANNEL: |
| 681 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 682 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 683 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | if (uiccCard == null) { |
| 685 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 686 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 687 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 688 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 689 | } else { |
| 690 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 691 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 692 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 693 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case EVENT_OPEN_CHANNEL_DONE: |
| 697 | ar = (AsyncResult) msg.obj; |
| 698 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | int[] result = (int[]) ar.result; |
| 702 | int channelId = result[0]; |
| 703 | byte[] selectResponse = null; |
| 704 | if (result.length > 1) { |
| 705 | selectResponse = new byte[result.length - 1]; |
| 706 | for (int i = 1; i < result.length; ++i) { |
| 707 | selectResponse[i - 1] = (byte) result[i]; |
| 708 | } |
| 709 | } |
| 710 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 711 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | if (ar.result == null) { |
| 714 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 716 | if (ar.exception != null) { |
| 717 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 718 | } |
| 719 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 720 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 721 | if (ar.exception instanceof CommandException) { |
| 722 | CommandException.Error error = |
| 723 | ((CommandException) (ar.exception)).getCommandError(); |
| 724 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 725 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 726 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 727 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 731 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 732 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 733 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 734 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case CMD_CLOSE_CHANNEL: |
| 738 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 739 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 740 | if (uiccCard == null) { |
| 741 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 742 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 744 | } else { |
| 745 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 746 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 747 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 748 | break; |
| 749 | |
| 750 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 751 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 752 | break; |
| 753 | |
| 754 | case CMD_NV_READ_ITEM: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 757 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 758 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | break; |
| 760 | |
| 761 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | ar = (AsyncResult) msg.obj; |
| 763 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 764 | if (ar.exception == null && ar.result != null) { |
| 765 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 766 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 767 | request.result = ""; |
| 768 | if (ar.result == null) { |
| 769 | loge("nvReadItem: Empty response"); |
| 770 | } else if (ar.exception instanceof CommandException) { |
| 771 | loge("nvReadItem: CommandException: " + |
| 772 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 773 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 775 | } |
| 776 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 777 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | break; |
| 779 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 780 | case CMD_NV_WRITE_ITEM: |
| 781 | request = (MainThreadRequest) msg.obj; |
| 782 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 783 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 785 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case EVENT_NV_WRITE_ITEM_DONE: |
| 789 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 790 | break; |
| 791 | |
| 792 | case CMD_NV_WRITE_CDMA_PRL: |
| 793 | request = (MainThreadRequest) msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 795 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 796 | break; |
| 797 | |
| 798 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 799 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 800 | break; |
| 801 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 802 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 803 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 804 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 805 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 806 | break; |
| 807 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 808 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 809 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 810 | break; |
| 811 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 812 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 815 | request); |
| 816 | Phone phone = getPhoneFromRequest(request); |
| 817 | if (phone != null) { |
| 818 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 819 | } else { |
| 820 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 821 | request.result = false; |
| 822 | notifyRequester(request); |
| 823 | } |
| 824 | break; |
| 825 | } |
| 826 | |
| 827 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 828 | ar = (AsyncResult) msg.obj; |
| 829 | request = (MainThreadRequest) ar.userObj; |
| 830 | if (ar.exception == null && ar.result != null) { |
| 831 | request.result = ar.result; |
| 832 | } else { |
| 833 | // request.result must be set to something non-null |
| 834 | // for the calling thread to unblock |
| 835 | if (request.result != null) { |
| 836 | request.result = ar.result; |
| 837 | } else { |
| 838 | request.result = false; |
| 839 | } |
| 840 | if (ar.result == null) { |
| 841 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 842 | } else if (ar.exception instanceof CommandException) { |
| 843 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 844 | + ar.exception); |
| 845 | } else { |
| 846 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 847 | } |
| 848 | } |
| 849 | notifyRequester(request); |
| 850 | break; |
| 851 | |
| 852 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 853 | request = (MainThreadRequest) msg.obj; |
| 854 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 855 | Phone phone = getPhoneFromRequest(request); |
| 856 | if (phone != null) { |
| 857 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 858 | request.workSource); |
| 859 | } else { |
| 860 | loge("enableNrDualConnectivity: No phone object"); |
| 861 | request.result = |
| 862 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 863 | notifyRequester(request); |
| 864 | } |
| 865 | break; |
| 866 | } |
| 867 | |
| 868 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 869 | ar = (AsyncResult) msg.obj; |
| 870 | request = (MainThreadRequest) ar.userObj; |
| 871 | if (ar.exception == null) { |
| 872 | request.result = |
| 873 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 874 | } else { |
| 875 | request.result = |
| 876 | TelephonyManager |
| 877 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 878 | if (ar.exception instanceof CommandException) { |
| 879 | CommandException.Error error = |
| 880 | ((CommandException) (ar.exception)).getCommandError(); |
| 881 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 882 | request.result = |
| 883 | TelephonyManager |
| 884 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 885 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 886 | request.result = |
| 887 | TelephonyManager |
| 888 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 889 | } |
| 890 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 891 | + ar.exception); |
| 892 | } else { |
| 893 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 894 | } |
| 895 | } |
| 896 | notifyRequester(request); |
| 897 | break; |
| 898 | } |
| 899 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 900 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 902 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 903 | request); |
| 904 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 905 | break; |
| 906 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | ar = (AsyncResult) msg.obj; |
| 909 | request = (MainThreadRequest) ar.userObj; |
| 910 | if (ar.exception == null && ar.result != null) { |
| 911 | request.result = ar.result; // Integer |
| 912 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 913 | // request.result must be set to something non-null |
| 914 | // for the calling thread to unblock |
| 915 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 916 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 917 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 918 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 920 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 921 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 922 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 923 | } |
| 924 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 925 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 928 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 929 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 930 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 931 | request); |
| 932 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 933 | (Pair<Integer, Long>) request.argument; |
| 934 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 935 | reasonWithNetworkTypes.first, |
| 936 | reasonWithNetworkTypes.second, |
| 937 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 938 | break; |
| 939 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 940 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 941 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 944 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 945 | request = (MainThreadRequest)msg.obj; |
| 946 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 947 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 948 | break; |
| 949 | |
| 950 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 951 | ar = (AsyncResult)msg.obj; |
| 952 | request = (MainThreadRequest)ar.userObj; |
| 953 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 954 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 955 | break; |
| 956 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 957 | case CMD_SET_VOICEMAIL_NUMBER: |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 960 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 961 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 962 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 963 | break; |
| 964 | |
| 965 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 966 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 967 | break; |
| 968 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 969 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 970 | request = (MainThreadRequest) msg.obj; |
| 971 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 972 | request); |
| 973 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 974 | break; |
| 975 | |
| 976 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 977 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 978 | break; |
| 979 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 980 | case CMD_PERFORM_NETWORK_SCAN: |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 983 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 984 | break; |
| 985 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 986 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 987 | request = (MainThreadRequest) msg.obj; |
| 988 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 990 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 991 | request.argument; |
| 992 | int callForwardingReason = args.first; |
| 993 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 994 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 995 | } |
| 996 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 999 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1000 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1001 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1004 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1005 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1006 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1007 | // any service for voice call. |
| 1008 | if ((callForwardInfo.serviceClass |
| 1009 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | callForwardingInfo = new CallForwardingInfo(true, |
| 1011 | callForwardInfo.reason, |
| 1012 | callForwardInfo.number, |
| 1013 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1014 | break; |
| 1015 | } |
| 1016 | } |
| 1017 | // Didn't find a call forward info for voice call. |
| 1018 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1019 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1020 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1021 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | } else { |
| 1024 | if (ar.result == null) { |
| 1025 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1026 | } |
| 1027 | if (ar.exception != null) { |
| 1028 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1029 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1030 | int errorCode = TelephonyManager |
| 1031 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1032 | if (ar.exception instanceof CommandException) { |
| 1033 | CommandException.Error error = |
| 1034 | ((CommandException) (ar.exception)).getCommandError(); |
| 1035 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1036 | errorCode = TelephonyManager |
| 1037 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1039 | errorCode = TelephonyManager |
| 1040 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1041 | } |
| 1042 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1044 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1049 | request = (MainThreadRequest) msg.obj; |
| 1050 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1054 | request.argument).first; |
| 1055 | request.phone.setCallForwardingOption( |
| 1056 | callForwardingInfoToSet.isEnabled() |
| 1057 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1058 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1059 | callForwardingInfoToSet.getReason(), |
| 1060 | callForwardingInfoToSet.getNumber(), |
| 1061 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1062 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1064 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1065 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | Consumer<Integer> callback = |
| 1069 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1070 | request.argument).second; |
| 1071 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1072 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1073 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1074 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | if (ar.exception instanceof CommandException) { |
| 1076 | CommandException.Error error = |
| 1077 | ((CommandException) (ar.exception)).getCommandError(); |
| 1078 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1079 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1080 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1082 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1083 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | callback.accept(errorCode); |
| 1087 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1088 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1089 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | request = (MainThreadRequest) msg.obj; |
| 1095 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1096 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1097 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1099 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1101 | ar = (AsyncResult) msg.obj; |
| 1102 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1104 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1105 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1106 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1107 | // Service Class is a bit mask per 3gpp 27.007. |
| 1108 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1109 | if (callForwardResults.length > 1 |
| 1110 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1112 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1114 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1115 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1117 | } |
| 1118 | } else { |
| 1119 | if (ar.result == null) { |
| 1120 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1121 | } |
| 1122 | if (ar.exception != null) { |
| 1123 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1124 | } |
| 1125 | if (ar.exception instanceof CommandException) { |
| 1126 | CommandException.Error error = |
| 1127 | ((CommandException) (ar.exception)).getCommandError(); |
| 1128 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1129 | callForwardingStatus = |
| 1130 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1131 | } |
| 1132 | } |
| 1133 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1135 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1137 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1138 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1139 | request = (MainThreadRequest) msg.obj; |
| 1140 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1141 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1142 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1143 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1144 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1146 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | ar = (AsyncResult) msg.obj; |
| 1148 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1150 | Consumer<Integer> callback = |
| 1151 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1152 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1153 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1154 | if (ar.exception instanceof CommandException) { |
| 1155 | CommandException.Error error = |
| 1156 | ((CommandException) (ar.exception)).getCommandError(); |
| 1157 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1158 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1159 | } else { |
| 1160 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1161 | } |
| 1162 | } else { |
| 1163 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1164 | } |
| 1165 | } else { |
| 1166 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1167 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1168 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1169 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1170 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1171 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1172 | ar = (AsyncResult) msg.obj; |
| 1173 | request = (MainThreadRequest) ar.userObj; |
| 1174 | CellNetworkScanResult cellScanResult; |
| 1175 | if (ar.exception == null && ar.result != null) { |
| 1176 | cellScanResult = new CellNetworkScanResult( |
| 1177 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1178 | (List<OperatorInfo>) ar.result); |
| 1179 | } else { |
| 1180 | if (ar.result == null) { |
| 1181 | loge("getCellNetworkScanResults: Empty response"); |
| 1182 | } |
| 1183 | if (ar.exception != null) { |
| 1184 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1185 | } |
| 1186 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1187 | if (ar.exception instanceof CommandException) { |
| 1188 | CommandException.Error error = |
| 1189 | ((CommandException) (ar.exception)).getCommandError(); |
| 1190 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1191 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1192 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1193 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1194 | } |
| 1195 | } |
| 1196 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1197 | } |
| 1198 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1199 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1200 | break; |
| 1201 | |
| 1202 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1203 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1204 | ManualNetworkSelectionArgument selArg = |
| 1205 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1206 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1207 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1208 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1209 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1210 | break; |
| 1211 | |
| 1212 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1213 | ar = (AsyncResult) msg.obj; |
| 1214 | request = (MainThreadRequest) ar.userObj; |
| 1215 | if (ar.exception == null) { |
| 1216 | request.result = true; |
| 1217 | } else { |
| 1218 | request.result = false; |
| 1219 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1220 | } |
| 1221 | notifyRequester(request); |
| 1222 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1223 | break; |
| 1224 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1225 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1226 | request = (MainThreadRequest) msg.obj; |
| 1227 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1228 | if (defaultPhone != null) { |
| 1229 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1230 | } else { |
| 1231 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1232 | Bundle bundle = new Bundle(); |
| 1233 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1234 | new ModemActivityInfo(0, 0, 0, |
| 1235 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1236 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1237 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1238 | break; |
| 1239 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1240 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1241 | ar = (AsyncResult) msg.obj; |
| 1242 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1243 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1244 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1245 | ModemActivityInfo ret = null; |
| 1246 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1247 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1248 | // Update the last modem activity info and the result of the request. |
| 1249 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1250 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1251 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1252 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1253 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1254 | .getTransmitTimeMillis(); |
| 1255 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1256 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1257 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1258 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1259 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1260 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1261 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1262 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1263 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1264 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1265 | info.getReceiveTimeMillis() |
| 1266 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1267 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1268 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1269 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1270 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1271 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1272 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1273 | } else { |
| 1274 | if (ar.result == null) { |
| 1275 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1276 | error = TelephonyManager.ModemActivityInfoException |
| 1277 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1278 | } else if (ar.exception instanceof CommandException) { |
| 1279 | loge("queryModemActivityInfo: CommandException: " + |
| 1280 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1281 | error = TelephonyManager.ModemActivityInfoException |
| 1282 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1283 | } else { |
| 1284 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1285 | error = TelephonyManager.ModemActivityInfoException |
| 1286 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1287 | } |
| 1288 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1289 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1290 | if (ret != null) { |
| 1291 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1292 | } else { |
| 1293 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1294 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1295 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1296 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1297 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1298 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1299 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1300 | case CMD_SET_ALLOWED_CARRIERS: |
| 1301 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1302 | CarrierRestrictionRules argument = |
| 1303 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1304 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1305 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1309 | ar = (AsyncResult) msg.obj; |
| 1310 | request = (MainThreadRequest) ar.userObj; |
| 1311 | if (ar.exception == null && ar.result != null) { |
| 1312 | request.result = ar.result; |
| 1313 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1314 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1315 | if (ar.exception instanceof CommandException) { |
| 1316 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1317 | CommandException.Error error = |
| 1318 | ((CommandException) (ar.exception)).getCommandError(); |
| 1319 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1320 | request.result = |
| 1321 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1322 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1323 | } else { |
| 1324 | loge("setAllowedCarriers: Unknown exception"); |
| 1325 | } |
| 1326 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1327 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1328 | break; |
| 1329 | |
| 1330 | case CMD_GET_ALLOWED_CARRIERS: |
| 1331 | request = (MainThreadRequest) msg.obj; |
| 1332 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1333 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | |
| 1336 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1337 | ar = (AsyncResult) msg.obj; |
| 1338 | request = (MainThreadRequest) ar.userObj; |
| 1339 | if (ar.exception == null && ar.result != null) { |
| 1340 | request.result = ar.result; |
| 1341 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1342 | request.result = new IllegalStateException( |
| 1343 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1344 | if (ar.result == null) { |
| 1345 | loge("getAllowedCarriers: Empty response"); |
| 1346 | } else if (ar.exception instanceof CommandException) { |
| 1347 | loge("getAllowedCarriers: CommandException: " + |
| 1348 | ar.exception); |
| 1349 | } else { |
| 1350 | loge("getAllowedCarriers: Unknown exception"); |
| 1351 | } |
| 1352 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1353 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1354 | break; |
| 1355 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1356 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1357 | ar = (AsyncResult) msg.obj; |
| 1358 | request = (MainThreadRequest) ar.userObj; |
| 1359 | if (ar.exception == null && ar.result != null) { |
| 1360 | request.result = ar.result; |
| 1361 | } else { |
| 1362 | request.result = new IllegalArgumentException( |
| 1363 | "Failed to retrieve Forbidden Plmns"); |
| 1364 | if (ar.result == null) { |
| 1365 | loge("getForbiddenPlmns: Empty response"); |
| 1366 | } else { |
| 1367 | loge("getForbiddenPlmns: Unknown exception"); |
| 1368 | } |
| 1369 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1370 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1371 | break; |
| 1372 | |
| 1373 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1374 | request = (MainThreadRequest) msg.obj; |
| 1375 | uiccCard = getUiccCardFromRequest(request); |
| 1376 | if (uiccCard == null) { |
| 1377 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1378 | request.result = new IllegalArgumentException( |
| 1379 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1380 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1381 | break; |
| 1382 | } |
| 1383 | Integer appType = (Integer) request.argument; |
| 1384 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1385 | if (uiccApp == null) { |
| 1386 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1387 | + appType); |
| 1388 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1389 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1390 | break; |
| 1391 | } else { |
| 1392 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1393 | + " specified type -- " + appType); |
| 1394 | } |
| 1395 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1396 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1397 | onCompleted); |
| 1398 | break; |
| 1399 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1400 | case CMD_SWITCH_SLOTS: |
| 1401 | request = (MainThreadRequest) msg.obj; |
| 1402 | int[] physicalSlots = (int[]) request.argument; |
| 1403 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1404 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1405 | break; |
| 1406 | |
| 1407 | case EVENT_SWITCH_SLOTS_DONE: |
| 1408 | ar = (AsyncResult) msg.obj; |
| 1409 | request = (MainThreadRequest) ar.userObj; |
| 1410 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1411 | notifyRequester(request); |
| 1412 | break; |
| 1413 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1414 | request = (MainThreadRequest) msg.obj; |
| 1415 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1416 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1417 | break; |
| 1418 | |
| 1419 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception != null) { |
| 1423 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1424 | } else { |
| 1425 | int mode = ((int[]) ar.result)[0]; |
| 1426 | if (mode == 0) { |
| 1427 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1428 | } else { |
| 1429 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1430 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1431 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1432 | notifyRequester(request); |
| 1433 | break; |
| 1434 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1435 | request = (MainThreadRequest) msg.obj; |
| 1436 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1437 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1438 | break; |
| 1439 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1440 | ar = (AsyncResult) msg.obj; |
| 1441 | request = (MainThreadRequest) ar.userObj; |
| 1442 | if (ar.exception != null) { |
| 1443 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1444 | } else { |
| 1445 | request.result = ((int[]) ar.result)[0]; |
| 1446 | } |
| 1447 | notifyRequester(request); |
| 1448 | break; |
| 1449 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1450 | request = (MainThreadRequest) msg.obj; |
| 1451 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1452 | int mode = (int) request.argument; |
| 1453 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1454 | break; |
| 1455 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1456 | ar = (AsyncResult) msg.obj; |
| 1457 | request = (MainThreadRequest) ar.userObj; |
| 1458 | request.result = ar.exception == null; |
| 1459 | notifyRequester(request); |
| 1460 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1461 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1462 | request = (MainThreadRequest) msg.obj; |
| 1463 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1464 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1465 | break; |
| 1466 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1467 | ar = (AsyncResult) msg.obj; |
| 1468 | request = (MainThreadRequest) ar.userObj; |
| 1469 | if (ar.exception != null) { |
| 1470 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1471 | } else { |
| 1472 | request.result = ((int[]) ar.result)[0]; |
| 1473 | } |
| 1474 | notifyRequester(request); |
| 1475 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1476 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1477 | request = (MainThreadRequest) msg.obj; |
| 1478 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1479 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1480 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1481 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1482 | break; |
| 1483 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1484 | ar = (AsyncResult) msg.obj; |
| 1485 | request = (MainThreadRequest) ar.userObj; |
| 1486 | request.result = ar.exception == null; |
| 1487 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1488 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | case CMD_GET_ALL_CELL_INFO: |
| 1490 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1492 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1493 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1494 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1495 | ar = (AsyncResult) msg.obj; |
| 1496 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1497 | // If a timeout occurs, the response will be null |
| 1498 | request.result = (ar.exception == null && ar.result != null) |
| 1499 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1500 | synchronized (request) { |
| 1501 | request.notifyAll(); |
| 1502 | } |
| 1503 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1504 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1505 | request = (MainThreadRequest) msg.obj; |
| 1506 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1507 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1508 | break; |
| 1509 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1510 | ar = (AsyncResult) msg.obj; |
| 1511 | request = (MainThreadRequest) ar.userObj; |
| 1512 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1513 | try { |
| 1514 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1515 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1516 | cb.onError( |
| 1517 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1518 | ar.exception.getClass().getName(), |
| 1519 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1520 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1521 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1522 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1523 | } else { |
| 1524 | // use the result as returned |
| 1525 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1526 | } |
| 1527 | } catch (RemoteException re) { |
| 1528 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1529 | } |
| 1530 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1531 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1532 | request = (MainThreadRequest) msg.obj; |
| 1533 | WorkSource ws = (WorkSource) request.argument; |
| 1534 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1535 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1536 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1537 | } |
| 1538 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1539 | ar = (AsyncResult) msg.obj; |
| 1540 | request = (MainThreadRequest) ar.userObj; |
| 1541 | if (ar.exception == null) { |
| 1542 | request.result = ar.result; |
| 1543 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1544 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1545 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1546 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | synchronized (request) { |
| 1550 | request.notifyAll(); |
| 1551 | } |
| 1552 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1553 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1554 | case CMD_MODEM_REBOOT: |
| 1555 | request = (MainThreadRequest) msg.obj; |
| 1556 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1557 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1558 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1559 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1560 | handleNullReturnEvent(msg, "rebootModem"); |
| 1561 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1562 | case CMD_REQUEST_ENABLE_MODEM: |
| 1563 | request = (MainThreadRequest) msg.obj; |
| 1564 | boolean enable = (boolean) request.argument; |
| 1565 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1566 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1567 | PhoneConfigurationManager.getInstance() |
| 1568 | .enablePhone(request.phone, enable, onCompleted); |
| 1569 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1570 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1571 | ar = (AsyncResult) msg.obj; |
| 1572 | request = (MainThreadRequest) ar.userObj; |
| 1573 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1574 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1575 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1576 | if ((boolean) request.result) { |
| 1577 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1578 | updateModemStateMetrics(); |
| 1579 | } else { |
| 1580 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1581 | + ar.exception); |
| 1582 | } |
| 1583 | notifyRequester(request); |
| 1584 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1585 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1586 | case CMD_GET_MODEM_STATUS: |
| 1587 | request = (MainThreadRequest) msg.obj; |
| 1588 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1589 | PhoneConfigurationManager.getInstance() |
| 1590 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1591 | break; |
| 1592 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1593 | ar = (AsyncResult) msg.obj; |
| 1594 | request = (MainThreadRequest) ar.userObj; |
| 1595 | int id = request.phone.getPhoneId(); |
| 1596 | if (ar.exception == null && ar.result != null) { |
| 1597 | request.result = ar.result; |
| 1598 | //update the cache as modem status has changed |
| 1599 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1600 | (boolean) request.result); |
| 1601 | } else { |
| 1602 | // Return true if modem status cannot be retrieved. For most cases, |
| 1603 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1604 | // and disable modem are not supported. Modem is always on. |
| 1605 | // TODO: this should be fixed in R to support a third |
| 1606 | // status UNKNOWN b/131631629 |
| 1607 | request.result = true; |
| 1608 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1609 | + ar.exception); |
| 1610 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1611 | notifyRequester(request); |
| 1612 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1613 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1614 | request = (MainThreadRequest) msg.obj; |
| 1615 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1616 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1617 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1618 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1619 | break; |
| 1620 | } |
| 1621 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1625 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1626 | args.second.accept(ar.exception == null); |
| 1627 | notifyRequester(request); |
| 1628 | break; |
| 1629 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1630 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1631 | request = (MainThreadRequest) msg.obj; |
| 1632 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1633 | Phone phone = getPhoneFromRequest(request); |
| 1634 | if (phone != null) { |
| 1635 | phone.getSystemSelectionChannels(onCompleted); |
| 1636 | } else { |
| 1637 | loge("getSystemSelectionChannels: No phone object"); |
| 1638 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1639 | notifyRequester(request); |
| 1640 | } |
| 1641 | break; |
| 1642 | } |
| 1643 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1644 | ar = (AsyncResult) msg.obj; |
| 1645 | request = (MainThreadRequest) ar.userObj; |
| 1646 | if (ar.exception == null && ar.result != null) { |
| 1647 | request.result = ar.result; |
| 1648 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1649 | request.result = new IllegalStateException( |
| 1650 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1651 | if (ar.result == null) { |
| 1652 | loge("getSystemSelectionChannels: Empty response"); |
| 1653 | } else { |
| 1654 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1655 | } |
| 1656 | } |
| 1657 | notifyRequester(request); |
| 1658 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1659 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1660 | ar = (AsyncResult) msg.obj; |
| 1661 | request = (MainThreadRequest) ar.userObj; |
| 1662 | if (ar.exception == null && ar.result != null) { |
| 1663 | request.result = ar.result; |
| 1664 | } else { |
| 1665 | request.result = -1; |
| 1666 | loge("Failed to set Forbidden Plmns"); |
| 1667 | if (ar.result == null) { |
| 1668 | loge("setForbidenPlmns: Empty response"); |
| 1669 | } else if (ar.exception != null) { |
| 1670 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1671 | request.result = -1; |
| 1672 | } else { |
| 1673 | loge("setForbiddenPlmns: Unknown exception"); |
| 1674 | } |
| 1675 | } |
| 1676 | notifyRequester(request); |
| 1677 | break; |
| 1678 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1679 | request = (MainThreadRequest) msg.obj; |
| 1680 | uiccCard = getUiccCardFromRequest(request); |
| 1681 | if (uiccCard == null) { |
| 1682 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1683 | request.result = -1; |
| 1684 | notifyRequester(request); |
| 1685 | break; |
| 1686 | } |
| 1687 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1688 | (Pair<Integer, List<String>>) request.argument; |
| 1689 | appType = setFplmnsArgs.first; |
| 1690 | List<String> fplmns = setFplmnsArgs.second; |
| 1691 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1692 | if (uiccApp == null) { |
| 1693 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1694 | request.result = -1; |
| 1695 | loge("Failed to get UICC App"); |
| 1696 | notifyRequester(request); |
| 1697 | } else { |
| 1698 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1699 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1700 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1701 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1702 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1703 | case CMD_ERASE_MODEM_CONFIG: |
| 1704 | request = (MainThreadRequest) msg.obj; |
| 1705 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1706 | defaultPhone.eraseModemConfig(onCompleted); |
| 1707 | break; |
| 1708 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1709 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1710 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1711 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1712 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1713 | request = (MainThreadRequest) msg.obj; |
| 1714 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1715 | notifyRequester(request); |
| 1716 | break; |
| 1717 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1718 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1719 | request = (MainThreadRequest) msg.obj; |
| 1720 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1721 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1722 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1723 | changed.first, changed.second, onCompleted); |
| 1724 | break; |
| 1725 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1726 | ar = (AsyncResult) msg.obj; |
| 1727 | request = (MainThreadRequest) ar.userObj; |
| 1728 | if (ar.exception == null) { |
| 1729 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1730 | // If the operation is successful, update the PIN storage |
| 1731 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1732 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1733 | UiccController.getInstance().getPinStorage() |
| 1734 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1735 | } else { |
| 1736 | request.result = msg.arg1; |
| 1737 | } |
| 1738 | notifyRequester(request); |
| 1739 | break; |
| 1740 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1741 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1742 | request = (MainThreadRequest) msg.obj; |
| 1743 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1744 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1745 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1746 | enabled.first, enabled.second, onCompleted); |
| 1747 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1748 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1749 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | if (ar.exception == null) { |
| 1753 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1754 | // If the operation is successful, update the PIN storage |
| 1755 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1756 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1757 | if (enabled.first) { |
| 1758 | UiccController.getInstance().getPinStorage() |
| 1759 | .storePin(enabled.second, phoneId); |
| 1760 | } else { |
| 1761 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1762 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1763 | } else { |
| 1764 | request.result = msg.arg1; |
| 1765 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1766 | |
| 1767 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1768 | notifyRequester(request); |
| 1769 | break; |
| 1770 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1771 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1772 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1773 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1774 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1775 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1776 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1777 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1778 | |
| 1779 | case CMD_SET_DATA_THROTTLING: { |
| 1780 | request = (MainThreadRequest) msg.obj; |
| 1781 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1782 | DataThrottlingRequest dataThrottlingRequest = |
| 1783 | (DataThrottlingRequest) request.argument; |
| 1784 | Phone phone = getPhoneFromRequest(request); |
| 1785 | if (phone != null) { |
| 1786 | phone.setDataThrottling(onCompleted, |
| 1787 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1788 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1789 | } else { |
| 1790 | loge("setDataThrottling: No phone object"); |
| 1791 | request.result = |
| 1792 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1793 | notifyRequester(request); |
| 1794 | } |
| 1795 | |
| 1796 | break; |
| 1797 | } |
| 1798 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1799 | ar = (AsyncResult) msg.obj; |
| 1800 | request = (MainThreadRequest) ar.userObj; |
| 1801 | |
| 1802 | if (ar.exception == null) { |
| 1803 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1804 | } else if (ar.exception instanceof CommandException) { |
| 1805 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1806 | CommandException.Error error = |
| 1807 | ((CommandException) (ar.exception)).getCommandError(); |
| 1808 | |
| 1809 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1810 | request.result = TelephonyManager |
| 1811 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1812 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1813 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1814 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1815 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1816 | } else { |
| 1817 | request.result = |
| 1818 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1819 | } |
| 1820 | } else { |
| 1821 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1822 | } |
| 1823 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1824 | notifyRequester(request); |
| 1825 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1826 | |
| 1827 | case CMD_SET_SIM_POWER: { |
| 1828 | request = (MainThreadRequest) msg.obj; |
| 1829 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | int stateToSet = |
| 1832 | ((Pair<Integer, IIntegerConsumer>) |
| 1833 | request.argument).first; |
| 1834 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1835 | break; |
| 1836 | } |
| 1837 | case EVENT_SET_SIM_POWER_DONE: { |
| 1838 | ar = (AsyncResult) msg.obj; |
| 1839 | request = (MainThreadRequest) ar.userObj; |
| 1840 | IIntegerConsumer callback = |
| 1841 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1842 | if (ar.exception != null) { |
| 1843 | loge("setSimPower exception: " + ar.exception); |
| 1844 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1845 | .RESULT_ERROR_UNKNOWN; |
| 1846 | if (ar.exception instanceof CommandException) { |
| 1847 | CommandException.Error error = |
| 1848 | ((CommandException) (ar.exception)).getCommandError(); |
| 1849 | if (error == CommandException.Error.SIM_ERR) { |
| 1850 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1851 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1852 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1853 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1854 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1855 | } else { |
| 1856 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1857 | } |
| 1858 | } |
| 1859 | try { |
| 1860 | callback.accept(errorCode); |
| 1861 | } catch (RemoteException e) { |
| 1862 | // Ignore if the remote process is no longer available to call back. |
| 1863 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1864 | } |
| 1865 | } else { |
| 1866 | try { |
| 1867 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1868 | } catch (RemoteException e) { |
| 1869 | // Ignore if the remote process is no longer available to call back. |
| 1870 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1871 | } |
| 1872 | } |
| 1873 | break; |
| 1874 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1875 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1876 | request = (MainThreadRequest) msg.obj; |
| 1877 | |
| 1878 | final Phone phone = getPhoneFromRequest(request); |
| 1879 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1880 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
| 1884 | |
| 1885 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1886 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1887 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1888 | request); |
| 1889 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1890 | request.subId, pair.first /*callingUid*/, |
| 1891 | pair.second /*request*/, onCompleted); |
| 1892 | break; |
| 1893 | } |
| 1894 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
| 1897 | // request.result will be the exception of ar if present, true otherwise. |
| 1898 | // Be cautious not to leave result null which will wait() forever |
| 1899 | request.result = ar.exception != null ? ar.exception : true; |
| 1900 | notifyRequester(request); |
| 1901 | break; |
| 1902 | } |
| 1903 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1904 | request = (MainThreadRequest) msg.obj; |
| 1905 | |
| 1906 | Phone phone = getPhoneFromRequest(request); |
| 1907 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1908 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1909 | notifyRequester(request); |
| 1910 | break; |
| 1911 | } |
| 1912 | |
| 1913 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1914 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1915 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1916 | request); |
| 1917 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1918 | request.subId, pair.first /*callingUid*/, |
| 1919 | pair.second /*request*/, onCompleted); |
| 1920 | break; |
| 1921 | } |
| 1922 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1923 | ar = (AsyncResult) msg.obj; |
| 1924 | request = (MainThreadRequest) ar.userObj; |
| 1925 | request.result = ar.exception != null ? ar.exception : true; |
| 1926 | notifyRequester(request); |
| 1927 | break; |
| 1928 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1929 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1930 | case CMD_GET_SLICING_CONFIG: { |
| 1931 | request = (MainThreadRequest) msg.obj; |
| 1932 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 1933 | request.phone.getSlicingConfig(onCompleted); |
| 1934 | break; |
| 1935 | } |
| 1936 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 1937 | ar = (AsyncResult) msg.obj; |
| 1938 | request = (MainThreadRequest) ar.userObj; |
| 1939 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1940 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1941 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1942 | Bundle bundle = new Bundle(); |
| 1943 | int resultCode = 0; |
| 1944 | if (ar.exception != null) { |
| 1945 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 1946 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1947 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1948 | } else if (ar.result == null) { |
| 1949 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1950 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1951 | } else { |
| 1952 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1953 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 1954 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 1958 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 1959 | } |
| 1960 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 1961 | result.send(resultCode, bundle); |
| 1962 | notifyRequester(request); |
| 1963 | break; |
| 1964 | } |
| 1965 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1966 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1967 | request = (MainThreadRequest) msg.obj; |
| 1968 | request.result = |
| 1969 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1970 | notifyRequester(request); |
| 1971 | break; |
| 1972 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1973 | default: |
| 1974 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1975 | break; |
| 1976 | } |
| 1977 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1978 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1979 | private void notifyRequester(MainThreadRequest request) { |
| 1980 | synchronized (request) { |
| 1981 | request.notifyAll(); |
| 1982 | } |
| 1983 | } |
| 1984 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1985 | private void handleNullReturnEvent(Message msg, String command) { |
| 1986 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1987 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1988 | if (ar.exception == null) { |
| 1989 | request.result = true; |
| 1990 | } else { |
| 1991 | request.result = false; |
| 1992 | if (ar.exception instanceof CommandException) { |
| 1993 | loge(command + ": CommandException: " + ar.exception); |
| 1994 | } else { |
| 1995 | loge(command + ": Unknown exception"); |
| 1996 | } |
| 1997 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1998 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1999 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | /** |
| 2003 | * Posts the specified command to be executed on the main thread, |
| 2004 | * waits for the request to complete, and returns the result. |
| 2005 | * @see #sendRequestAsync |
| 2006 | */ |
| 2007 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2008 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2009 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /** |
| 2013 | * Posts the specified command to be executed on the main thread, |
| 2014 | * waits for the request to complete, and returns the result. |
| 2015 | * @see #sendRequestAsync |
| 2016 | */ |
| 2017 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2018 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2019 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * Posts the specified command to be executed on the main thread, |
| 2024 | * waits for the request to complete, and returns the result. |
| 2025 | * @see #sendRequestAsync |
| 2026 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2027 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2028 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2029 | } |
| 2030 | |
| 2031 | /** |
| 2032 | * Posts the specified command to be executed on the main thread, |
| 2033 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2034 | * if not timeout or null otherwise. |
| 2035 | * @see #sendRequestAsync |
| 2036 | */ |
| 2037 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2038 | long timeoutInMs) { |
| 2039 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | /** |
| 2043 | * Posts the specified command to be executed on the main thread, |
| 2044 | * waits for the request to complete, and returns the result. |
| 2045 | * @see #sendRequestAsync |
| 2046 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2047 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2048 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | /** |
| 2052 | * Posts the specified command to be executed on the main thread, |
| 2053 | * waits for the request to complete, and returns the result. |
| 2054 | * @see #sendRequestAsync |
| 2055 | */ |
| 2056 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2057 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2058 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2062 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2063 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2064 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2065 | * @see #sendRequestAsync |
| 2066 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2067 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2068 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2070 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2071 | } |
| 2072 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2073 | MainThreadRequest request = null; |
| 2074 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2075 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2076 | } else if (phone != null) { |
| 2077 | request = new MainThreadRequest(argument, phone, workSource); |
| 2078 | } else { |
| 2079 | request = new MainThreadRequest(argument, subId, workSource); |
| 2080 | } |
| 2081 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2082 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2083 | msg.sendToTarget(); |
| 2084 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2085 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2087 | if (timeoutInMs >= 0) { |
| 2088 | // Wait for at least timeoutInMs before returning null request result |
| 2089 | long now = SystemClock.elapsedRealtime(); |
| 2090 | long deadline = now + timeoutInMs; |
| 2091 | while (request == null && now < deadline) { |
| 2092 | try { |
| 2093 | request.wait(deadline - now); |
| 2094 | } catch (InterruptedException e) { |
| 2095 | // Do nothing, go back and check if request is completed or timeout |
| 2096 | } finally { |
| 2097 | now = SystemClock.elapsedRealtime(); |
| 2098 | } |
| 2099 | } |
| 2100 | } else { |
| 2101 | // Wait for the request to complete |
| 2102 | while (request.result == null) { |
| 2103 | try { |
| 2104 | request.wait(); |
| 2105 | } catch (InterruptedException e) { |
| 2106 | // Do nothing, go back and wait until the request is complete |
| 2107 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2111 | if (request.result == null) { |
| 2112 | Log.wtf(LOG_TAG, |
| 2113 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | return request.result; |
| 2116 | } |
| 2117 | |
| 2118 | /** |
| 2119 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2120 | * Posts the specified command to be executed on the main thread, and |
| 2121 | * returns immediately. |
| 2122 | * @see #sendRequest |
| 2123 | */ |
| 2124 | private void sendRequestAsync(int command) { |
| 2125 | mMainThreadHandler.sendEmptyMessage(command); |
| 2126 | } |
| 2127 | |
| 2128 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2129 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2130 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2131 | */ |
| 2132 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2133 | sendRequestAsync(command, argument, null, null); |
| 2134 | } |
| 2135 | |
| 2136 | /** |
| 2137 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2138 | * @see {@link #sendRequest(int,Object)} |
| 2139 | */ |
| 2140 | private void sendRequestAsync( |
| 2141 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2142 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2143 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2144 | msg.sendToTarget(); |
| 2145 | } |
| 2146 | |
| 2147 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2148 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2149 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2150 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2151 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2152 | synchronized (PhoneInterfaceManager.class) { |
| 2153 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2154 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | } else { |
| 2156 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2157 | } |
| 2158 | return sInstance; |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2163 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2164 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2166 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2167 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2169 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2171 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2172 | mTelephonySharedPreferences = |
| 2173 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2174 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2175 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2176 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2177 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2178 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2179 | publish(); |
| 2180 | } |
| 2181 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2182 | private Phone getDefaultPhone() { |
| 2183 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2184 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2185 | } |
| 2186 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2187 | private void publish() { |
| 2188 | if (DBG) log("publish: " + this); |
| 2189 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2190 | TelephonyFrameworkInitializer |
| 2191 | .getTelephonyServiceManager() |
| 2192 | .getTelephonyServiceRegisterer() |
| 2193 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2196 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2197 | if (request.phone != null) { |
| 2198 | return request.phone; |
| 2199 | } else { |
| 2200 | return getPhoneFromSubId(request.subId); |
| 2201 | } |
| 2202 | } |
| 2203 | |
| 2204 | private Phone getPhoneFromSubId(int subId) { |
| 2205 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2206 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2207 | } |
| 2208 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2209 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2210 | Phone phone = getPhoneFromRequest(request); |
| 2211 | return phone == null ? null : |
| 2212 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2213 | } |
| 2214 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2215 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2216 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2217 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2218 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2219 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2220 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2221 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2222 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2223 | } |
| 2224 | |
| 2225 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2226 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2227 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2230 | private boolean isImsAvailableOnDevice() { |
| 2231 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2232 | if (pm == null) { |
| 2233 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2234 | // so do not throw error and allow. |
| 2235 | return true; |
| 2236 | } |
| 2237 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2238 | } |
| 2239 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2240 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2241 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2242 | } |
| 2243 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2244 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | if (DBG) log("dial: " + number); |
| 2246 | // No permission check needed here: This is just a wrapper around the |
| 2247 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2248 | // the UI before it does anything. |
| 2249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2250 | final long identity = Binder.clearCallingIdentity(); |
| 2251 | try { |
| 2252 | String url = createTelUrl(number); |
| 2253 | if (url == null) { |
| 2254 | return; |
| 2255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2258 | PhoneConstants.State state = mCM.getState(subId); |
| 2259 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2260 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2261 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2262 | mApp.startActivity(intent); |
| 2263 | } |
| 2264 | } finally { |
| 2265 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2270 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2273 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | if (DBG) log("call: " + number); |
| 2275 | |
| 2276 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2277 | // need to do a permission check since we're calling startActivity() |
| 2278 | // from the context of the phone app. |
| 2279 | enforceCallPermission(); |
| 2280 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2281 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | != AppOpsManager.MODE_ALLOWED) { |
| 2283 | return; |
| 2284 | } |
| 2285 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | final long identity = Binder.clearCallingIdentity(); |
| 2287 | try { |
| 2288 | String url = createTelUrl(number); |
| 2289 | if (url == null) { |
| 2290 | return; |
| 2291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2293 | boolean isValid = false; |
| 2294 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2295 | if (slist != null) { |
| 2296 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2297 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2298 | isValid = true; |
| 2299 | break; |
| 2300 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2301 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2303 | if (!isValid) { |
| 2304 | return; |
| 2305 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2306 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2307 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2308 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2309 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2310 | mApp.startActivity(intent); |
| 2311 | } finally { |
| 2312 | Binder.restoreCallingIdentity(identity); |
| 2313 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2316 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2317 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2318 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2319 | } |
| 2320 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2321 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2322 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2323 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2324 | } |
| 2325 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2326 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2328 | |
| 2329 | final long identity = Binder.clearCallingIdentity(); |
| 2330 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2331 | Phone phone = getPhone(subId); |
| 2332 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2333 | checkSimPin.start(); |
| 2334 | return checkSimPin.unlockSim(null, pin); |
| 2335 | } finally { |
| 2336 | Binder.restoreCallingIdentity(identity); |
| 2337 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2340 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2342 | |
| 2343 | final long identity = Binder.clearCallingIdentity(); |
| 2344 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2345 | Phone phone = getPhone(subId); |
| 2346 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2347 | checkSimPuk.start(); |
| 2348 | return checkSimPuk.unlockSim(puk, pin); |
| 2349 | } finally { |
| 2350 | Binder.restoreCallingIdentity(identity); |
| 2351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2355 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | * a synchronous one. |
| 2357 | */ |
| 2358 | private static class UnlockSim extends Thread { |
| 2359 | |
| 2360 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2361 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | |
| 2363 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2364 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2365 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2366 | |
| 2367 | // For replies from SimCard interface |
| 2368 | private Handler mHandler; |
| 2369 | |
| 2370 | // For async handler to identify request type |
| 2371 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2372 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2373 | UnlockSim(int phoneId, IccCard simCard) { |
| 2374 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | mSimCard = simCard; |
| 2376 | } |
| 2377 | |
| 2378 | @Override |
| 2379 | public void run() { |
| 2380 | Looper.prepare(); |
| 2381 | synchronized (UnlockSim.this) { |
| 2382 | mHandler = new Handler() { |
| 2383 | @Override |
| 2384 | public void handleMessage(Message msg) { |
| 2385 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2386 | switch (msg.what) { |
| 2387 | case SUPPLY_PIN_COMPLETE: |
| 2388 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2389 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2390 | mRetryCount = msg.arg1; |
| 2391 | if (ar.exception != null) { |
| 2392 | if (ar.exception instanceof CommandException && |
| 2393 | ((CommandException)(ar.exception)).getCommandError() |
| 2394 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2395 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2396 | } //When UiccCardApp dispose,handle message and return exception |
| 2397 | else if (ar.exception instanceof CommandException && |
| 2398 | ((CommandException) (ar.exception)).getCommandError() |
| 2399 | == CommandException.Error.ABORTED) { |
| 2400 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2401 | } else { |
| 2402 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2403 | } |
| 2404 | } else { |
| 2405 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2406 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2407 | mDone = true; |
| 2408 | UnlockSim.this.notifyAll(); |
| 2409 | } |
| 2410 | break; |
| 2411 | } |
| 2412 | } |
| 2413 | }; |
| 2414 | UnlockSim.this.notifyAll(); |
| 2415 | } |
| 2416 | Looper.loop(); |
| 2417 | } |
| 2418 | |
| 2419 | /* |
| 2420 | * Use PIN or PUK to unlock SIM card |
| 2421 | * |
| 2422 | * If PUK is null, unlock SIM card with PIN |
| 2423 | * |
| 2424 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2425 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2426 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | |
| 2428 | while (mHandler == null) { |
| 2429 | try { |
| 2430 | wait(); |
| 2431 | } catch (InterruptedException e) { |
| 2432 | Thread.currentThread().interrupt(); |
| 2433 | } |
| 2434 | } |
| 2435 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2436 | |
| 2437 | if (puk == null) { |
| 2438 | mSimCard.supplyPin(pin, callback); |
| 2439 | } else { |
| 2440 | mSimCard.supplyPuk(puk, pin, callback); |
| 2441 | } |
| 2442 | |
| 2443 | while (!mDone) { |
| 2444 | try { |
| 2445 | Log.d(LOG_TAG, "wait for done"); |
| 2446 | wait(); |
| 2447 | } catch (InterruptedException e) { |
| 2448 | // Restore the interrupted status |
| 2449 | Thread.currentThread().interrupt(); |
| 2450 | } |
| 2451 | } |
| 2452 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2453 | int[] resultArray = new int[2]; |
| 2454 | resultArray[0] = mResult; |
| 2455 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2456 | |
| 2457 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2458 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2459 | } |
| 2460 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2461 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2465 | /** |
| 2466 | * This method has been removed due to privacy and stability concerns. |
| 2467 | */ |
| 2468 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2469 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2470 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2471 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2474 | @Override |
| 2475 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2476 | mApp.getSystemService(AppOpsManager.class) |
| 2477 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2478 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2479 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2480 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2481 | // Callers targeting S have no business invoking this method. |
| 2482 | return; |
| 2483 | } |
| 2484 | |
| 2485 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2486 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2487 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2488 | .setCallingPackage(callingPackage) |
| 2489 | .setCallingFeatureId(null) |
| 2490 | .setCallingPid(Binder.getCallingPid()) |
| 2491 | .setCallingUid(Binder.getCallingUid()) |
| 2492 | .setMethod("updateServiceLocation") |
| 2493 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2494 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2495 | .build()); |
| 2496 | // Apps that lack location permission have no business calling this method; |
| 2497 | // however, because no permission was declared in the public API, denials must |
| 2498 | // all be "soft". |
| 2499 | switch (locationResult) { |
| 2500 | case DENIED_HARD: /* fall through */ |
| 2501 | case DENIED_SOFT: |
| 2502 | return; |
| 2503 | } |
| 2504 | |
| 2505 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2508 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2510 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | } |
| 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2514 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2517 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2518 | @Override |
| 2519 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2520 | return isRadioOnWithFeature(callingPackage, null); |
| 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | @Override |
| 2525 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2526 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2527 | callingFeatureId); |
| 2528 | } |
| 2529 | |
| 2530 | @Deprecated |
| 2531 | @Override |
| 2532 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2533 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2536 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2537 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2538 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2539 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2540 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2541 | return false; |
| 2542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | return isRadioOnForSubscriber(subId); |
| 2547 | } finally { |
| 2548 | Binder.restoreCallingIdentity(identity); |
| 2549 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2553 | final long identity = Binder.clearCallingIdentity(); |
| 2554 | try { |
| 2555 | final Phone phone = getPhone(subId); |
| 2556 | if (phone != null) { |
| 2557 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2558 | } else { |
| 2559 | return false; |
| 2560 | } |
| 2561 | } finally { |
| 2562 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2567 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2569 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2570 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2571 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | |
| 2573 | final long identity = Binder.clearCallingIdentity(); |
| 2574 | try { |
| 2575 | final Phone phone = getPhone(subId); |
| 2576 | if (phone != null) { |
| 2577 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2578 | } |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2581 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2585 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2588 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | final Phone phone = getPhone(subId); |
| 2594 | if (phone == null) { |
| 2595 | return false; |
| 2596 | } |
| 2597 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2598 | toggleRadioOnOffForSubscriber(subId); |
| 2599 | } |
| 2600 | return true; |
| 2601 | } finally { |
| 2602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2605 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2606 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2607 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2608 | /* |
| 2609 | * If any of the Radios are available, it will need to be |
| 2610 | * shutdown. So return true if any Radio is available. |
| 2611 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2612 | final long identity = Binder.clearCallingIdentity(); |
| 2613 | try { |
| 2614 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2615 | Phone phone = PhoneFactory.getPhone(i); |
| 2616 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2617 | } |
| 2618 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2619 | return false; |
| 2620 | } finally { |
| 2621 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2622 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2623 | } |
| 2624 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2626 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | enforceModifyPermission(); |
| 2628 | |
| 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2632 | logv("Shutting down Phone " + i); |
| 2633 | shutdownRadioUsingPhoneId(i); |
| 2634 | } |
| 2635 | } finally { |
| 2636 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2641 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2642 | if (phone != null && phone.isRadioAvailable()) { |
| 2643 | phone.shutdownRadio(); |
| 2644 | } |
| 2645 | } |
| 2646 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2648 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2649 | |
| 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
| 2652 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2653 | if (defaultPhone != null) { |
| 2654 | defaultPhone.setRadioPower(turnOn); |
| 2655 | return true; |
| 2656 | } else { |
| 2657 | loge("There's no default phone."); |
| 2658 | return false; |
| 2659 | } |
| 2660 | } finally { |
| 2661 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2662 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2665 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | |
| 2668 | final long identity = Binder.clearCallingIdentity(); |
| 2669 | try { |
| 2670 | final Phone phone = getPhone(subId); |
| 2671 | if (phone != null) { |
| 2672 | phone.setRadioPower(turnOn); |
| 2673 | return true; |
| 2674 | } else { |
| 2675 | return false; |
| 2676 | } |
| 2677 | } finally { |
| 2678 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2679 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2682 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2683 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | public boolean enableDataConnectivity() { |
| 2685 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2686 | |
| 2687 | final long identity = Binder.clearCallingIdentity(); |
| 2688 | try { |
| 2689 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2690 | final Phone phone = getPhone(subId); |
| 2691 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2692 | phone.getDataEnabledSettings().setDataEnabled( |
| 2693 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | return true; |
| 2695 | } else { |
| 2696 | return false; |
| 2697 | } |
| 2698 | } finally { |
| 2699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2703 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2704 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | public boolean disableDataConnectivity() { |
| 2706 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2707 | |
| 2708 | final long identity = Binder.clearCallingIdentity(); |
| 2709 | try { |
| 2710 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2711 | final Phone phone = getPhone(subId); |
| 2712 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2713 | phone.getDataEnabledSettings().setDataEnabled( |
| 2714 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | return true; |
| 2716 | } else { |
| 2717 | return false; |
| 2718 | } |
| 2719 | } finally { |
| 2720 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2724 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2725 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | final long identity = Binder.clearCallingIdentity(); |
| 2727 | try { |
| 2728 | final Phone phone = getPhone(subId); |
| 2729 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2730 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2731 | } else { |
| 2732 | return false; |
| 2733 | } |
| 2734 | } finally { |
| 2735 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2736 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2740 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2743 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2744 | enforceCallPermission(); |
| 2745 | |
| 2746 | final long identity = Binder.clearCallingIdentity(); |
| 2747 | try { |
| 2748 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2749 | return; |
| 2750 | } |
| 2751 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2752 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(identity); |
| 2755 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2756 | }; |
| 2757 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2758 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2760 | |
| 2761 | final long identity = Binder.clearCallingIdentity(); |
| 2762 | try { |
| 2763 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2764 | return false; |
| 2765 | } |
| 2766 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2772 | /** |
| 2773 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2774 | * tag on getCallState Binder call. |
| 2775 | */ |
| 2776 | @Deprecated |
| 2777 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2779 | if (CompatChanges.isChangeEnabled( |
| 2780 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2781 | Binder.getCallingUid())) { |
| 2782 | // Do not allow this API to be called on API version 31+, it should only be |
| 2783 | // called on old apps using this Binder call directly. |
| 2784 | throw new SecurityException("This method can only be used for applications " |
| 2785 | + "targeting API version 30 or less."); |
| 2786 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | final long identity = Binder.clearCallingIdentity(); |
| 2788 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2789 | Phone phone = getPhone(getDefaultSubscription()); |
| 2790 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2791 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(identity); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | @Override |
| 2798 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2799 | if (CompatChanges.isChangeEnabled( |
| 2800 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2801 | Binder.getCallingUid())) { |
| 2802 | // Check READ_PHONE_STATE for API version 31+ |
| 2803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2804 | featureId, "getCallStateForSubscription")) { |
| 2805 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2806 | + "targeting API level 31+."); |
| 2807 | } |
| 2808 | } |
| 2809 | final long identity = Binder.clearCallingIdentity(); |
| 2810 | try { |
| 2811 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2813 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2814 | } finally { |
| 2815 | Binder.restoreCallingIdentity(identity); |
| 2816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2819 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2820 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2821 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2822 | } |
| 2823 | |
| 2824 | @Override |
| 2825 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | final long identity = Binder.clearCallingIdentity(); |
| 2827 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2828 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | if (phone != null) { |
| 2830 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2831 | } else { |
| 2832 | return PhoneConstantConversions.convertDataState( |
| 2833 | PhoneConstants.DataState.DISCONNECTED); |
| 2834 | } |
| 2835 | } finally { |
| 2836 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2837 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2840 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2841 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2842 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2843 | } |
| 2844 | |
| 2845 | @Override |
| 2846 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2849 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 | if (phone != null) { |
| 2851 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2852 | } else { |
| 2853 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2854 | } |
| 2855 | } finally { |
| 2856 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2857 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2861 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2862 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2863 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2864 | |
| 2865 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2866 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2867 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2868 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2869 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2870 | .setCallingPid(Binder.getCallingPid()) |
| 2871 | .setCallingUid(Binder.getCallingUid()) |
| 2872 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2873 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2874 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2875 | .build()); |
| 2876 | switch (locationResult) { |
| 2877 | case DENIED_HARD: |
| 2878 | throw new SecurityException("Not allowed to access cell location"); |
| 2879 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2880 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2881 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2884 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | final long identity = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2888 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2889 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(identity); |
| 2892 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2896 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2897 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2898 | // registered cell info, so return a NULL country instead. |
| 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2901 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2902 | // Get default phone in this case. |
| 2903 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2904 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2905 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2907 | if (phone == null) return ""; |
| 2908 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2909 | if (sst == null) return ""; |
| 2910 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2911 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2912 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2913 | } finally { |
| 2914 | Binder.restoreCallingIdentity(identity); |
| 2915 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2918 | /** |
| 2919 | * This method was removed due to potential issues caused by performing partial |
| 2920 | * updates of service state, and lack of a credible use case. |
| 2921 | * |
| 2922 | * This has the ability to break the telephony implementation by disabling notification of |
| 2923 | * changes in device connectivity. DO NOT USE THIS! |
| 2924 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2925 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2926 | public void enableLocationUpdates() { |
| 2927 | mApp.enforceCallingOrSelfPermission( |
| 2928 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2931 | /** |
| 2932 | * This method was removed due to potential issues caused by performing partial |
| 2933 | * updates of service state, and lack of a credible use case. |
| 2934 | * |
| 2935 | * This has the ability to break the telephony implementation by disabling notification of |
| 2936 | * changes in device connectivity. DO NOT USE THIS! |
| 2937 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2938 | @Override |
| 2939 | public void disableLocationUpdates() { |
| 2940 | mApp.enforceCallingOrSelfPermission( |
| 2941 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2942 | } |
| 2943 | |
| 2944 | @Override |
| 2945 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2946 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2947 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2948 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2949 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2950 | throw new SecurityException( |
| 2951 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2952 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2953 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2954 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2955 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2956 | return null; |
| 2957 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2958 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2959 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2960 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2961 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2962 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2963 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2964 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2965 | for (CellInfo ci : info) { |
| 2966 | if (ci instanceof CellInfoGsm) { |
| 2967 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2968 | } else if (ci instanceof CellInfoWcdma) { |
| 2969 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2970 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2971 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2972 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | } |
| 2974 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2975 | private List<CellInfo> getCachedCellInfo() { |
| 2976 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2977 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2978 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2979 | if (info != null) cellInfos.addAll(info); |
| 2980 | } |
| 2981 | return cellInfos; |
| 2982 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2983 | |
| 2984 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2985 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2986 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2987 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2988 | |
| 2989 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2990 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2991 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2992 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2993 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2994 | .setCallingPid(Binder.getCallingPid()) |
| 2995 | .setCallingUid(Binder.getCallingUid()) |
| 2996 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2997 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2998 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2999 | .build()); |
| 3000 | switch (locationResult) { |
| 3001 | case DENIED_HARD: |
| 3002 | throw new SecurityException("Not allowed to access cell info"); |
| 3003 | case DENIED_SOFT: |
| 3004 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3007 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3008 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3009 | return getCachedCellInfo(); |
| 3010 | } |
| 3011 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3012 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3013 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3017 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3018 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3019 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | if (info != null) cellInfos.addAll(info); |
| 3021 | } |
| 3022 | return cellInfos; |
| 3023 | } finally { |
| 3024 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3025 | } |
| 3026 | } |
| 3027 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3028 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3029 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3030 | String callingFeatureId) { |
| 3031 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3032 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3036 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3037 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3038 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3039 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3042 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3043 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3044 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3045 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3046 | |
| 3047 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3048 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3049 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3050 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3051 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3052 | .setCallingPid(Binder.getCallingPid()) |
| 3053 | .setCallingUid(Binder.getCallingUid()) |
| 3054 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3055 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3056 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3057 | .build()); |
| 3058 | switch (locationResult) { |
| 3059 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3060 | if (TelephonyPermissions |
| 3061 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3062 | // Safetynet logging for b/154934934 |
| 3063 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3064 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3065 | throw new SecurityException("Not allowed to access cell info"); |
| 3066 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3067 | if (TelephonyPermissions |
| 3068 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3069 | // Safetynet logging for b/154934934 |
| 3070 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3071 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3072 | try { |
| 3073 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3074 | } catch (RemoteException re) { |
| 3075 | // Drop without consequences |
| 3076 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3077 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3080 | |
| 3081 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3082 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3083 | |
| 3084 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3085 | } |
| 3086 | |
| 3087 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3089 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3090 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | |
| 3092 | final long identity = Binder.clearCallingIdentity(); |
| 3093 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3094 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3095 | } finally { |
| 3096 | Binder.restoreCallingIdentity(identity); |
| 3097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3100 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3101 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3102 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3103 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3104 | return null; |
| 3105 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3106 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3107 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3108 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3109 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3110 | return null; |
| 3111 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | |
| 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
| 3115 | return phone.getImei(); |
| 3116 | } finally { |
| 3117 | Binder.restoreCallingIdentity(identity); |
| 3118 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3122 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3123 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3124 | String tac = null; |
| 3125 | if (phone != null) { |
| 3126 | String imei = phone.getImei(); |
| 3127 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3128 | } |
| 3129 | return tac; |
| 3130 | } |
| 3131 | |
| 3132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3133 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3134 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3135 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3136 | return null; |
| 3137 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3138 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3139 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3140 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3141 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3142 | return null; |
| 3143 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3144 | |
| 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | return phone.getMeid(); |
| 3148 | } finally { |
| 3149 | Binder.restoreCallingIdentity(identity); |
| 3150 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3154 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3155 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3156 | String manufacturerCode = null; |
| 3157 | if (phone != null) { |
| 3158 | String meid = phone.getMeid(); |
| 3159 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3160 | } |
| 3161 | return manufacturerCode; |
| 3162 | } |
| 3163 | |
| 3164 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3165 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3166 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3167 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3168 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3169 | return null; |
| 3170 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3171 | int subId = phone.getSubId(); |
| 3172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3173 | mApp, subId, callingPackage, callingFeatureId, |
| 3174 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3175 | return null; |
| 3176 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3177 | |
| 3178 | final long identity = Binder.clearCallingIdentity(); |
| 3179 | try { |
| 3180 | return phone.getDeviceSvn(); |
| 3181 | } finally { |
| 3182 | Binder.restoreCallingIdentity(identity); |
| 3183 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3186 | @Override |
| 3187 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | final Phone phone = getPhone(subId); |
| 3191 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3192 | } finally { |
| 3193 | Binder.restoreCallingIdentity(identity); |
| 3194 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | @Override |
| 3198 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | final long identity = Binder.clearCallingIdentity(); |
| 3200 | try { |
| 3201 | final Phone phone = getPhone(subId); |
| 3202 | return phone == null ? null : phone.getCarrierName(); |
| 3203 | } finally { |
| 3204 | Binder.restoreCallingIdentity(identity); |
| 3205 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3206 | } |
| 3207 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3208 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3209 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | final Phone phone = getPhone(subId); |
| 3213 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3214 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
| 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3221 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3222 | final long identity = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3225 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3226 | } finally { |
| 3227 | Binder.restoreCallingIdentity(identity); |
| 3228 | } |
| 3229 | } |
| 3230 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3231 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3232 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3233 | if (!isSubscriptionMccMnc) { |
| 3234 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3235 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3236 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3237 | if (phone == null) { |
| 3238 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3239 | } |
| 3240 | final long identity = Binder.clearCallingIdentity(); |
| 3241 | try { |
| 3242 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3243 | } finally { |
| 3244 | Binder.restoreCallingIdentity(identity); |
| 3245 | } |
| 3246 | } |
| 3247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | // |
| 3249 | // Internal helper methods. |
| 3250 | // |
| 3251 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3252 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3253 | * Make sure the caller is the calling package itself |
| 3254 | * |
| 3255 | * @throws SecurityException if the caller is not the calling package |
| 3256 | */ |
| 3257 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3258 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3259 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3260 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3261 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3262 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3263 | } catch (PackageManager.NameNotFoundException e) { |
| 3264 | // packageUid is -1 |
| 3265 | } |
| 3266 | if (packageUid != callingUid) { |
| 3267 | throw new SecurityException(message + ": Package " + callingPackage |
| 3268 | + " does not belong to " + callingUid); |
| 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3273 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3274 | * |
| 3275 | * @throws SecurityException if the caller does not have the required permission |
| 3276 | */ |
| 3277 | private void enforceModifyPermission() { |
| 3278 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3279 | } |
| 3280 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3281 | /** |
| 3282 | * Make sure the caller is system. |
| 3283 | * |
| 3284 | * @throws SecurityException if the caller is not system. |
| 3285 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3286 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3287 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3288 | throw new SecurityException("Caller must be system"); |
| 3289 | } |
| 3290 | } |
| 3291 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3292 | private void enforceActiveEmergencySessionPermission() { |
| 3293 | mApp.enforceCallingOrSelfPermission( |
| 3294 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3295 | } |
| 3296 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3297 | /** |
| 3298 | * Make sure the caller has the CALL_PHONE permission. |
| 3299 | * |
| 3300 | * @throws SecurityException if the caller does not have the required permission |
| 3301 | */ |
| 3302 | private void enforceCallPermission() { |
| 3303 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3304 | } |
| 3305 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3306 | private void enforceSettingsPermission() { |
| 3307 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3310 | private void enforceRebootPermission() { |
| 3311 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3312 | } |
| 3313 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3314 | private String createTelUrl(String number) { |
| 3315 | if (TextUtils.isEmpty(number)) { |
| 3316 | return null; |
| 3317 | } |
| 3318 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3319 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3322 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3323 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3324 | } |
| 3325 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3326 | private static void logv(String msg) { |
| 3327 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3328 | } |
| 3329 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3330 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3331 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3332 | } |
| 3333 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3334 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3335 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3336 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3337 | } |
| 3338 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3339 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3340 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3341 | final long identity = Binder.clearCallingIdentity(); |
| 3342 | try { |
| 3343 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3344 | if (phone == null) { |
| 3345 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3346 | } else { |
| 3347 | return phone.getPhoneType(); |
| 3348 | } |
| 3349 | } finally { |
| 3350 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3351 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | /** |
| 3355 | * Returns the CDMA ERI icon index to display |
| 3356 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3357 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3358 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3359 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3360 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3363 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3364 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3365 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3366 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3367 | mApp, subId, callingPackage, callingFeatureId, |
| 3368 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3369 | return -1; |
| 3370 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3371 | |
| 3372 | final long identity = Binder.clearCallingIdentity(); |
| 3373 | try { |
| 3374 | final Phone phone = getPhone(subId); |
| 3375 | if (phone != null) { |
| 3376 | return phone.getCdmaEriIconIndex(); |
| 3377 | } else { |
| 3378 | return -1; |
| 3379 | } |
| 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | /** |
| 3386 | * Returns the CDMA ERI icon mode, |
| 3387 | * 0 - ON |
| 3388 | * 1 - FLASHING |
| 3389 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3390 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3391 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3392 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3393 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3396 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3397 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3398 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3399 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3400 | mApp, subId, callingPackage, callingFeatureId, |
| 3401 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3402 | return -1; |
| 3403 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3404 | |
| 3405 | final long identity = Binder.clearCallingIdentity(); |
| 3406 | try { |
| 3407 | final Phone phone = getPhone(subId); |
| 3408 | if (phone != null) { |
| 3409 | return phone.getCdmaEriIconMode(); |
| 3410 | } else { |
| 3411 | return -1; |
| 3412 | } |
| 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | /** |
| 3419 | * Returns the CDMA ERI text, |
| 3420 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3421 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3422 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3423 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3424 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3427 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3428 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3429 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3430 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3431 | mApp, subId, callingPackage, callingFeatureId, |
| 3432 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3433 | return null; |
| 3434 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3435 | |
| 3436 | final long identity = Binder.clearCallingIdentity(); |
| 3437 | try { |
| 3438 | final Phone phone = getPhone(subId); |
| 3439 | if (phone != null) { |
| 3440 | return phone.getCdmaEriText(); |
| 3441 | } else { |
| 3442 | return null; |
| 3443 | } |
| 3444 | } finally { |
| 3445 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3450 | * Returns the CDMA MDN. |
| 3451 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3452 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3453 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3455 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3456 | |
| 3457 | final long identity = Binder.clearCallingIdentity(); |
| 3458 | try { |
| 3459 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3460 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | return phone.getLine1Number(); |
| 3462 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3463 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | return null; |
| 3465 | } |
| 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | /** |
| 3472 | * Returns the CDMA MIN. |
| 3473 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3474 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3475 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3477 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | |
| 3479 | final long identity = Binder.clearCallingIdentity(); |
| 3480 | try { |
| 3481 | final Phone phone = getPhone(subId); |
| 3482 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3483 | return phone.getCdmaMin(); |
| 3484 | } else { |
| 3485 | return null; |
| 3486 | } |
| 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3492 | @Override |
| 3493 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3494 | INumberVerificationCallback callback, String callingPackage) { |
| 3495 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3496 | != PERMISSION_GRANTED) { |
| 3497 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3498 | } |
| 3499 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3500 | |
| 3501 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3502 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3503 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3504 | + "calling package: " + callingPackage |
| 3505 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | if (range == null) { |
| 3509 | throw new NullPointerException("Range must be non-null"); |
| 3510 | } |
| 3511 | |
| 3512 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3513 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3514 | |
| 3515 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3516 | } |
| 3517 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3518 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3519 | * Returns true if CDMA provisioning needs to run. |
| 3520 | */ |
| 3521 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3522 | final long identity = Binder.clearCallingIdentity(); |
| 3523 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3524 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3525 | } finally { |
| 3526 | Binder.restoreCallingIdentity(identity); |
| 3527 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3528 | } |
| 3529 | |
| 3530 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3531 | * Sets the voice mail number of a given subId. |
| 3532 | */ |
| 3533 | @Override |
| 3534 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3535 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3536 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | |
| 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3541 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3542 | return success; |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
| 3545 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3546 | } |
| 3547 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3548 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3549 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3551 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3552 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3553 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3554 | throw new SecurityException("caller must be system dialer"); |
| 3555 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3556 | |
| 3557 | final long identity = Binder.clearCallingIdentity(); |
| 3558 | try { |
| 3559 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3560 | if (phoneAccountHandle == null) { |
| 3561 | return null; |
| 3562 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3563 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3564 | } finally { |
| 3565 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3566 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3570 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3571 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3574 | mApp, subId, callingPackage, callingFeatureId, |
| 3575 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3576 | return null; |
| 3577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3581 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
| 3584 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3588 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3589 | VisualVoicemailSmsFilterSettings settings) { |
| 3590 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3591 | |
| 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3595 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
| 3598 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3599 | } |
| 3600 | |
| 3601 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3602 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3603 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | |
| 3605 | final long identity = Binder.clearCallingIdentity(); |
| 3606 | try { |
| 3607 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3608 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
| 3611 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3615 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3616 | String callingPackage, int subId) { |
| 3617 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3618 | |
| 3619 | final long identity = Binder.clearCallingIdentity(); |
| 3620 | try { |
| 3621 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3622 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3623 | } finally { |
| 3624 | Binder.restoreCallingIdentity(identity); |
| 3625 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3629 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3630 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3631 | |
| 3632 | final long identity = Binder.clearCallingIdentity(); |
| 3633 | try { |
| 3634 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3635 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3636 | } finally { |
| 3637 | Binder.restoreCallingIdentity(identity); |
| 3638 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3642 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3643 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3644 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3645 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3646 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3647 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3648 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3649 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3650 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3651 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3652 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3653 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3654 | * Sets the voice activation state of a given subId. |
| 3655 | */ |
| 3656 | @Override |
| 3657 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3659 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | |
| 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = getPhone(subId); |
| 3664 | if (phone != null) { |
| 3665 | phone.setVoiceActivationState(activationState); |
| 3666 | } else { |
| 3667 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3668 | } |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3671 | } |
| 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * Sets the data activation state of a given subId. |
| 3676 | */ |
| 3677 | @Override |
| 3678 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3680 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3681 | |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | final Phone phone = getPhone(subId); |
| 3685 | if (phone != null) { |
| 3686 | phone.setDataActivationState(activationState); |
| 3687 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3688 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | } |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * Returns the voice activation state of a given subId. |
| 3697 | */ |
| 3698 | @Override |
| 3699 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3701 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3702 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | if (phone != null) { |
| 3706 | return phone.getVoiceActivationState(); |
| 3707 | } else { |
| 3708 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3709 | } |
| 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | /** |
| 3716 | * Returns the data activation state of a given subId. |
| 3717 | */ |
| 3718 | @Override |
| 3719 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3721 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3722 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3723 | final long identity = Binder.clearCallingIdentity(); |
| 3724 | try { |
| 3725 | if (phone != null) { |
| 3726 | return phone.getDataActivationState(); |
| 3727 | } else { |
| 3728 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3729 | } |
| 3730 | } finally { |
| 3731 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3736 | * Returns the unread count of voicemails for a subId |
| 3737 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3738 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3739 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3740 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3741 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3742 | mApp, subId, callingPackage, callingFeatureId, |
| 3743 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3744 | return 0; |
| 3745 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3746 | final long identity = Binder.clearCallingIdentity(); |
| 3747 | try { |
| 3748 | final Phone phone = getPhone(subId); |
| 3749 | if (phone != null) { |
| 3750 | return phone.getVoiceMessageCount(); |
| 3751 | } else { |
| 3752 | return 0; |
| 3753 | } |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3756 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3760 | * returns true, if the device is in a state where both voice and data |
| 3761 | * are supported simultaneously. This can change based on location or network condition. |
| 3762 | */ |
| 3763 | @Override |
| 3764 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3765 | final long identity = Binder.clearCallingIdentity(); |
| 3766 | try { |
| 3767 | final Phone phone = getPhone(subId); |
| 3768 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3775 | * Send the dialer code if called from the current default dialer or the caller has |
| 3776 | * carrier privilege. |
| 3777 | * @param inputCode The dialer code to send |
| 3778 | */ |
| 3779 | @Override |
| 3780 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3781 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3782 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3783 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3784 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3785 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3786 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3787 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3788 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3789 | |
| 3790 | final long identity = Binder.clearCallingIdentity(); |
| 3791 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3792 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(identity); |
| 3795 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3796 | } |
| 3797 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3798 | @Override |
| 3799 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3800 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3801 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3802 | mApp, subId, "getNetworkSelectionMode"); |
| 3803 | final long identity = Binder.clearCallingIdentity(); |
| 3804 | try { |
| 3805 | if (!isActiveSubscription(subId)) { |
| 3806 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3807 | } |
| 3808 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3809 | } finally { |
| 3810 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3811 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3814 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3815 | public boolean isInEmergencySmsMode() { |
| 3816 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3817 | final long identity = Binder.clearCallingIdentity(); |
| 3818 | try { |
| 3819 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3820 | if (phone.isInEmergencySmsMode()) { |
| 3821 | return true; |
| 3822 | } |
| 3823 | } |
| 3824 | } finally { |
| 3825 | Binder.restoreCallingIdentity(identity); |
| 3826 | } |
| 3827 | return false; |
| 3828 | } |
| 3829 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3830 | /** |
| 3831 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3832 | * @param subId The subscription to use to check the configuration. |
| 3833 | * @param c The callback that will be used to send the result. |
| 3834 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3835 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3836 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3837 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3838 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3839 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3840 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3841 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3842 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3843 | "IMS not available on device."); |
| 3844 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | final long token = Binder.clearCallingIdentity(); |
| 3846 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3848 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3849 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3850 | } catch (ImsException e) { |
| 3851 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | } finally { |
| 3853 | Binder.restoreCallingIdentity(token); |
| 3854 | } |
| 3855 | } |
| 3856 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3857 | /** |
| 3858 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3859 | * @param subId The subscription to use to check the configuration. |
| 3860 | * @param c The callback that will be used to send the result. |
| 3861 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3862 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3863 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3864 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3865 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3866 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3867 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3868 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3869 | final long token = Binder.clearCallingIdentity(); |
| 3870 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3871 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3872 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3873 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3874 | } catch (ImsException e) { |
| 3875 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3876 | + "is inactive, ignoring unregister."); |
| 3877 | // If the subscription is no longer active, just return, since the callback |
| 3878 | // will already have been removed internally. |
| 3879 | } finally { |
| 3880 | Binder.restoreCallingIdentity(token); |
| 3881 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3884 | /** |
| 3885 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3886 | */ |
| 3887 | @Override |
| 3888 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3889 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3890 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3891 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3892 | "IMS not available on device."); |
| 3893 | } |
| 3894 | final long token = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | Phone phone = getPhone(subId); |
| 3897 | if (phone == null) { |
| 3898 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3899 | + subId + "'"); |
| 3900 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3901 | } |
| 3902 | phone.getImsRegistrationState(regState -> { |
| 3903 | try { |
| 3904 | consumer.accept((regState == null) |
| 3905 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3906 | } catch (RemoteException e) { |
| 3907 | // Ignore if the remote process is no longer available to call back. |
| 3908 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3909 | } |
| 3910 | }); |
| 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(token); |
| 3913 | } |
| 3914 | } |
| 3915 | |
| 3916 | /** |
| 3917 | * Get the transport type for the IMS service registration state. |
| 3918 | */ |
| 3919 | @Override |
| 3920 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3921 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3922 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3923 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3924 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3925 | "IMS not available on device."); |
| 3926 | } |
| 3927 | final long token = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | Phone phone = getPhone(subId); |
| 3930 | if (phone == null) { |
| 3931 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3932 | + subId + "'"); |
| 3933 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3934 | } |
| 3935 | phone.getImsRegistrationTech(regTech -> { |
| 3936 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3937 | int regTechConverted = (regTech == null) |
| 3938 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3939 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3940 | regTechConverted); |
| 3941 | try { |
| 3942 | consumer.accept(regTechConverted); |
| 3943 | } catch (RemoteException e) { |
| 3944 | // Ignore if the remote process is no longer available to call back. |
| 3945 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3946 | } |
| 3947 | }); |
| 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(token); |
| 3950 | } |
| 3951 | } |
| 3952 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3953 | /** |
| 3954 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3955 | * @param subId The subscription to use to check the configuration. |
| 3956 | * @param c The callback that will be used to send the result. |
| 3957 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3958 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3959 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3960 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3961 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3962 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3963 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3964 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3965 | "IMS not available on device."); |
| 3966 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3968 | final long token = Binder.clearCallingIdentity(); |
| 3969 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3970 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3971 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3972 | } catch (ImsException e) { |
| 3973 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3974 | } finally { |
| 3975 | Binder.restoreCallingIdentity(token); |
| 3976 | } |
| 3977 | } |
| 3978 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3979 | /** |
| 3980 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3981 | * @param subId The subscription to use to check the configuration. |
| 3982 | * @param c The callback that will be used to send the result. |
| 3983 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3985 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3986 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3987 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3988 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3989 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3990 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3991 | |
| 3992 | final long token = Binder.clearCallingIdentity(); |
| 3993 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3994 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3995 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3996 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3997 | } catch (ImsException e) { |
| 3998 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3999 | + "is inactive, ignoring unregister."); |
| 4000 | // If the subscription is no longer active, just return, since the callback |
| 4001 | // will already have been removed internally. |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(token); |
| 4004 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4008 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4009 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4011 | final long token = Binder.clearCallingIdentity(); |
| 4012 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4013 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4015 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4016 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4017 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4018 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4019 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4020 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(token); |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4027 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4028 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4029 | final long token = Binder.clearCallingIdentity(); |
| 4030 | try { |
| 4031 | Phone phone = getPhone(subId); |
| 4032 | if (phone == null) return false; |
| 4033 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4034 | } catch (com.android.ims.ImsException e) { |
| 4035 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4036 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | } finally { |
| 4038 | Binder.restoreCallingIdentity(token); |
| 4039 | } |
| 4040 | } |
| 4041 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4042 | /** |
| 4043 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4044 | * subscription. |
| 4045 | * @param subId The subscription to use to check the configuration. |
| 4046 | * @param callback The callback that will be used to send the result. |
| 4047 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4048 | * @param transportType The transport type of the MmTelFeature capability. |
| 4049 | */ |
| 4050 | @Override |
| 4051 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4052 | int transportType) { |
| 4053 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4054 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4055 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4056 | "IMS not available on device."); |
| 4057 | } |
| 4058 | final long token = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | int slotId = getSlotIndex(subId); |
| 4061 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4062 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4063 | + subId + "'"); |
| 4064 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4065 | } |
| 4066 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4067 | transportType, aBoolean -> { |
| 4068 | try { |
| 4069 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4070 | } catch (RemoteException e) { |
| 4071 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4072 | + "running. Ignore"); |
| 4073 | } |
| 4074 | }); |
| 4075 | } finally { |
| 4076 | Binder.restoreCallingIdentity(token); |
| 4077 | } |
| 4078 | } |
| 4079 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4080 | /** |
| 4081 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4082 | * @param subId The subscription to use to check the configuration. |
| 4083 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | @Override |
| 4085 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4086 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4087 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4088 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4090 | final long token = Binder.clearCallingIdentity(); |
| 4091 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4092 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4093 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4094 | } catch (ImsException e) { |
| 4095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(token); |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4102 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4104 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4105 | final long identity = Binder.clearCallingIdentity(); |
| 4106 | try { |
| 4107 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4108 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4109 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4110 | } catch (ImsException e) { |
| 4111 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4112 | } finally { |
| 4113 | Binder.restoreCallingIdentity(identity); |
| 4114 | } |
| 4115 | } |
| 4116 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4117 | /** |
| 4118 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4119 | * @param subId The subscription to use to check the configuration. |
| 4120 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4121 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4122 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4123 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4124 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4128 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4129 | } catch (ImsException e) { |
| 4130 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
| 4133 | } |
| 4134 | } |
| 4135 | |
| 4136 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4137 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4139 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4140 | final long identity = Binder.clearCallingIdentity(); |
| 4141 | try { |
| 4142 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4143 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4144 | } catch (ImsException e) { |
| 4145 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | } finally { |
| 4147 | Binder.restoreCallingIdentity(identity); |
| 4148 | } |
| 4149 | } |
| 4150 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4151 | /** |
| 4152 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4153 | * @param subId The subscription to use to check the configuration. |
| 4154 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | @Override |
| 4156 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4157 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4158 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4159 | final long identity = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4162 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4163 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4164 | } catch (ImsException e) { |
| 4165 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4166 | } finally { |
| 4167 | Binder.restoreCallingIdentity(identity); |
| 4168 | } |
| 4169 | } |
| 4170 | |
| 4171 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4172 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4174 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4175 | final long identity = Binder.clearCallingIdentity(); |
| 4176 | try { |
| 4177 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4178 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4179 | } catch (ImsException e) { |
| 4180 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
| 4184 | } |
| 4185 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4186 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4187 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4188 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4189 | * @param subId The subscription to use to check the configuration. |
| 4190 | */ |
| 4191 | @Override |
| 4192 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4193 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4194 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4195 | final long identity = Binder.clearCallingIdentity(); |
| 4196 | try { |
| 4197 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4198 | return ImsManager.getInstance(mApp, |
| 4199 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4200 | } catch (ImsException e) { |
| 4201 | throw new ServiceSpecificException(e.getCode()); |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | /** |
| 4208 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4209 | * Requires MODIFY_PHONE_STATE permission. |
| 4210 | * @param subId The subscription to use to check the configuration. |
| 4211 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4212 | * false otherwise |
| 4213 | */ |
| 4214 | @Override |
| 4215 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4216 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4217 | "setCrossSimCallingEnabled"); |
| 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
| 4220 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4221 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4222 | .setCrossSimCallingEnabled(isEnabled); |
| 4223 | } catch (ImsException e) { |
| 4224 | throw new ServiceSpecificException(e.getCode()); |
| 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(identity); |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4231 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4232 | * @param subId The subscription to use to check the configuration. |
| 4233 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4234 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4235 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4236 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4237 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4238 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | final long identity = Binder.clearCallingIdentity(); |
| 4240 | try { |
| 4241 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4242 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4243 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4244 | } catch (ImsException e) { |
| 4245 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(identity); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4252 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4254 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4255 | final long identity = Binder.clearCallingIdentity(); |
| 4256 | try { |
| 4257 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4258 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4259 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4260 | } catch (ImsException e) { |
| 4261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | @Override |
| 4268 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4270 | "setVoWiFiNonPersistent"); |
| 4271 | final long identity = Binder.clearCallingIdentity(); |
| 4272 | try { |
| 4273 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4274 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4275 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4276 | } catch (ImsException e) { |
| 4277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4278 | } finally { |
| 4279 | Binder.restoreCallingIdentity(identity); |
| 4280 | } |
| 4281 | } |
| 4282 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4283 | /** |
| 4284 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4285 | * @param subId The subscription to use to check the configuration. |
| 4286 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4287 | @Override |
| 4288 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4289 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4290 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4291 | final long identity = Binder.clearCallingIdentity(); |
| 4292 | try { |
| 4293 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4294 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4295 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4296 | } catch (ImsException e) { |
| 4297 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
| 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | @Override |
| 4304 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4306 | "setVoWiFiModeSetting"); |
| 4307 | final long identity = Binder.clearCallingIdentity(); |
| 4308 | try { |
| 4309 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4310 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4311 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4312 | } catch (ImsException e) { |
| 4313 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | @Override |
| 4320 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4321 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4322 | final long identity = Binder.clearCallingIdentity(); |
| 4323 | try { |
| 4324 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4325 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4326 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4327 | } catch (ImsException e) { |
| 4328 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
| 4331 | } |
| 4332 | } |
| 4333 | |
| 4334 | @Override |
| 4335 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4336 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4337 | "setVoWiFiRoamingModeSetting"); |
| 4338 | final long identity = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4341 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4342 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4343 | } catch (ImsException e) { |
| 4344 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4345 | } finally { |
| 4346 | Binder.restoreCallingIdentity(identity); |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | @Override |
| 4351 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4353 | "setRttCapabilityEnabled"); |
| 4354 | final long identity = Binder.clearCallingIdentity(); |
| 4355 | try { |
| 4356 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4357 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4358 | } catch (ImsException e) { |
| 4359 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | } finally { |
| 4361 | Binder.restoreCallingIdentity(identity); |
| 4362 | } |
| 4363 | } |
| 4364 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4365 | /** |
| 4366 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4367 | * @param subId The subscription to use to check the configuration. |
| 4368 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4369 | @Override |
| 4370 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4371 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4372 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4373 | final long identity = Binder.clearCallingIdentity(); |
| 4374 | try { |
| 4375 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4376 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4377 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4378 | } catch (ImsException e) { |
| 4379 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4380 | } finally { |
| 4381 | Binder.restoreCallingIdentity(identity); |
| 4382 | } |
| 4383 | } |
| 4384 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4385 | @Override |
| 4386 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4387 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4388 | final long identity = Binder.clearCallingIdentity(); |
| 4389 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4390 | if (!isImsAvailableOnDevice()) { |
| 4391 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4392 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4393 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4394 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4395 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4396 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4397 | } catch (ImsException e) { |
| 4398 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4399 | } finally { |
| 4400 | Binder.restoreCallingIdentity(identity); |
| 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | @Override |
| 4405 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4406 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4407 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4408 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4409 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4410 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4411 | try { |
| 4412 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4413 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4414 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4415 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4416 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4417 | + "is inactive, ignoring unregister."); |
| 4418 | // If the subscription is no longer active, just return, since the callback will already |
| 4419 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4420 | } finally { |
| 4421 | Binder.restoreCallingIdentity(identity); |
| 4422 | } |
| 4423 | } |
| 4424 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4425 | |
| 4426 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4428 | message); |
| 4429 | } |
| 4430 | |
| 4431 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4432 | boolean isMmtelCapability) { |
| 4433 | Phone phone = getPhone(subId); |
| 4434 | if (phone == null) { |
| 4435 | loge("phone instance null for subid " + subId); |
| 4436 | return false; |
| 4437 | } |
| 4438 | if (isMmtelCapability) { |
| 4439 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4440 | return false; |
| 4441 | } |
| 4442 | } else { |
| 4443 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4444 | return false; |
| 4445 | } |
| 4446 | } |
| 4447 | return true; |
| 4448 | } |
| 4449 | |
| 4450 | @Override |
| 4451 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4452 | boolean isProvisioned) { |
| 4453 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4454 | |
| 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
| 4457 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4458 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4459 | return; |
| 4460 | } |
| 4461 | |
| 4462 | // this capability requires provisioning, route to the correct API. |
| 4463 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4464 | switch (capability) { |
| 4465 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4466 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4467 | ims.setEabProvisioned(isProvisioned); |
| 4468 | break; |
| 4469 | default: { |
| 4470 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4471 | + "rcs capability '" + capability + "', which does not require " |
| 4472 | + "provisioning."); |
| 4473 | } |
| 4474 | } |
| 4475 | } finally { |
| 4476 | Binder.restoreCallingIdentity(identity); |
| 4477 | } |
| 4478 | |
| 4479 | } |
| 4480 | |
| 4481 | |
| 4482 | @Override |
| 4483 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4484 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4485 | final long identity = Binder.clearCallingIdentity(); |
| 4486 | try { |
| 4487 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4488 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4489 | return true; |
| 4490 | } |
| 4491 | |
| 4492 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4493 | switch (capability) { |
| 4494 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4495 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4496 | return ims.isEabProvisionedOnDevice(); |
| 4497 | |
| 4498 | default: { |
| 4499 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4500 | + "capability '" + capability + "', which does not require " |
| 4501 | + "provisioning."); |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
| 4507 | } |
| 4508 | } |
| 4509 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4510 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4511 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4512 | boolean isProvisioned) { |
| 4513 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4514 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4515 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4516 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4517 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4518 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4519 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
| 4522 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4523 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4524 | return; |
| 4525 | } |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4526 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4527 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4528 | loge("setImsProvisioningStatusForCapability: called for technology that does " |
| 4529 | + "not support provisioning - " + tech); |
| 4530 | return; |
| 4531 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4532 | |
| 4533 | // this capability requires provisioning, route to the correct API. |
| 4534 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4535 | switch (capability) { |
| 4536 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4537 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4538 | ims.setVolteProvisioned(isProvisioned); |
| 4539 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4540 | ims.setWfcProvisioned(isProvisioned); |
| 4541 | } |
| 4542 | break; |
| 4543 | } |
| 4544 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4545 | // There is currently no difference in VT provisioning type. |
| 4546 | ims.setVtProvisioned(isProvisioned); |
| 4547 | break; |
| 4548 | } |
| 4549 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4550 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4551 | // change the capability of the feature instead if needed. |
| 4552 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4553 | == isProvisioned) { |
| 4554 | // No change in provisioning. |
| 4555 | return; |
| 4556 | } |
| 4557 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4558 | try { |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4559 | ims.changeMmTelCapability(isProvisioned, capability, tech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4560 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4561 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4562 | + ", Exception" + e.getMessage()); |
| 4563 | } |
| 4564 | break; |
| 4565 | } |
| 4566 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4567 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4568 | + "MmTel capability '" + capability + "', which does not require " |
| 4569 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
| 4575 | } |
| 4576 | } |
| 4577 | |
| 4578 | @Override |
| 4579 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4580 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4581 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE |
| 4582 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4583 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4584 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4585 | } |
| 4586 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4587 | final long identity = Binder.clearCallingIdentity(); |
| 4588 | try { |
| 4589 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4590 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4591 | return true; |
| 4592 | } |
| 4593 | |
Brad Ebinger | 0d79c57 | 2021-04-17 15:20:49 -0700 | [diff] [blame] | 4594 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_NR |
| 4595 | || tech == ImsRegistrationImplBase.REGISTRATION_TECH_CROSS_SIM) { |
| 4596 | loge("getImsProvisioningStatusForCapability: called for technology that does " |
| 4597 | + "not support provisioning - " + tech); |
| 4598 | return true; |
| 4599 | } |
| 4600 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4601 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4602 | switch (capability) { |
| 4603 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4604 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4605 | return ims.isVolteProvisionedOnDevice(); |
| 4606 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4607 | return ims.isWfcProvisionedOnDevice(); |
| 4608 | } |
| 4609 | // This should never happen, since we are checking tech above to make sure it |
| 4610 | // is either LTE or IWLAN. |
| 4611 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4612 | + "capability."); |
| 4613 | } |
| 4614 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4615 | // There is currently no difference in VT provisioning type. |
| 4616 | return ims.isVtProvisionedOnDevice(); |
| 4617 | } |
| 4618 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4619 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4620 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4621 | } |
| 4622 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4623 | throw new IllegalArgumentException( |
| 4624 | "Tried to get provisioning for MmTel capability '" + capability |
| 4625 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | @Override |
| 4635 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4636 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4637 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4638 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4639 | } |
| 4640 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4641 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4642 | return (provisionedBits & capability) > 0; |
| 4643 | } |
| 4644 | |
| 4645 | @Override |
| 4646 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4647 | boolean isProvisioned) { |
| 4648 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4649 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4650 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4651 | } |
| 4652 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4653 | "setProvisioningStatusForCapability"); |
| 4654 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4655 | // If the current provisioning status for capability already matches isProvisioned, |
| 4656 | // do nothing. |
| 4657 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4658 | return; |
| 4659 | } |
| 4660 | if (isProvisioned) { |
| 4661 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4662 | } else { |
| 4663 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | /** |
| 4668 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4669 | * technology. The bitfield should mirror the bitfield defined by |
| 4670 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4671 | */ |
| 4672 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4673 | String key = getMmTelProvisioningKey(subId, tech); |
| 4674 | // Default is no capabilities are provisioned. |
| 4675 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4676 | } |
| 4677 | |
| 4678 | /** |
| 4679 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4680 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4681 | * technology specified. |
| 4682 | * |
| 4683 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4684 | */ |
| 4685 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4686 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4687 | String key = getMmTelProvisioningKey(subId, tech); |
| 4688 | editor.putInt(key, newField); |
| 4689 | editor.commit(); |
| 4690 | } |
| 4691 | |
| 4692 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4693 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4694 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4695 | } |
| 4696 | |
| 4697 | /** |
| 4698 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4699 | * carrier associated with the subscription id. |
| 4700 | */ |
| 4701 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4702 | int capability) { |
| 4703 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4704 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4705 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4706 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4707 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4708 | false); |
| 4709 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4710 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4711 | |
| 4712 | // First check to make sure that the capability requires provisioning. |
| 4713 | switch (capability) { |
| 4714 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4715 | // intentional fallthrough |
| 4716 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4717 | if (requireVoiceVtProvisioning) { |
| 4718 | // Voice and Video requires provisioning |
| 4719 | return true; |
| 4720 | } |
| 4721 | break; |
| 4722 | } |
| 4723 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4724 | if (requireUtProvisioning) { |
| 4725 | // UT requires provisioning |
| 4726 | return true; |
| 4727 | } |
| 4728 | break; |
| 4729 | } |
| 4730 | } |
| 4731 | return false; |
| 4732 | } |
| 4733 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4734 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4735 | int capability) { |
| 4736 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4737 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4738 | |
| 4739 | boolean requireRcsProvisioning = c.getBoolean( |
| 4740 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4741 | |
| 4742 | // First check to make sure that the capability requires provisioning. |
| 4743 | switch (capability) { |
| 4744 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4745 | // intentional fallthrough |
| 4746 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4747 | if (requireRcsProvisioning) { |
| 4748 | // OPTION or PRESENCE requires provisioning |
| 4749 | return true; |
| 4750 | } |
| 4751 | break; |
| 4752 | } |
| 4753 | } |
| 4754 | return false; |
| 4755 | } |
| 4756 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4757 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4758 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4759 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4760 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4761 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4762 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4766 | int slotId = getSlotIndex(subId); |
| 4767 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4768 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4769 | + subId + "' for key:" + key); |
| 4770 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4771 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4772 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4773 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4774 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4775 | + subId + "' for key:" + key); |
| 4776 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4777 | } finally { |
| 4778 | Binder.restoreCallingIdentity(identity); |
| 4779 | } |
| 4780 | } |
| 4781 | |
| 4782 | @Override |
| 4783 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4784 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4785 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4786 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4787 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4788 | final long identity = Binder.clearCallingIdentity(); |
| 4789 | try { |
| 4790 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4791 | int slotId = getSlotIndex(subId); |
| 4792 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4793 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4794 | + subId + "' for key:" + key); |
| 4795 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4796 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4797 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4798 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4799 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4800 | + subId + "' for key:" + key); |
| 4801 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(identity); |
| 4804 | } |
| 4805 | } |
| 4806 | |
| 4807 | @Override |
| 4808 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4809 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4810 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4811 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4813 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4814 | final long identity = Binder.clearCallingIdentity(); |
| 4815 | try { |
| 4816 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4817 | int slotId = getSlotIndex(subId); |
| 4818 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4819 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4820 | + subId + "' for key:" + key); |
| 4821 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4822 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4823 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4824 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4825 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4826 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4827 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4828 | } finally { |
| 4829 | Binder.restoreCallingIdentity(identity); |
| 4830 | } |
| 4831 | } |
| 4832 | |
| 4833 | @Override |
| 4834 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4835 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4836 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4837 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4839 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4840 | final long identity = Binder.clearCallingIdentity(); |
| 4841 | try { |
| 4842 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4843 | int slotId = getSlotIndex(subId); |
| 4844 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4845 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4846 | + subId + "' for key:" + key); |
| 4847 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4848 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4849 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4850 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4851 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4852 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4853 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4854 | } finally { |
| 4855 | Binder.restoreCallingIdentity(identity); |
| 4856 | } |
| 4857 | } |
| 4858 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4859 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4860 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4861 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4862 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4863 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4864 | } |
| 4865 | return slotId; |
| 4866 | } |
| 4867 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4868 | private int getSlotIndex(int subId) { |
| 4869 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4870 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4871 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4872 | } |
| 4873 | return slotId; |
| 4874 | } |
| 4875 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4876 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4877 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4878 | */ |
| 4879 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4880 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4881 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4882 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4883 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4884 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4885 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4886 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4887 | mApp, subId, callingPackage, callingFeatureId, |
| 4888 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4889 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4890 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4891 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
| 4894 | final Phone phone = getPhone(subId); |
| 4895 | if (phone != null) { |
| 4896 | return phone.getServiceState().getDataNetworkType(); |
| 4897 | } else { |
| 4898 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4899 | } |
| 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4902 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
| 4905 | /** |
| 4906 | * Returns the data network type |
| 4907 | */ |
| 4908 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4909 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4910 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4911 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | /** |
| 4915 | * Returns the data network type for a subId |
| 4916 | */ |
| 4917 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4918 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4919 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4920 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4921 | mApp, subId, callingPackage, callingFeatureId, |
| 4922 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4923 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4924 | } |
| 4925 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
| 4928 | final Phone phone = getPhone(subId); |
| 4929 | if (phone != null) { |
| 4930 | return phone.getServiceState().getDataNetworkType(); |
| 4931 | } else { |
| 4932 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4933 | } |
| 4934 | } finally { |
| 4935 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4936 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4940 | * Returns the Voice network type for a subId |
| 4941 | */ |
| 4942 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4943 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4944 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4946 | mApp, subId, callingPackage, callingFeatureId, |
| 4947 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4948 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4949 | } |
| 4950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | final long identity = Binder.clearCallingIdentity(); |
| 4952 | try { |
| 4953 | final Phone phone = getPhone(subId); |
| 4954 | if (phone != null) { |
| 4955 | return phone.getServiceState().getVoiceNetworkType(); |
| 4956 | } else { |
| 4957 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4958 | } |
| 4959 | } finally { |
| 4960 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4961 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | /** |
| 4965 | * @return true if a ICC card is present |
| 4966 | */ |
| 4967 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4968 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4969 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4970 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4971 | } |
| 4972 | |
| 4973 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4974 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4975 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4976 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4977 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | final long identity = Binder.clearCallingIdentity(); |
| 4979 | try { |
| 4980 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4981 | if (phone != null) { |
| 4982 | return phone.getIccCard().hasIccCard(); |
| 4983 | } else { |
| 4984 | return false; |
| 4985 | } |
| 4986 | } finally { |
| 4987 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4988 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | /** |
| 4992 | * Return if the current radio is LTE on CDMA. This |
| 4993 | * is a tri-state return value as for a period of time |
| 4994 | * the mode may be unknown. |
| 4995 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4996 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4997 | * @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] | 4998 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4999 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5000 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5001 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5002 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5003 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5004 | } |
| 5005 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5006 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5007 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5008 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5009 | try { |
| 5010 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5011 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5012 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5013 | } |
| 5014 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | final long identity = Binder.clearCallingIdentity(); |
| 5016 | try { |
| 5017 | final Phone phone = getPhone(subId); |
| 5018 | if (phone == null) { |
| 5019 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5020 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5021 | return TelephonyProperties.lte_on_cdma_device() |
| 5022 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5023 | } |
| 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5026 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5027 | } |
| 5028 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5029 | /** |
| 5030 | * {@hide} |
| 5031 | * Returns Default subId, 0 in the case of single standby. |
| 5032 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5033 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5034 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5035 | } |
| 5036 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5037 | private int getSlotForDefaultSubscription() { |
| 5038 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5039 | } |
| 5040 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5041 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5042 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5043 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5044 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5045 | private boolean isActiveSubscription(int subId) { |
| 5046 | return mSubscriptionController.isActiveSubId(subId); |
| 5047 | } |
| 5048 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5049 | /** |
| 5050 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5051 | */ |
| 5052 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5053 | final long identity = Binder.clearCallingIdentity(); |
| 5054 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5055 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5056 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5057 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5058 | } finally { |
| 5059 | Binder.restoreCallingIdentity(identity); |
| 5060 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | /** |
| 5064 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5065 | */ |
| 5066 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5067 | final long identity = Binder.clearCallingIdentity(); |
| 5068 | try { |
| 5069 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5070 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5071 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| 5074 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5075 | } |
| 5076 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5077 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5078 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5079 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5080 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5081 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5082 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 5083 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 5084 | if (phoneId == -1) { |
| 5085 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 5086 | + " does not correspond to an active phone"); |
| 5087 | } |
| 5088 | return PhoneFactory.getPhone(phoneId); |
| 5089 | } |
| 5090 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5091 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5092 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 5093 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5095 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5096 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5097 | if (DBG) { |
| 5098 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 5099 | } |
| 5100 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 5101 | p2); |
| 5102 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5103 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5104 | |
| 5105 | @Override |
| 5106 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 5107 | int slotIndex, String callingPackage, String aid, int p2) { |
| 5108 | enforceModifyPermission(); |
| 5109 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5110 | if (DBG) { |
| 5111 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 5112 | } |
| 5113 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5114 | callingPackage, aid, p2); |
| 5115 | } |
| 5116 | |
| 5117 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 5118 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5119 | final long identity = Binder.clearCallingIdentity(); |
| 5120 | try { |
| 5121 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 5122 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5123 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5124 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | if (bestComponent == null |
| 5126 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5127 | loge("The calling package is not allowed to access ISD-R."); |
| 5128 | throw new SecurityException( |
| 5129 | "The calling package is not allowed to access ISD-R."); |
| 5130 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5131 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5132 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5134 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 5135 | null /* workSource */); |
| 5136 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | return response; |
| 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5144 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5146 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5147 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 5148 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 5149 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5150 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5151 | @Override |
| 5152 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 5153 | enforceModifyPermission(); |
| 5154 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 5155 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 5156 | channel); |
| 5157 | } |
| 5158 | |
| 5159 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | final long identity = Binder.clearCallingIdentity(); |
| 5161 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5162 | if (channel < 0) { |
| 5163 | return false; |
| 5164 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5165 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5166 | null /* workSource */); |
| 5167 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | return success; |
| 5169 | } finally { |
| 5170 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5171 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5175 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5176 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5178 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5179 | if (DBG) { |
| 5180 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5181 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5182 | + p3 + " data=" + data); |
| 5183 | } |
| 5184 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5185 | command, p1, p2, p3, data); |
| 5186 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5187 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5188 | @Override |
| 5189 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5190 | int command, int p1, int p2, int p3, String data) { |
| 5191 | enforceModifyPermission(); |
| 5192 | if (DBG) { |
| 5193 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5194 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5195 | + p3 + " data=" + data); |
| 5196 | } |
| 5197 | return iccTransmitApduLogicalChannelWithPermission( |
| 5198 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5199 | data); |
| 5200 | } |
| 5201 | |
| 5202 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5203 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5206 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | return ""; |
| 5208 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5210 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5211 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5212 | null /* workSource */); |
| 5213 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5214 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | // Append the returned status code to the end of the response payload. |
| 5216 | String s = Integer.toHexString( |
| 5217 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5218 | if (response.payload != null) { |
| 5219 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5220 | } |
| 5221 | return s; |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5224 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5225 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5226 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5227 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5228 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5229 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5231 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5232 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5233 | if (DBG) { |
| 5234 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5235 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5236 | } |
| 5237 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5238 | cla, command, p1, p2, p3, data); |
| 5239 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5240 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5241 | @Override |
| 5242 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5243 | int command, int p1, int p2, int p3, String data) { |
| 5244 | enforceModifyPermission(); |
| 5245 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5246 | if (DBG) { |
| 5247 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5248 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5249 | + " data=" + data); |
| 5250 | } |
| 5251 | |
| 5252 | return iccTransmitApduBasicChannelWithPermission( |
| 5253 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5254 | p2, p3, data); |
| 5255 | } |
| 5256 | |
| 5257 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5258 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5259 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | final long identity = Binder.clearCallingIdentity(); |
| 5261 | try { |
| 5262 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5263 | && TextUtils.equals(ISDR_AID, data)) { |
| 5264 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5265 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5266 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | if (bestComponent == null |
| 5268 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5269 | loge("The calling package is not allowed to select ISD-R."); |
| 5270 | throw new SecurityException( |
| 5271 | "The calling package is not allowed to select ISD-R."); |
| 5272 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5273 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5274 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5276 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5277 | null /* workSource */); |
| 5278 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5279 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5280 | // Append the returned status code to the end of the response payload. |
| 5281 | String s = Integer.toHexString( |
| 5282 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5283 | if (response.payload != null) { |
| 5284 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5285 | } |
| 5286 | return s; |
| 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5289 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5293 | 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] | 5294 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5296 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | final long identity = Binder.clearCallingIdentity(); |
| 5299 | try { |
| 5300 | if (DBG) { |
| 5301 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5302 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5303 | } |
| 5304 | |
| 5305 | IccIoResult response = |
| 5306 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5307 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5308 | subId); |
| 5309 | |
| 5310 | if (DBG) { |
| 5311 | log("Exchange SIM_IO [R]" + response); |
| 5312 | } |
| 5313 | |
| 5314 | byte[] result = null; |
| 5315 | int length = 2; |
| 5316 | if (response.payload != null) { |
| 5317 | length = 2 + response.payload.length; |
| 5318 | result = new byte[length]; |
| 5319 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5320 | } else { |
| 5321 | result = new byte[length]; |
| 5322 | } |
| 5323 | |
| 5324 | result[length - 1] = (byte) response.sw2; |
| 5325 | result[length - 2] = (byte) response.sw1; |
| 5326 | return result; |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5329 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5332 | /** |
| 5333 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5334 | * on a particular subscription |
| 5335 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5336 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5337 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5339 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5340 | return null; |
| 5341 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | |
| 5343 | final long identity = Binder.clearCallingIdentity(); |
| 5344 | try { |
| 5345 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5346 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5347 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5348 | return null; |
| 5349 | } |
| 5350 | Object response = sendRequest( |
| 5351 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5352 | if (response instanceof String[]) { |
| 5353 | return (String[]) response; |
| 5354 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5355 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5357 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | } finally { |
| 5359 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5360 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5361 | } |
| 5362 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5363 | /** |
| 5364 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5365 | * subscription. |
| 5366 | * |
| 5367 | * @param subId the id of the subscription. |
| 5368 | * @param appType the uicc app type, must be USIM or SIM. |
| 5369 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5370 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5371 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5372 | * @return number of fplmns that is successfully written to the SIM. |
| 5373 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5374 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5375 | String callingFeatureId) { |
| 5376 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5377 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5378 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5379 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5380 | } |
| 5381 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5382 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5383 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5384 | } |
| 5385 | if (fplmns == null) { |
| 5386 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5387 | } |
| 5388 | for (String fplmn : fplmns) { |
| 5389 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5390 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5391 | } |
| 5392 | } |
| 5393 | final long identity = Binder.clearCallingIdentity(); |
| 5394 | try { |
| 5395 | Object response = sendRequest( |
| 5396 | CMD_SET_FORBIDDEN_PLMNS, |
| 5397 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5398 | subId); |
| 5399 | return (int) response; |
| 5400 | } finally { |
| 5401 | Binder.restoreCallingIdentity(identity); |
| 5402 | } |
| 5403 | } |
| 5404 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5405 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5406 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5407 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5408 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
| 5412 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5413 | if (response.payload == null) { |
| 5414 | return ""; |
| 5415 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | // Append the returned status code to the end of the response payload. |
| 5418 | String s = Integer.toHexString( |
| 5419 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5420 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5421 | return s; |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5425 | } |
| 5426 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5427 | /** |
| 5428 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5429 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5430 | * |
| 5431 | * @param itemID the ID of the item to read |
| 5432 | * @return the NV item as a String, or null on error. |
| 5433 | */ |
| 5434 | @Override |
| 5435 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5436 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5437 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5438 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | |
| 5440 | final long identity = Binder.clearCallingIdentity(); |
| 5441 | try { |
| 5442 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5443 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5445 | return value; |
| 5446 | } finally { |
| 5447 | Binder.restoreCallingIdentity(identity); |
| 5448 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | /** |
| 5452 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5453 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5454 | * |
| 5455 | * @param itemID the ID of the item to read |
| 5456 | * @param itemValue the value to write, as a String |
| 5457 | * @return true on success; false on any failure |
| 5458 | */ |
| 5459 | @Override |
| 5460 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5461 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5463 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | |
| 5465 | final long identity = Binder.clearCallingIdentity(); |
| 5466 | try { |
| 5467 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5468 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5469 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5470 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5471 | return success; |
| 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
| 5474 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5475 | } |
| 5476 | |
| 5477 | /** |
| 5478 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5479 | * Used for device configuration by some CDMA operators. |
| 5480 | * |
| 5481 | * @param preferredRoamingList byte array containing the new PRL |
| 5482 | * @return true on success; false on any failure |
| 5483 | */ |
| 5484 | @Override |
| 5485 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5486 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5487 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5488 | |
| 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
| 5491 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5492 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5493 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5494 | return success; |
| 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5498 | } |
| 5499 | |
| 5500 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5501 | * 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] | 5502 | * Used for device configuration by some CDMA operators. |
| 5503 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5504 | * @param slotIndex - device slot. |
| 5505 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5506 | * @return true on success; false on any failure |
| 5507 | */ |
| 5508 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5509 | public boolean resetModemConfig(int slotIndex) { |
| 5510 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5511 | if (phone != null) { |
| 5512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5513 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
| 5517 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5518 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5519 | return success; |
| 5520 | } finally { |
| 5521 | Binder.restoreCallingIdentity(identity); |
| 5522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5524 | return false; |
| 5525 | } |
| 5526 | |
| 5527 | /** |
| 5528 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5529 | * |
| 5530 | * @param slotIndex - device slot. |
| 5531 | * |
| 5532 | * @return true on success; false on any failure |
| 5533 | */ |
| 5534 | @Override |
| 5535 | public boolean rebootModem(int slotIndex) { |
| 5536 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5537 | if (phone != null) { |
| 5538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5539 | mApp, phone.getSubId(), "rebootModem"); |
| 5540 | |
| 5541 | final long identity = Binder.clearCallingIdentity(); |
| 5542 | try { |
| 5543 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5544 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5545 | return success; |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
| 5548 | } |
| 5549 | } |
| 5550 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5551 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5552 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5553 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5554 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5555 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5556 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5557 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5558 | return new String[0]; |
| 5559 | } |
| 5560 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | final long identity = Binder.clearCallingIdentity(); |
| 5562 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5563 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | } finally { |
| 5565 | Binder.restoreCallingIdentity(identity); |
| 5566 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5567 | } |
| 5568 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5569 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5570 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5571 | * {@link #disableIms(int)}. |
| 5572 | * @param slotIndex device slot. |
| 5573 | */ |
| 5574 | public void resetIms(int slotIndex) { |
| 5575 | enforceModifyPermission(); |
| 5576 | |
| 5577 | final long identity = Binder.clearCallingIdentity(); |
| 5578 | try { |
| 5579 | if (mImsResolver == null) { |
| 5580 | // may happen if the does not support IMS. |
| 5581 | return; |
| 5582 | } |
| 5583 | mImsResolver.disableIms(slotIndex); |
| 5584 | mImsResolver.enableIms(slotIndex); |
| 5585 | } finally { |
| 5586 | Binder.restoreCallingIdentity(identity); |
| 5587 | } |
| 5588 | } |
| 5589 | |
| 5590 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5591 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5592 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5593 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5594 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5595 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | |
| 5597 | final long identity = Binder.clearCallingIdentity(); |
| 5598 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5599 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5600 | // may happen if the device does not support IMS. |
| 5601 | return; |
| 5602 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5603 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | } finally { |
| 5605 | Binder.restoreCallingIdentity(identity); |
| 5606 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5607 | } |
| 5608 | |
| 5609 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5610 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5611 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5612 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5613 | public void disableIms(int slotId) { |
| 5614 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | |
| 5616 | final long identity = Binder.clearCallingIdentity(); |
| 5617 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5618 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5619 | // may happen if the device does not support IMS. |
| 5620 | return; |
| 5621 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5622 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5629 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5630 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5631 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5632 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5633 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5634 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | |
| 5636 | final long identity = Binder.clearCallingIdentity(); |
| 5637 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5638 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5639 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5640 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5641 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5642 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5643 | } finally { |
| 5644 | Binder.restoreCallingIdentity(identity); |
| 5645 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5646 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5647 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5648 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5649 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5650 | @Override |
| 5651 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5652 | enforceModifyPermission(); |
| 5653 | |
| 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5657 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5658 | } finally { |
| 5659 | Binder.restoreCallingIdentity(identity); |
| 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5664 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5665 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5666 | */ |
| 5667 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5668 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5669 | |
| 5670 | final long identity = Binder.clearCallingIdentity(); |
| 5671 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5672 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5673 | // may happen if the device does not support IMS. |
| 5674 | return null; |
| 5675 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5676 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | } finally { |
| 5678 | Binder.restoreCallingIdentity(identity); |
| 5679 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5680 | } |
| 5681 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5682 | /** |
| 5683 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5684 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5685 | */ |
| 5686 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5687 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | |
| 5689 | final long identity = Binder.clearCallingIdentity(); |
| 5690 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5691 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5692 | // may happen if the device does not support IMS. |
| 5693 | return null; |
| 5694 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5695 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | } finally { |
| 5697 | Binder.restoreCallingIdentity(identity); |
| 5698 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5699 | } |
| 5700 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5701 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5702 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5703 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5704 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5705 | * @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] | 5706 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5707 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5708 | * @param packageName The name of the package that the current configuration will be replaced |
| 5709 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5710 | * @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] | 5711 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5712 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5713 | int[] featureTypes, String packageName) { |
| 5714 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5715 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5717 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5718 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5719 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5720 | final long identity = Binder.clearCallingIdentity(); |
| 5721 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5722 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5723 | // may happen if the device does not support IMS. |
| 5724 | return false; |
| 5725 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5726 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5727 | for (int featureType : featureTypes) { |
| 5728 | featureConfig.put(featureType, packageName); |
| 5729 | } |
| 5730 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5731 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
| 5734 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5738 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5739 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5740 | * |
| 5741 | * This should only be used for testing. |
| 5742 | * |
| 5743 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5744 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5745 | */ |
| 5746 | @Override |
| 5747 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5748 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5749 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5750 | "clearCarrierImsServiceOverride"); |
| 5751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5752 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5753 | "clearCarrierImsServiceOverride"); |
| 5754 | |
| 5755 | final long identity = Binder.clearCallingIdentity(); |
| 5756 | try { |
| 5757 | if (mImsResolver == null) { |
| 5758 | // may happen if the device does not support IMS. |
| 5759 | return false; |
| 5760 | } |
| 5761 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
| 5764 | } |
| 5765 | } |
| 5766 | |
| 5767 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5768 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5769 | * |
| 5770 | * @param slotId The slot that the ImsService is associated with. |
| 5771 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5772 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5773 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5774 | * @return the package name of the ImsService configuration. |
| 5775 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5776 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5777 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5778 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5779 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5780 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5781 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5782 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5786 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5787 | // may happen if the device does not support IMS. |
| 5788 | return ""; |
| 5789 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5790 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5791 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5792 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(identity); |
| 5795 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5796 | } |
| 5797 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5798 | /** |
| 5799 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5800 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5801 | * @param callback A callback with an integer containing the |
| 5802 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5803 | */ |
| 5804 | @Override |
| 5805 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5806 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5807 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5808 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5809 | "IMS not available on device."); |
| 5810 | } |
| 5811 | final long token = Binder.clearCallingIdentity(); |
| 5812 | try { |
| 5813 | int slotId = getSlotIndex(subId); |
| 5814 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5815 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5816 | + subId + "'"); |
| 5817 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5818 | } |
| 5819 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5820 | try { |
| 5821 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5822 | } catch (RemoteException e) { |
| 5823 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5824 | + "Ignore"); |
| 5825 | } |
| 5826 | }); |
| 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(token); |
| 5829 | } |
| 5830 | } |
| 5831 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5832 | /** |
| 5833 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5834 | */ |
| 5835 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5836 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5837 | |
| 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5840 | // NOTE: Before S, this method only set the default phone. |
| 5841 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5842 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5843 | phone.setImsRegistrationState(registered); |
| 5844 | } |
| 5845 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5846 | } finally { |
| 5847 | Binder.restoreCallingIdentity(identity); |
| 5848 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5852 | * Set the network selection mode to automatic. |
| 5853 | * |
| 5854 | */ |
| 5855 | @Override |
| 5856 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5858 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | |
| 5860 | final long identity = Binder.clearCallingIdentity(); |
| 5861 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5862 | if (!isActiveSubscription(subId)) { |
| 5863 | return; |
| 5864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5865 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5866 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5867 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5868 | } finally { |
| 5869 | Binder.restoreCallingIdentity(identity); |
| 5870 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5871 | } |
| 5872 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5873 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5874 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5875 | * |
| 5876 | * @param subId the id of the subscription. |
| 5877 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5878 | * the operator to attach to. |
| 5879 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5880 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5881 | * normal network selection next time. |
| 5882 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5883 | */ |
| 5884 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5885 | public boolean setNetworkSelectionModeManual( |
| 5886 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5888 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5889 | |
| 5890 | if (!isActiveSubscription(subId)) { |
| 5891 | return false; |
| 5892 | } |
| 5893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | final long identity = Binder.clearCallingIdentity(); |
| 5895 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5896 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5898 | if (DBG) { |
| 5899 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5900 | + " operator: " + operatorInfo); |
| 5901 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5906 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5907 | /** |
| 5908 | * Get the manual network selection |
| 5909 | * |
| 5910 | * @param subId the id of the subscription. |
| 5911 | * |
| 5912 | * @return the previously saved user selected PLMN |
| 5913 | */ |
| 5914 | @Override |
| 5915 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5916 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5917 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5918 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
| 5922 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5923 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5924 | } |
| 5925 | |
| 5926 | final Phone phone = getPhone(subId); |
| 5927 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5928 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5929 | } |
| 5930 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5931 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5932 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5933 | } finally { |
| 5934 | Binder.restoreCallingIdentity(identity); |
| 5935 | } |
| 5936 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5937 | |
| 5938 | /** |
| 5939 | * Scans for available networks. |
| 5940 | */ |
| 5941 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5942 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5943 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5945 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5946 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5947 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5948 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5949 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5950 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5951 | .setCallingPid(Binder.getCallingPid()) |
| 5952 | .setCallingUid(Binder.getCallingUid()) |
| 5953 | .setMethod("getCellNetworkScanResults") |
| 5954 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5955 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5956 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5957 | .build()); |
| 5958 | switch (locationResult) { |
| 5959 | case DENIED_HARD: |
| 5960 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5961 | case DENIED_SOFT: |
| 5962 | return null; |
| 5963 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5964 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5965 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | try { |
| 5967 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5968 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
| 5972 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5976 | * Get the call forwarding info, given the call forwarding reason. |
| 5977 | */ |
| 5978 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5979 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5980 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5981 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5982 | long identity = Binder.clearCallingIdentity(); |
| 5983 | try { |
| 5984 | if (DBG) { |
| 5985 | log("getCallForwarding: subId " + subId |
| 5986 | + " callForwardingReason" + callForwardingReason); |
| 5987 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5988 | |
| 5989 | Phone phone = getPhone(subId); |
| 5990 | if (phone == null) { |
| 5991 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5992 | callback.onError( |
| 5993 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5994 | } catch (RemoteException e) { |
| 5995 | // ignore |
| 5996 | } |
| 5997 | return; |
| 5998 | } |
| 5999 | |
| 6000 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6001 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6002 | @Override |
| 6003 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6004 | try { |
| 6005 | callback.onCallForwardingInfoAvailable(info); |
| 6006 | } catch (RemoteException e) { |
| 6007 | // ignore |
| 6008 | } |
| 6009 | } |
| 6010 | |
| 6011 | @Override |
| 6012 | public void onError(int error) { |
| 6013 | try { |
| 6014 | callback.onError(error); |
| 6015 | } catch (RemoteException e) { |
| 6016 | // ignore |
| 6017 | } |
| 6018 | } |
| 6019 | }); |
| 6020 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6021 | } finally { |
| 6022 | Binder.restoreCallingIdentity(identity); |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | /** |
| 6027 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6028 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6029 | */ |
| 6030 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6031 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6032 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6033 | enforceModifyPermission(); |
| 6034 | long identity = Binder.clearCallingIdentity(); |
| 6035 | try { |
| 6036 | if (DBG) { |
| 6037 | log("setCallForwarding: subId " + subId |
| 6038 | + " callForwardingInfo" + callForwardingInfo); |
| 6039 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6040 | |
| 6041 | Phone phone = getPhone(subId); |
| 6042 | if (phone == null) { |
| 6043 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6044 | callback.accept( |
| 6045 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6046 | } catch (RemoteException e) { |
| 6047 | // ignore |
| 6048 | } |
| 6049 | return; |
| 6050 | } |
| 6051 | |
| 6052 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6053 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6054 | |
| 6055 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6056 | } finally { |
| 6057 | Binder.restoreCallingIdentity(identity); |
| 6058 | } |
| 6059 | } |
| 6060 | |
| 6061 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6062 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6063 | */ |
| 6064 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6065 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6066 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6067 | long identity = Binder.clearCallingIdentity(); |
| 6068 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6069 | Phone phone = getPhone(subId); |
| 6070 | if (phone == null) { |
| 6071 | try { |
| 6072 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6073 | } catch (RemoteException e) { |
| 6074 | // ignore |
| 6075 | } |
| 6076 | return; |
| 6077 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6078 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6079 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6080 | boolean requireUssd = c.getBoolean( |
| 6081 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6082 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6083 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6084 | if (requireUssd) { |
| 6085 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6086 | getSubscriptionCarrierId(subId)); |
| 6087 | String newUssdCommand = ""; |
| 6088 | try { |
| 6089 | newUssdCommand = carrierXmlParser.getFeature( |
| 6090 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6091 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6092 | } catch (NullPointerException e) { |
| 6093 | loge("Failed to generate USSD number" + e); |
| 6094 | } |
| 6095 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6096 | mMainThreadHandler, callback, carrierXmlParser, |
| 6097 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6098 | final String ussdCommand = newUssdCommand; |
| 6099 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6100 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6101 | }); |
| 6102 | } else { |
| 6103 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6104 | callback::accept); |
| 6105 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6106 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6113 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6114 | */ |
| 6115 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6116 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6117 | enforceModifyPermission(); |
| 6118 | long identity = Binder.clearCallingIdentity(); |
| 6119 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6120 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6121 | |
| 6122 | Phone phone = getPhone(subId); |
| 6123 | if (phone == null) { |
| 6124 | try { |
| 6125 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6126 | } catch (RemoteException e) { |
| 6127 | // ignore |
| 6128 | } |
| 6129 | return; |
| 6130 | } |
| 6131 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6132 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6133 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6134 | boolean requireUssd = c.getBoolean( |
| 6135 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6136 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6137 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6138 | if (requireUssd) { |
| 6139 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6140 | getSubscriptionCarrierId(subId)); |
| 6141 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6142 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6143 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6144 | String newUssdCommand = ""; |
| 6145 | try { |
| 6146 | newUssdCommand = carrierXmlParser.getFeature( |
| 6147 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6148 | .makeCommand(ssAction, null); |
| 6149 | } catch (NullPointerException e) { |
| 6150 | loge("Failed to generate USSD number" + e); |
| 6151 | } |
| 6152 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6153 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6154 | final String ussdCommand = newUssdCommand; |
| 6155 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6156 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6157 | }); |
| 6158 | } else { |
| 6159 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6160 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6161 | |
| 6162 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6163 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6164 | } finally { |
| 6165 | Binder.restoreCallingIdentity(identity); |
| 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6170 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6171 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6172 | * @param subId id of the subscription |
| 6173 | * @param request contains the radio access networks with bands/channels to scan |
| 6174 | * @param messenger callback messenger for scan results or errors |
| 6175 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6176 | * @return the id of the requested scan which can be used to stop the scan. |
| 6177 | */ |
| 6178 | @Override |
| 6179 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6180 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6182 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6183 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6184 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6185 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6186 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6187 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6188 | .setCallingPid(Binder.getCallingPid()) |
| 6189 | .setCallingUid(Binder.getCallingUid()) |
| 6190 | .setMethod("requestNetworkScan") |
| 6191 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 6192 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6193 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6194 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6195 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6196 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6197 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6198 | if (e != null) { |
| 6199 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6200 | throw e; |
| 6201 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6202 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6203 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6204 | } |
| 6205 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6207 | int callingUid = Binder.getCallingUid(); |
| 6208 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6209 | final long identity = Binder.clearCallingIdentity(); |
| 6210 | try { |
| 6211 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6212 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6213 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6214 | } finally { |
| 6215 | Binder.restoreCallingIdentity(identity); |
| 6216 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6219 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6220 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6221 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6222 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6223 | boolean hasNetworkScanPermission = |
| 6224 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6225 | == PERMISSION_GRANTED; |
| 6226 | |
| 6227 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6228 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6229 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6230 | } |
| 6231 | |
| 6232 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6233 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6234 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6235 | return new SecurityException("Specific channels must not be" |
| 6236 | + " scanned without location access."); |
| 6237 | } |
| 6238 | } |
| 6239 | } |
| 6240 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6241 | return null; |
| 6242 | } |
| 6243 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6244 | /** |
| 6245 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6246 | * |
| 6247 | * @param subId id of the subscription |
| 6248 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6249 | */ |
| 6250 | @Override |
| 6251 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6253 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6254 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6255 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | final long identity = Binder.clearCallingIdentity(); |
| 6257 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6258 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | } finally { |
| 6260 | Binder.restoreCallingIdentity(identity); |
| 6261 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6262 | } |
| 6263 | |
| 6264 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6265 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6266 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6267 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6268 | */ |
| 6269 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6270 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6271 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6272 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6273 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6274 | |
| 6275 | final long identity = Binder.clearCallingIdentity(); |
| 6276 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6277 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6278 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6279 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6280 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6281 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | } finally { |
| 6283 | Binder.restoreCallingIdentity(identity); |
| 6284 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6288 | * Get the allowed network types for certain reason. |
| 6289 | * |
| 6290 | * @param subId the id of the subscription. |
| 6291 | * @param reason the reason the allowed network type change is taking place |
| 6292 | * @return the allowed network types. |
| 6293 | */ |
| 6294 | @Override |
| 6295 | public long getAllowedNetworkTypesForReason(int subId, |
| 6296 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6297 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6298 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6299 | final long identity = Binder.clearCallingIdentity(); |
| 6300 | try { |
| 6301 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6302 | } finally { |
| 6303 | Binder.restoreCallingIdentity(identity); |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6308 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6309 | * @param subId subscription id of the sim card |
| 6310 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6311 | * This can be passed following states |
| 6312 | * <ol> |
| 6313 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6314 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6315 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6316 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6317 | * </ol> |
| 6318 | * @return operation result. |
| 6319 | */ |
| 6320 | @Override |
| 6321 | public int setNrDualConnectivityState(int subId, |
| 6322 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6324 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6325 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6326 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6327 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6328 | } |
| 6329 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6330 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6331 | final long identity = Binder.clearCallingIdentity(); |
| 6332 | try { |
| 6333 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6334 | nrDualConnectivityState, subId, |
| 6335 | workSource); |
| 6336 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6337 | return result; |
| 6338 | } finally { |
| 6339 | Binder.restoreCallingIdentity(identity); |
| 6340 | } |
| 6341 | } |
| 6342 | |
| 6343 | /** |
| 6344 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6345 | * @return true if dual connectivity is enabled else false |
| 6346 | */ |
| 6347 | @Override |
| 6348 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6349 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6350 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6351 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6352 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6353 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6354 | return false; |
| 6355 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6356 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
| 6359 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6360 | null, subId, workSource); |
| 6361 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6362 | return isEnabled; |
| 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
| 6365 | } |
| 6366 | } |
| 6367 | |
| 6368 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6369 | * Set the allowed network types of the device and |
| 6370 | * provide the reason triggering the allowed network change. |
| 6371 | * |
| 6372 | * @param subId the id of the subscription. |
| 6373 | * @param reason the reason the allowed network type change is taking place |
| 6374 | * @param allowedNetworkTypes the allowed network types. |
| 6375 | * @return true on success; false on any failure. |
| 6376 | */ |
| 6377 | @Override |
| 6378 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6379 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6380 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6382 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6383 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6384 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6385 | return false; |
| 6386 | } |
| 6387 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6388 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6389 | return false; |
| 6390 | } |
| 6391 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6392 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6393 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6394 | |
| 6395 | |
| 6396 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6397 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6398 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6399 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6400 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6403 | Boolean success = (Boolean) sendRequest( |
| 6404 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6405 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6406 | |
| 6407 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6408 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
| 6411 | } |
| 6412 | } |
| 6413 | |
| 6414 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6415 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6416 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6417 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6418 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6419 | * @hide |
| 6420 | */ |
| 6421 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6422 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6423 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6424 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6425 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6426 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6427 | if (phone != null) { |
| 6428 | return phone.hasMatchedTetherApnSetting(); |
| 6429 | } else { |
| 6430 | return false; |
| 6431 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6432 | } finally { |
| 6433 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6434 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6435 | } |
| 6436 | |
| 6437 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6438 | * Enable or disable always reporting signal strength changes from radio. |
| 6439 | * |
| 6440 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6441 | */ |
| 6442 | @Override |
| 6443 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6444 | enforceModifyPermission(); |
| 6445 | enforceSystemCaller(); |
| 6446 | |
| 6447 | final long identity = Binder.clearCallingIdentity(); |
| 6448 | final Phone phone = getPhone(subId); |
| 6449 | try { |
| 6450 | if (phone != null) { |
| 6451 | if (DBG) { |
| 6452 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6453 | + " isEnable=" + isEnable); |
| 6454 | } |
| 6455 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6456 | } else { |
| 6457 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6458 | + subId); |
| 6459 | } |
| 6460 | } finally { |
| 6461 | Binder.restoreCallingIdentity(identity); |
| 6462 | } |
| 6463 | } |
| 6464 | |
| 6465 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6466 | * Get the user enabled state of Mobile Data. |
| 6467 | * |
| 6468 | * TODO: remove and use isUserDataEnabled. |
| 6469 | * This can't be removed now because some vendor codes |
| 6470 | * calls through ITelephony directly while they should |
| 6471 | * use TelephonyManager. |
| 6472 | * |
| 6473 | * @return true on enabled |
| 6474 | */ |
| 6475 | @Override |
| 6476 | public boolean getDataEnabled(int subId) { |
| 6477 | return isUserDataEnabled(subId); |
| 6478 | } |
| 6479 | |
| 6480 | /** |
| 6481 | * Get whether mobile data is enabled per user setting. |
| 6482 | * |
| 6483 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6484 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6485 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6486 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6487 | * |
| 6488 | * @return {@code true} if data is enabled else {@code false} |
| 6489 | */ |
| 6490 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6491 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6492 | try { |
| 6493 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6494 | null); |
| 6495 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6497 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6498 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | |
| 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
| 6502 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6503 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6504 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6505 | if (phone != null) { |
| 6506 | boolean retVal = phone.isUserDataEnabled(); |
| 6507 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6508 | return retVal; |
| 6509 | } else { |
| 6510 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6511 | return false; |
| 6512 | } |
| 6513 | } finally { |
| 6514 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6519 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6520 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6521 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6522 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6523 | * @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] | 6524 | */ |
| 6525 | @Override |
| 6526 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6527 | try { |
| 6528 | try { |
| 6529 | mApp.enforceCallingOrSelfPermission( |
| 6530 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6531 | null); |
| 6532 | } catch (Exception e) { |
| 6533 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6534 | "isDataEnabled"); |
| 6535 | } |
| 6536 | } catch (Exception e) { |
| 6537 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6538 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6539 | |
| 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
| 6542 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6543 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6544 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6545 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6546 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6548 | return retVal; |
| 6549 | } else { |
| 6550 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6551 | return false; |
| 6552 | } |
| 6553 | } finally { |
| 6554 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6555 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6556 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6557 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6558 | /** |
| 6559 | * Check if data is enabled for a specific reason |
| 6560 | * @param subId Subscription index |
| 6561 | * @param reason the reason the data enable change is taking place |
| 6562 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6563 | */ |
| 6564 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6565 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6566 | @TelephonyManager.DataEnabledReason int reason) { |
| 6567 | try { |
| 6568 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6569 | null); |
| 6570 | } catch (Exception e) { |
| 6571 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6572 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | |
| 6576 | final long identity = Binder.clearCallingIdentity(); |
| 6577 | try { |
| 6578 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6579 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6580 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6581 | + " reason=" + reason); |
| 6582 | } |
| 6583 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6584 | if (phone != null) { |
| 6585 | boolean retVal; |
| 6586 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6587 | retVal = phone.isUserDataEnabled(); |
| 6588 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6589 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6590 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6591 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6592 | return retVal; |
| 6593 | } else { |
| 6594 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6595 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6596 | + subId + " retVal=false"); |
| 6597 | } |
| 6598 | return false; |
| 6599 | } |
| 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
| 6602 | } |
| 6603 | } |
| 6604 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6605 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6606 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6607 | if (uid == Process.PHONE_UID) { |
| 6608 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6609 | // 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] | 6610 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6611 | } |
| 6612 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6613 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6614 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6615 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6616 | || subController == null) return privilegeFromSim; |
| 6617 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6618 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6619 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6620 | |
| 6621 | final long identity = Binder.clearCallingIdentity(); |
| 6622 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6623 | int subId = phone.getSubId(); |
| 6624 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6625 | // A test override is in place for the privileges for this subId, so don't try to |
| 6626 | // read the subscription privileges. |
| 6627 | return privilegeFromSim; |
| 6628 | } |
| 6629 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6630 | SubscriptionManager subManager = (SubscriptionManager) |
| 6631 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6632 | for (String pkg : packages) { |
| 6633 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6634 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6635 | } |
| 6636 | } |
| 6637 | return privilegeFromSim; |
| 6638 | } finally { |
| 6639 | Binder.restoreCallingIdentity(identity); |
| 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6644 | String pkgName) { |
| 6645 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6646 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6647 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6648 | || subController == null) return privilegeFromSim; |
| 6649 | |
| 6650 | final long identity = Binder.clearCallingIdentity(); |
| 6651 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6652 | int subId = phone.getSubId(); |
| 6653 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6654 | // A test override is in place for the privileges for this subId, so don't try to |
| 6655 | // read the subscription privileges. |
| 6656 | return privilegeFromSim; |
| 6657 | } |
| 6658 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6659 | SubscriptionManager subManager = (SubscriptionManager) |
| 6660 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6661 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6662 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6663 | } finally { |
| 6664 | Binder.restoreCallingIdentity(identity); |
| 6665 | } |
| 6666 | } |
| 6667 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6668 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6669 | public int getCarrierPrivilegeStatus(int subId) { |
| 6670 | final Phone phone = getPhone(subId); |
| 6671 | if (phone == null) { |
| 6672 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6673 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6674 | } |
| 6675 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6676 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6677 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6678 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6679 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6680 | |
| 6681 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6682 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6683 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6684 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6685 | |
| 6686 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6687 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6688 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6689 | final Phone phone = getPhone(subId); |
| 6690 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6691 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6692 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6693 | } |
| 6694 | UiccProfile profile = |
| 6695 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6696 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6697 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6698 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6699 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6700 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6701 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6702 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6703 | } |
| 6704 | |
| 6705 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6706 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6707 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6708 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6709 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6713 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6714 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6715 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6716 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6717 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6718 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6719 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6720 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | @Override |
| 6724 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Sarah Chin | fc3169b | 2021-04-28 20:21:03 -0700 | [diff] [blame] | 6725 | // TODO(b/186774706): Remove @RequiresPermission from TelephonyManager API |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6726 | if (TextUtils.isEmpty(pkgName)) |
| 6727 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6728 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6729 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6730 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6731 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6732 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6733 | continue; |
| 6734 | } |
| 6735 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6736 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6737 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6738 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6739 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6740 | break; |
| 6741 | } |
| 6742 | } |
| 6743 | |
| 6744 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6745 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6746 | |
| 6747 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6748 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6749 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6750 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6751 | loge("phoneId " + phoneId + " is not valid."); |
| 6752 | return null; |
| 6753 | } |
| 6754 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6755 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6756 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6757 | return null ; |
| 6758 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6759 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6760 | } |
| 6761 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6762 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6763 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6764 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6765 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6766 | List<String> privilegedPackages = new ArrayList<>(); |
| 6767 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6768 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6769 | // has UICC in that slot. |
| 6770 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6771 | if (card.hasCarrierPrivilegeRules()) { |
| 6772 | if (packages == null) { |
| 6773 | // Only check packages in user 0 for now |
| 6774 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6775 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6776 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6777 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6778 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6779 | } |
| 6780 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6781 | PackageInfo pkgInfo = packages.get(p); |
| 6782 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6783 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6784 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6785 | privilegedPackages.add(pkgInfo.packageName); |
| 6786 | } |
| 6787 | } |
| 6788 | } |
| 6789 | } |
| 6790 | return privilegedPackages; |
| 6791 | } |
| 6792 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6793 | @Override |
| 6794 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6795 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6796 | |
| 6797 | final long identity = Binder.clearCallingIdentity(); |
| 6798 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6799 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6800 | try { |
| 6801 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6802 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6803 | } |
| 6804 | } finally { |
| 6805 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6806 | } |
| 6807 | return privilegedPackages; |
| 6808 | } |
| 6809 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6810 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6811 | final Phone phone = getPhone(subId); |
| 6812 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6813 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6814 | return null; |
| 6815 | } |
| 6816 | String iccId = card.getIccId(); |
| 6817 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6818 | return null; |
| 6819 | } |
| 6820 | return iccId; |
| 6821 | } |
| 6822 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6823 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6824 | public void setCallComposerStatus(int subId, int status) { |
| 6825 | enforceModifyPermission(); |
| 6826 | |
| 6827 | final long identity = Binder.clearCallingIdentity(); |
| 6828 | try { |
| 6829 | Phone phone = getPhone(subId); |
| 6830 | if (phone != null) { |
| 6831 | Phone defaultPhone = phone.getImsPhone(); |
| 6832 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6833 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6834 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6835 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6836 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6837 | } |
| 6838 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6839 | } catch (ImsException e) { |
| 6840 | throw new ServiceSpecificException(e.getCode()); |
| 6841 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6842 | Binder.restoreCallingIdentity(identity); |
| 6843 | } |
| 6844 | } |
| 6845 | |
| 6846 | @Override |
| 6847 | public int getCallComposerStatus(int subId) { |
| 6848 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6849 | |
| 6850 | final long identity = Binder.clearCallingIdentity(); |
| 6851 | try { |
| 6852 | Phone phone = getPhone(subId); |
| 6853 | if (phone != null) { |
| 6854 | Phone defaultPhone = phone.getImsPhone(); |
| 6855 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6856 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6857 | return imsPhone.getCallComposerStatus(); |
| 6858 | } |
| 6859 | } |
| 6860 | } finally { |
| 6861 | Binder.restoreCallingIdentity(identity); |
| 6862 | } |
| 6863 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6864 | } |
| 6865 | |
| 6866 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6867 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6868 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6869 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6870 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6872 | final long identity = Binder.clearCallingIdentity(); |
| 6873 | try { |
| 6874 | final String iccId = getIccId(subId); |
| 6875 | final Phone phone = getPhone(subId); |
| 6876 | if (phone == null) { |
| 6877 | return false; |
| 6878 | } |
| 6879 | final String subscriberId = phone.getSubscriberId(); |
| 6880 | |
| 6881 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6882 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6883 | + subscriberId + " to " + number); |
| 6884 | } |
| 6885 | |
| 6886 | if (TextUtils.isEmpty(iccId)) { |
| 6887 | return false; |
| 6888 | } |
| 6889 | |
| 6890 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6891 | |
| 6892 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6893 | if (alphaTag == null) { |
| 6894 | editor.remove(alphaTagPrefKey); |
| 6895 | } else { |
| 6896 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6897 | } |
| 6898 | |
| 6899 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6900 | // track all merged IMSIs based on line number |
| 6901 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6902 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6903 | if (number == null) { |
| 6904 | editor.remove(numberPrefKey); |
| 6905 | editor.remove(subscriberPrefKey); |
| 6906 | } else { |
| 6907 | editor.putString(numberPrefKey, number); |
| 6908 | editor.putString(subscriberPrefKey, subscriberId); |
| 6909 | } |
| 6910 | |
| 6911 | editor.commit(); |
| 6912 | return true; |
| 6913 | } finally { |
| 6914 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6915 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6916 | } |
| 6917 | |
| 6918 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6919 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6920 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6921 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6923 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6924 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6925 | return null; |
| 6926 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6927 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6928 | final long identity = Binder.clearCallingIdentity(); |
| 6929 | try { |
| 6930 | String iccId = getIccId(subId); |
| 6931 | if (iccId != null) { |
| 6932 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6933 | if (DBG_MERGE) { |
| 6934 | log("getLine1NumberForDisplay returning " |
| 6935 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6936 | } |
| 6937 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6938 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6940 | return null; |
| 6941 | } finally { |
| 6942 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6943 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6944 | } |
| 6945 | |
| 6946 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6947 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6948 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6949 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6950 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6951 | return null; |
| 6952 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6953 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6954 | final long identity = Binder.clearCallingIdentity(); |
| 6955 | try { |
| 6956 | String iccId = getIccId(subId); |
| 6957 | if (iccId != null) { |
| 6958 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6959 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6960 | } |
| 6961 | return null; |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6964 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6965 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6966 | |
| 6967 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6968 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6969 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6970 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6971 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6973 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6974 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6975 | return null; |
| 6976 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6977 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6978 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6979 | // the process, where TelephonyManager was instantiated. |
| 6980 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6981 | final long identity = Binder.clearCallingIdentity(); |
| 6982 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6983 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6984 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6985 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6986 | |
| 6987 | // Figure out what subscribers are currently active |
| 6988 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6989 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6990 | // Only consider subs which match the current subId |
| 6991 | // This logic can be simplified. See b/131189269 for progress. |
| 6992 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6993 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | |
| 6996 | // First pass, find a number override for an active subscriber |
| 6997 | String mergeNumber = null; |
| 6998 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6999 | for (String key : prefs.keySet()) { |
| 7000 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7001 | final String subscriberId = (String) prefs.get(key); |
| 7002 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7003 | final String iccId = key.substring( |
| 7004 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7005 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7006 | mergeNumber = (String) prefs.get(numberKey); |
| 7007 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7008 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7009 | + " for active subscriber " + subscriberId); |
| 7010 | } |
| 7011 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7012 | break; |
| 7013 | } |
| 7014 | } |
| 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | // Shortcut when no active merged subscribers |
| 7019 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7020 | return null; |
| 7021 | } |
| 7022 | |
| 7023 | // Second pass, find all subscribers under that line override |
| 7024 | final ArraySet<String> result = new ArraySet<>(); |
| 7025 | for (String key : prefs.keySet()) { |
| 7026 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7027 | final String number = (String) prefs.get(key); |
| 7028 | if (mergeNumber.equals(number)) { |
| 7029 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7030 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7031 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7032 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7033 | result.add(subscriberId); |
| 7034 | } |
| 7035 | } |
| 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7040 | Arrays.sort(resultArray); |
| 7041 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7042 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7044 | } |
| 7045 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7048 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7052 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7053 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7054 | |
| 7055 | final long identity = Binder.clearCallingIdentity(); |
| 7056 | try { |
| 7057 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7058 | TelephonyManager.class); |
| 7059 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7060 | if (subscriberId == null) { |
| 7061 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7062 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7063 | + subId); |
| 7064 | } |
| 7065 | return null; |
| 7066 | } |
| 7067 | |
| 7068 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7069 | .getSubscriptionInfo(subId); |
| 7070 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7071 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7072 | if (groupUuid == null) { |
| 7073 | return new String[]{subscriberId}; |
| 7074 | } |
| 7075 | |
| 7076 | // Get all subscriberIds from the group. |
| 7077 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7078 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7079 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7080 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7081 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7082 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7083 | if (subscriberId != null) { |
| 7084 | mergedSubscriberIds.add(subscriberId); |
| 7085 | } |
| 7086 | } |
| 7087 | |
| 7088 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7089 | } finally { |
| 7090 | Binder.restoreCallingIdentity(identity); |
| 7091 | |
| 7092 | } |
| 7093 | } |
| 7094 | |
| 7095 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7096 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7097 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7098 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7099 | |
| 7100 | final long identity = Binder.clearCallingIdentity(); |
| 7101 | try { |
| 7102 | final Phone phone = getPhone(subId); |
| 7103 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7104 | } finally { |
| 7105 | Binder.restoreCallingIdentity(identity); |
| 7106 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7107 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7108 | |
| 7109 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7110 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7111 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7112 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7113 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7114 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | |
| 7116 | final long identity = Binder.clearCallingIdentity(); |
| 7117 | try { |
| 7118 | final Phone phone = getPhone(subId); |
| 7119 | if (phone == null) { |
| 7120 | return false; |
| 7121 | } |
| 7122 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7123 | cdmaNonRoamingList); |
| 7124 | } finally { |
| 7125 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7126 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7127 | } |
| 7128 | |
| 7129 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7130 | @Deprecated |
| 7131 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7132 | enforceModifyPermission(); |
| 7133 | |
| 7134 | int returnValue = 0; |
| 7135 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7136 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7137 | if(result.exception == null) { |
| 7138 | if (result.result != null) { |
| 7139 | byte[] responseData = (byte[])(result.result); |
| 7140 | if(responseData.length > oemResp.length) { |
| 7141 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7142 | responseData.length + "bytes. Buffer Size is " + |
| 7143 | oemResp.length + "bytes."); |
| 7144 | } |
| 7145 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7146 | returnValue = responseData.length; |
| 7147 | } |
| 7148 | } else { |
| 7149 | CommandException ex = (CommandException) result.exception; |
| 7150 | returnValue = ex.getCommandError().ordinal(); |
| 7151 | if(returnValue > 0) returnValue *= -1; |
| 7152 | } |
| 7153 | } catch (RuntimeException e) { |
| 7154 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7155 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7156 | if(returnValue > 0) returnValue *= -1; |
| 7157 | } |
| 7158 | |
| 7159 | return returnValue; |
| 7160 | } |
| 7161 | |
| 7162 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7163 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7164 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7165 | try { |
| 7166 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7167 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7168 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7169 | } catch (SecurityException e) { |
| 7170 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7171 | throw e; |
| 7172 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7173 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7174 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7175 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7176 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7177 | final long identity = Binder.clearCallingIdentity(); |
| 7178 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7179 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7180 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7181 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7182 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| 7185 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7186 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7187 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7188 | |
| 7189 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7190 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7191 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7192 | try { |
| 7193 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7194 | Binder.getCallingUid())) { |
| 7195 | throw new SecurityException("Package uid and package name do not match: " |
| 7196 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 7197 | } |
| 7198 | } catch (PackageManager.NameNotFoundException e) { |
| 7199 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 7200 | } |
| 7201 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7202 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7203 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7204 | throw new SecurityException("App must be the dialer role holder to" |
| 7205 | + " upload a call composer pic"); |
| 7206 | } |
| 7207 | |
| 7208 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7209 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7210 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7211 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7212 | boolean readUntilEnd = false; |
| 7213 | int totalBytesRead = 0; |
| 7214 | byte[] buffer = new byte[16 * 1024]; |
| 7215 | while (true) { |
| 7216 | int numRead; |
| 7217 | try { |
| 7218 | numRead = input.read(buffer); |
| 7219 | } catch (IOException e) { |
| 7220 | try { |
| 7221 | fd.checkError(); |
| 7222 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7223 | null); |
| 7224 | } catch (IOException e1) { |
| 7225 | // This means that the other side closed explicitly with an error. If this |
| 7226 | // happens, log and ignore. |
| 7227 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7228 | } |
| 7229 | break; |
| 7230 | } |
| 7231 | if (numRead == -1) { |
| 7232 | readUntilEnd = true; |
| 7233 | break; |
| 7234 | } |
| 7235 | totalBytesRead += numRead; |
| 7236 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7237 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7238 | try { |
| 7239 | input.close(); |
| 7240 | } catch (IOException e) { |
| 7241 | // ignore |
| 7242 | } |
| 7243 | break; |
| 7244 | } |
| 7245 | output.write(buffer, 0, numRead); |
| 7246 | } |
| 7247 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7248 | // close is above, where the picture size is too big. |
| 7249 | |
| 7250 | try { |
| 7251 | fd.checkError(); |
| 7252 | } catch (IOException e) { |
| 7253 | loge("Remote end for call composer closed with an error: " + e); |
| 7254 | return; |
| 7255 | } |
| 7256 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7257 | if (!readUntilEnd) { |
| 7258 | loge("Did not finish reading entire image; aborting"); |
| 7259 | return; |
| 7260 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7261 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7262 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7263 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7264 | new CallComposerPictureTransfer.Factory() {}, |
| 7265 | imageData, |
| 7266 | (result) -> { |
| 7267 | if (result.first != null) { |
| 7268 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7269 | Bundle outputResult = new Bundle(); |
| 7270 | outputResult.putParcelable( |
| 7271 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7272 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7273 | outputResult); |
| 7274 | } else { |
| 7275 | callback.send(result.second, null); |
| 7276 | } |
| 7277 | } |
| 7278 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7279 | }); |
| 7280 | } |
| 7281 | |
| 7282 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7283 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7284 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7285 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7286 | |
| 7287 | final long identity = Binder.clearCallingIdentity(); |
| 7288 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7289 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7290 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7297 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7298 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7300 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7301 | return false; |
| 7302 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
| 7306 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7307 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7308 | // In the long run, we may instead need to check if there exists a connection service |
| 7309 | // which can support video calling. |
| 7310 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7311 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | return imsManager.isVtEnabledByPlatform() |
| 7313 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7314 | && imsManager.isVtEnabledByUser(); |
| 7315 | } finally { |
| 7316 | Binder.restoreCallingIdentity(identity); |
| 7317 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7318 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7319 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7320 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7321 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7322 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7323 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7324 | mApp, subId, callingPackage, callingFeatureId, |
| 7325 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7326 | return false; |
| 7327 | } |
| 7328 | |
| 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
| 7331 | CarrierConfigManager configManager = |
| 7332 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7333 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7334 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7335 | } finally { |
| 7336 | Binder.restoreCallingIdentity(identity); |
| 7337 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7338 | } |
| 7339 | |
| 7340 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7341 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7342 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7343 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | return false; |
| 7345 | } |
| 7346 | |
| 7347 | final long identity = Binder.clearCallingIdentity(); |
| 7348 | try { |
| 7349 | CarrierConfigManager configManager = |
| 7350 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7351 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7352 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
| 7355 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7356 | } |
| 7357 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7358 | @Override |
| 7359 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7360 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7361 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7362 | } |
| 7363 | |
| 7364 | @Override |
| 7365 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | final long identity = Binder.clearCallingIdentity(); |
| 7367 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7368 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7369 | } finally { |
| 7370 | Binder.restoreCallingIdentity(identity); |
| 7371 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7372 | } |
| 7373 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7374 | /** |
| 7375 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7376 | * support for the feature and device firmware support. |
| 7377 | * |
| 7378 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7379 | */ |
| 7380 | @Override |
| 7381 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7382 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7383 | final Phone phone = getPhone(subscriptionId); |
| 7384 | if (phone == null) { |
| 7385 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7386 | return false; |
| 7387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7389 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7390 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7391 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7392 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7393 | return isCarrierSupported && isDeviceSupported; |
| 7394 | } finally { |
| 7395 | Binder.restoreCallingIdentity(identity); |
| 7396 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7397 | } |
| 7398 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7399 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7400 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7401 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7402 | * 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] | 7403 | */ |
| 7404 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7407 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7408 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7409 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7410 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7411 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7412 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7416 | } |
| 7417 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7418 | @Deprecated |
| 7419 | @Override |
| 7420 | public String getDeviceId(String callingPackage) { |
| 7421 | return getDeviceIdWithFeature(callingPackage, null); |
| 7422 | } |
| 7423 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7424 | /** |
| 7425 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7426 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7427 | * |
| 7428 | * <p>Requires Permission: |
| 7429 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7430 | */ |
| 7431 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7432 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7433 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7434 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7435 | return null; |
| 7436 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7437 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7438 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7440 | return null; |
| 7441 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7442 | |
| 7443 | final long identity = Binder.clearCallingIdentity(); |
| 7444 | try { |
| 7445 | return phone.getDeviceId(); |
| 7446 | } finally { |
| 7447 | Binder.restoreCallingIdentity(identity); |
| 7448 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7451 | /** |
| 7452 | * {@hide} |
| 7453 | * Returns the IMS Registration Status on a particular subid |
| 7454 | * |
| 7455 | * @param subId |
| 7456 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7457 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7458 | Phone phone = getPhone(subId); |
| 7459 | if (phone != null) { |
| 7460 | return phone.isImsRegistered(); |
| 7461 | } else { |
| 7462 | return false; |
| 7463 | } |
| 7464 | } |
| 7465 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7466 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7467 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7468 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7470 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7471 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7472 | } |
| 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
| 7475 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7476 | } finally { |
| 7477 | Binder.restoreCallingIdentity(identity); |
| 7478 | } |
| 7479 | } |
| 7480 | |
| 7481 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7482 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7483 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7484 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7485 | mApp, |
| 7486 | subscriptionId, |
| 7487 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7488 | final long identity = Binder.clearCallingIdentity(); |
| 7489 | try { |
| 7490 | Phone phone = getPhone(subscriptionId); |
| 7491 | if (phone == null) { |
| 7492 | return null; |
| 7493 | } |
| 7494 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7495 | } finally { |
| 7496 | Binder.restoreCallingIdentity(identity); |
| 7497 | } |
| 7498 | } |
| 7499 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7500 | /** |
| 7501 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7502 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7503 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | final long identity = Binder.clearCallingIdentity(); |
| 7505 | try { |
| 7506 | Phone phone = getPhone(subId); |
| 7507 | if (phone != null) { |
| 7508 | return phone.isWifiCallingEnabled(); |
| 7509 | } else { |
| 7510 | return false; |
| 7511 | } |
| 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7514 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7515 | } |
| 7516 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7517 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7518 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7519 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7520 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | try { |
| 7523 | Phone phone = getPhone(subId); |
| 7524 | if (phone != null) { |
| 7525 | return phone.isVideoEnabled(); |
| 7526 | } else { |
| 7527 | return false; |
| 7528 | } |
| 7529 | } finally { |
| 7530 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7531 | } |
| 7532 | } |
| 7533 | |
| 7534 | /** |
| 7535 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7536 | * defined in {@link ImsRegistrationImplBase}. |
| 7537 | */ |
| 7538 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | final long identity = Binder.clearCallingIdentity(); |
| 7540 | try { |
| 7541 | Phone phone = getPhone(subId); |
| 7542 | if (phone != null) { |
| 7543 | return phone.getImsRegistrationTech(); |
| 7544 | } else { |
| 7545 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7546 | } |
| 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7549 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7550 | } |
| 7551 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7552 | @Override |
| 7553 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7554 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7555 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7556 | return; |
| 7557 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7558 | Phone defaultPhone = getDefaultPhone(); |
| 7559 | if (defaultPhone != null) { |
| 7560 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7561 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7562 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7563 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7564 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7565 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7566 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7567 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7568 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7569 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7570 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7571 | Phone phone = getPhone(subId); |
| 7572 | if (phone != null) { |
| 7573 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7574 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7575 | "user=" + RadioAccessFamily.getRafFromNetworkType( |
| 7576 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 7577 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7578 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7579 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7580 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7581 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7582 | // There has been issues when Sms raw table somehow stores orphan |
| 7583 | // fragments. They lead to garbled message when new fragments come |
| 7584 | // in and combined with those stale ones. In case this happens again, |
| 7585 | // user can reset all network settings which will clean up this table. |
| 7586 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7587 | // Clean up IMS settings as well here. |
| 7588 | int slotId = getSlotIndex(subId); |
| 7589 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7590 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7591 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7592 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7593 | if (defaultPhone == null) { |
| 7594 | return; |
| 7595 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7596 | // Erase modem config if erase modem on network setting is enabled. |
| 7597 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7598 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7599 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7600 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7601 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7602 | |
| 7603 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7604 | } finally { |
| 7605 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7606 | } |
| 7607 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7608 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7609 | private void cleanUpSmsRawTable(Context context) { |
| 7610 | ContentResolver resolver = context.getContentResolver(); |
| 7611 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7612 | resolver.delete(uri, null, null); |
| 7613 | } |
| 7614 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7615 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7616 | public String getSimLocaleForSubscriber(int subId) { |
| 7617 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7618 | final Phone phone = getPhone(subId); |
| 7619 | if (phone == null) { |
| 7620 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7621 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7623 | final long identity = Binder.clearCallingIdentity(); |
| 7624 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7625 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7626 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7627 | if (info == null) { |
| 7628 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7629 | return null; |
| 7630 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7631 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7632 | // preferences (EF-PL and EF-LI)... |
| 7633 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7634 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7635 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7636 | if (localeFromDefaultSim != null) { |
| 7637 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7638 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7639 | + localeFromDefaultSim); |
| 7640 | return localeFromDefaultSim.toLanguageTag(); |
| 7641 | } else { |
| 7642 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7643 | } |
| 7644 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7645 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7646 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7647 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7648 | // the SIM and carrier preferences does not include a country we add the country |
| 7649 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7650 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7651 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7652 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7653 | return mccLocale.toLanguageTag(); |
| 7654 | } |
| 7655 | |
| 7656 | if (DBG) log("No locale found - returning null"); |
| 7657 | return null; |
| 7658 | } finally { |
| 7659 | Binder.restoreCallingIdentity(identity); |
| 7660 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7661 | } |
| 7662 | |
| 7663 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7664 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7665 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7666 | } |
| 7667 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7668 | /** |
| 7669 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7670 | */ |
| 7671 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7672 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7673 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7674 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7675 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7676 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7677 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7678 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7679 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7680 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7681 | * representing the state of the modem. |
| 7682 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7683 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7684 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7685 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7686 | */ |
| 7687 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7688 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7689 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7690 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | |
| 7692 | final long identity = Binder.clearCallingIdentity(); |
| 7693 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7694 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7697 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7698 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7699 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7700 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7701 | // less than total activity duration. |
| 7702 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7703 | if (info == null) { |
| 7704 | return false; |
| 7705 | } |
| 7706 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7707 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7708 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7709 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7710 | return (info.isValid() |
| 7711 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7712 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7713 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7714 | && (totalTxTimeMs <= activityDurationMs)); |
| 7715 | } |
| 7716 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7717 | /** |
| 7718 | * {@hide} |
| 7719 | * Returns the service state information on specified subscription. |
| 7720 | */ |
| 7721 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7722 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7723 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7724 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7725 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7726 | return null; |
| 7727 | } |
| 7728 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7729 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7730 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7731 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7732 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7733 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7734 | .setCallingPid(Binder.getCallingPid()) |
| 7735 | .setCallingUid(Binder.getCallingUid()) |
| 7736 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7737 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7738 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7739 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7740 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7741 | .build()); |
| 7742 | |
| 7743 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7744 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7745 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7746 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7747 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7748 | .setCallingPid(Binder.getCallingPid()) |
| 7749 | .setCallingUid(Binder.getCallingUid()) |
| 7750 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7751 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7752 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7753 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7754 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7755 | .build()); |
| 7756 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7757 | boolean hasFinePermission = |
| 7758 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7759 | boolean hasCoarsePermission = |
| 7760 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7761 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7762 | final Phone phone = getPhone(subId); |
| 7763 | if (phone == null) { |
| 7764 | return null; |
| 7765 | } |
| 7766 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7767 | final long identity = Binder.clearCallingIdentity(); |
| 7768 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7769 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7770 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7771 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7772 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7773 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7774 | Rlog.d(LOG_TAG, |
| 7775 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7776 | return null; |
| 7777 | } |
| 7778 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7779 | ServiceState ss = phone.getServiceState(); |
| 7780 | |
| 7781 | // Scrub out the location info in ServiceState depending on what level of access |
| 7782 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7783 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7784 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7785 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
| 7788 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7789 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7790 | |
| 7791 | /** |
| 7792 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7793 | * |
| 7794 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7795 | * voicemail ringtone. |
| 7796 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7797 | * PhoneAccount. |
| 7798 | */ |
| 7799 | @Override |
| 7800 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | final long identity = Binder.clearCallingIdentity(); |
| 7802 | try { |
| 7803 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7804 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7805 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7806 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7807 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
| 7811 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7815 | * Sets the per-account voicemail ringtone. |
| 7816 | * |
| 7817 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7818 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7819 | * |
| 7820 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7821 | * voicemail ringtone. |
| 7822 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7823 | * PhoneAccount. |
| 7824 | */ |
| 7825 | @Override |
| 7826 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7827 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7828 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7829 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7830 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7831 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7833 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7834 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | |
| 7837 | final long identity = Binder.clearCallingIdentity(); |
| 7838 | try { |
| 7839 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7840 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7841 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7842 | } |
| 7843 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7844 | } finally { |
| 7845 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7846 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7850 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7851 | * |
| 7852 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7853 | * voicemail vibration setting. |
| 7854 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7855 | */ |
| 7856 | @Override |
| 7857 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7858 | final long identity = Binder.clearCallingIdentity(); |
| 7859 | try { |
| 7860 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7861 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7862 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7863 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7866 | } finally { |
| 7867 | Binder.restoreCallingIdentity(identity); |
| 7868 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7869 | } |
| 7870 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7871 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7872 | * Sets the per-account voicemail vibration. |
| 7873 | * |
| 7874 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7875 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7876 | * |
| 7877 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7878 | * voicemail vibration setting. |
| 7879 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7880 | * specific PhoneAccount. |
| 7881 | */ |
| 7882 | @Override |
| 7883 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7884 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7885 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7886 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7887 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7888 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7889 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7890 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7891 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7892 | } |
| 7893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7894 | final long identity = Binder.clearCallingIdentity(); |
| 7895 | try { |
| 7896 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7897 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7898 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | } |
| 7900 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7901 | } finally { |
| 7902 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7903 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7904 | } |
| 7905 | |
| 7906 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7907 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7908 | * |
| 7909 | * @throws SecurityException if the caller does not have the required permission |
| 7910 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7911 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7912 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7913 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7914 | } |
| 7915 | |
| 7916 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7917 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7918 | * permission. |
| 7919 | * |
| 7920 | * @throws SecurityException if the caller does not have the required permission |
| 7921 | */ |
| 7922 | private void enforceSendSmsPermission() { |
| 7923 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7924 | } |
| 7925 | |
| 7926 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7927 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7928 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7929 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7930 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7931 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7932 | final long identity = Binder.clearCallingIdentity(); |
| 7933 | try { |
| 7934 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7935 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | if (componentName == null) { |
| 7937 | throw new SecurityException( |
| 7938 | "Caller not current active visual voicemail package[null]"); |
| 7939 | } |
| 7940 | String vvmPackage = componentName.getPackageName(); |
| 7941 | if (!callingPackage.equals(vvmPackage)) { |
| 7942 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7943 | + vvmPackage + "]"); |
| 7944 | } |
| 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7947 | } |
| 7948 | } |
| 7949 | |
| 7950 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7951 | * Return the application ID for the app type. |
| 7952 | * |
| 7953 | * @param subId the subscription ID that this request applies to. |
| 7954 | * @param appType the uicc app type. |
| 7955 | * @return Application ID for specificied app type, or null if no uicc. |
| 7956 | */ |
| 7957 | @Override |
| 7958 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7959 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7960 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7961 | |
| 7962 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7963 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7964 | if (phone == null) { |
| 7965 | return null; |
| 7966 | } |
| 7967 | String aid = null; |
| 7968 | try { |
| 7969 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7970 | .getApplicationByType(appType).getAid(); |
| 7971 | } catch (Exception e) { |
| 7972 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7973 | } |
| 7974 | return aid; |
| 7975 | } finally { |
| 7976 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7977 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7978 | } |
| 7979 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7980 | /** |
| 7981 | * Return the Electronic Serial Number. |
| 7982 | * |
| 7983 | * @param subId the subscription ID that this request applies to. |
| 7984 | * @return ESN or null if error. |
| 7985 | */ |
| 7986 | @Override |
| 7987 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7988 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7989 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7990 | |
| 7991 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7992 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | if (phone == null) { |
| 7994 | return null; |
| 7995 | } |
| 7996 | String esn = null; |
| 7997 | try { |
| 7998 | esn = phone.getEsn(); |
| 7999 | } catch (Exception e) { |
| 8000 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8001 | } |
| 8002 | return esn; |
| 8003 | } finally { |
| 8004 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8005 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8006 | } |
| 8007 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8008 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8009 | * Return the Preferred Roaming List Version. |
| 8010 | * |
| 8011 | * @param subId the subscription ID that this request applies to. |
| 8012 | * @return PRLVersion or null if error. |
| 8013 | */ |
| 8014 | @Override |
| 8015 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8016 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8017 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | |
| 8019 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8020 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | if (phone == null) { |
| 8022 | return null; |
| 8023 | } |
| 8024 | String cdmaPrlVersion = null; |
| 8025 | try { |
| 8026 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8027 | } catch (Exception e) { |
| 8028 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8029 | } |
| 8030 | return cdmaPrlVersion; |
| 8031 | } finally { |
| 8032 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8033 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8034 | } |
| 8035 | |
| 8036 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8037 | * Get snapshot of Telephony histograms |
| 8038 | * @return List of Telephony histograms |
| 8039 | * @hide |
| 8040 | */ |
| 8041 | @Override |
| 8042 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8044 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8045 | |
| 8046 | final long identity = Binder.clearCallingIdentity(); |
| 8047 | try { |
| 8048 | return RIL.getTelephonyRILTimingHistograms(); |
| 8049 | } finally { |
| 8050 | Binder.restoreCallingIdentity(identity); |
| 8051 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8052 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8053 | |
| 8054 | /** |
| 8055 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8056 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8057 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8058 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8059 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8060 | * @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] | 8061 | */ |
| 8062 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8063 | @TelephonyManager.SetCarrierRestrictionResult |
| 8064 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8065 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8066 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8067 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8068 | if (carrierRestrictionRules == null) { |
| 8069 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8070 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8072 | final long identity = Binder.clearCallingIdentity(); |
| 8073 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8074 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8075 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8076 | } finally { |
| 8077 | Binder.restoreCallingIdentity(identity); |
| 8078 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8079 | } |
| 8080 | |
| 8081 | /** |
| 8082 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8083 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8084 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8085 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8086 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8087 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8088 | */ |
| 8089 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8090 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8091 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8092 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8093 | |
| 8094 | final long identity = Binder.clearCallingIdentity(); |
| 8095 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8096 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8097 | if (response instanceof CarrierRestrictionRules) { |
| 8098 | return (CarrierRestrictionRules) response; |
| 8099 | } |
| 8100 | // Response is an Exception of some kind, |
| 8101 | // which is signalled to the user as a NULL retval |
| 8102 | return null; |
| 8103 | } catch (Exception e) { |
| 8104 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8105 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| 8108 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8109 | } |
| 8110 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8111 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8112 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8113 | * @param subId the subscription ID that this action applies to. |
| 8114 | * @param enabled control enable or disable radio. |
| 8115 | * {@hide} |
| 8116 | */ |
| 8117 | @Override |
| 8118 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8119 | enforceModifyPermission(); |
| 8120 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | |
| 8122 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8123 | if (phone == null) { |
| 8124 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8125 | return; |
| 8126 | } |
| 8127 | try { |
| 8128 | phone.carrierActionSetRadioEnabled(enabled); |
| 8129 | } catch (Exception e) { |
| 8130 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8131 | } finally { |
| 8132 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8133 | } |
| 8134 | } |
| 8135 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8136 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8137 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8138 | * network status based on which carrier apps could apply actions accordingly, |
| 8139 | * enable/disable default url handler for example. |
| 8140 | * |
| 8141 | * @param subId the subscription ID that this action applies to. |
| 8142 | * @param report control start/stop reporting the default network status. |
| 8143 | * {@hide} |
| 8144 | */ |
| 8145 | @Override |
| 8146 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8147 | enforceModifyPermission(); |
| 8148 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | |
| 8150 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8151 | if (phone == null) { |
| 8152 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8153 | return; |
| 8154 | } |
| 8155 | try { |
| 8156 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8157 | } catch (Exception e) { |
| 8158 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8159 | } finally { |
| 8160 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8161 | } |
| 8162 | } |
| 8163 | |
| 8164 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8165 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8166 | * @param subId the subscription ID that this action applies to. |
| 8167 | * {@hide} |
| 8168 | */ |
| 8169 | @Override |
| 8170 | public void carrierActionResetAll(int subId) { |
| 8171 | enforceModifyPermission(); |
| 8172 | final Phone phone = getPhone(subId); |
| 8173 | if (phone == null) { |
| 8174 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8175 | return; |
| 8176 | } |
| 8177 | try { |
| 8178 | phone.carrierActionResetAll(); |
| 8179 | } catch (Exception e) { |
| 8180 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8181 | } |
| 8182 | } |
| 8183 | |
| 8184 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8185 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8186 | * bug report is being generated. |
| 8187 | */ |
| 8188 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8189 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8190 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8191 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8192 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8193 | + Binder.getCallingPid() |
| 8194 | + ", uid=" + Binder.getCallingUid() |
| 8195 | + "without permission " |
| 8196 | + android.Manifest.permission.DUMP); |
| 8197 | return; |
| 8198 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8199 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8200 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8201 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8202 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8203 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8204 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8205 | @NonNull String[] args) { |
| 8206 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8207 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8208 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8209 | } |
| 8210 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8211 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8212 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8213 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8214 | * @param reason the reason the data enable change is taking place |
| 8215 | * @param enabled True if enabling the data, otherwise disabling. |
| 8216 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8217 | */ |
| 8218 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8219 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8220 | boolean enabled) { |
| 8221 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8222 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8223 | try { |
| 8224 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8225 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8226 | } catch (SecurityException se) { |
| 8227 | enforceModifyPermission(); |
| 8228 | } |
| 8229 | } else { |
| 8230 | enforceModifyPermission(); |
| 8231 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | |
| 8233 | final long identity = Binder.clearCallingIdentity(); |
| 8234 | try { |
| 8235 | Phone phone = getPhone(subId); |
| 8236 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8237 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8238 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8239 | } else { |
| 8240 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8242 | } |
| 8243 | } finally { |
| 8244 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8245 | } |
| 8246 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8247 | |
| 8248 | /** |
| 8249 | * Get Client request stats |
| 8250 | * @return List of Client Request Stats |
| 8251 | * @hide |
| 8252 | */ |
| 8253 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8254 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8255 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8256 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8257 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8258 | return null; |
| 8259 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8260 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8261 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
| 8264 | if (phone != null) { |
| 8265 | return phone.getClientRequestStats(); |
| 8266 | } |
| 8267 | |
| 8268 | return null; |
| 8269 | } finally { |
| 8270 | Binder.restoreCallingIdentity(identity); |
| 8271 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8272 | } |
| 8273 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8274 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8275 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8276 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8277 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8278 | |
| 8279 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8280 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8281 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8282 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8283 | * @param state State of SIM (power down, power up, pass through) |
| 8284 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8285 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8286 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8287 | * |
| 8288 | **/ |
| 8289 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8290 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8291 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8292 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8293 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8294 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | final long identity = Binder.clearCallingIdentity(); |
| 8297 | try { |
| 8298 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8299 | phone.setSimPowerState(state, null, workSource); |
| 8300 | } |
| 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | /** |
| 8307 | * Set SIM card power state. |
| 8308 | * |
| 8309 | * @param slotIndex SIM slot id. |
| 8310 | * @param state State of SIM (power down, power up, pass through) |
| 8311 | * @param callback callback to trigger after success or failure |
| 8312 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8313 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8314 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8315 | * |
| 8316 | **/ |
| 8317 | @Override |
| 8318 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8319 | IIntegerConsumer callback) { |
| 8320 | enforceModifyPermission(); |
| 8321 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8322 | |
| 8323 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8324 | |
| 8325 | final long identity = Binder.clearCallingIdentity(); |
| 8326 | try { |
| 8327 | if (phone != null) { |
| 8328 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8329 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | } |
| 8331 | } finally { |
| 8332 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8333 | } |
| 8334 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8335 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8336 | private boolean isUssdApiAllowed(int subId) { |
| 8337 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8338 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8339 | if (configManager == null) { |
| 8340 | return false; |
| 8341 | } |
| 8342 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8343 | if (pb == null) { |
| 8344 | return false; |
| 8345 | } |
| 8346 | return pb.getBoolean( |
| 8347 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8348 | } |
| 8349 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8350 | /** |
| 8351 | * Check if phone is in emergency callback mode |
| 8352 | * @return true if phone is in emergency callback mode |
| 8353 | * @param subId sub id |
| 8354 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8355 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8356 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8357 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8358 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8359 | |
| 8360 | final long identity = Binder.clearCallingIdentity(); |
| 8361 | try { |
| 8362 | if (phone != null) { |
| 8363 | return phone.isInEcm(); |
| 8364 | } else { |
| 8365 | return false; |
| 8366 | } |
| 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8369 | } |
| 8370 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8371 | |
| 8372 | /** |
| 8373 | * Get the current signal strength information for the given subscription. |
| 8374 | * Because this information is not updated when the device is in a low power state |
| 8375 | * it should not be relied-upon to be current. |
| 8376 | * @param subId Subscription index |
| 8377 | * @return the most recent cached signal strength info from the modem |
| 8378 | */ |
| 8379 | @Override |
| 8380 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8381 | final long identity = Binder.clearCallingIdentity(); |
| 8382 | try { |
| 8383 | Phone p = getPhone(subId); |
| 8384 | if (p == null) { |
| 8385 | return null; |
| 8386 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8388 | return p.getSignalStrength(); |
| 8389 | } finally { |
| 8390 | Binder.restoreCallingIdentity(identity); |
| 8391 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8392 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8393 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8394 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8395 | * Get the current modem radio state for the given slot. |
| 8396 | * @param slotIndex slot index. |
| 8397 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8398 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8399 | * @return the current radio power state from the modem |
| 8400 | */ |
| 8401 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8402 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8403 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8404 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8405 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8406 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8407 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8408 | } |
| 8409 | |
| 8410 | final long identity = Binder.clearCallingIdentity(); |
| 8411 | try { |
| 8412 | return phone.getRadioPowerState(); |
| 8413 | } finally { |
| 8414 | Binder.restoreCallingIdentity(identity); |
| 8415 | } |
| 8416 | } |
| 8417 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8418 | } |
| 8419 | |
| 8420 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8421 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8422 | * |
| 8423 | * <p>Requires one of the following permissions: |
| 8424 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8425 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8426 | * privileges. |
| 8427 | * |
| 8428 | * @param subId subscription id |
| 8429 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8430 | * {@code false}. |
| 8431 | */ |
| 8432 | @Override |
| 8433 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8434 | try { |
| 8435 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8436 | null); |
| 8437 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8438 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8439 | mApp, subId, "isDataRoamingEnabled"); |
| 8440 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8441 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8442 | boolean isEnabled = false; |
| 8443 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8444 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8445 | Phone phone = getPhone(subId); |
| 8446 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8447 | } finally { |
| 8448 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8449 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8450 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8451 | } |
| 8452 | |
| 8453 | |
| 8454 | /** |
| 8455 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8456 | * |
| 8457 | * <p> Requires permission: |
| 8458 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8459 | * privileges. |
| 8460 | * |
| 8461 | * @param subId subscription id |
| 8462 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8463 | */ |
| 8464 | @Override |
| 8465 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8466 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8467 | mApp, subId, "setDataRoamingEnabled"); |
| 8468 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8469 | final long identity = Binder.clearCallingIdentity(); |
| 8470 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8471 | Phone phone = getPhone(subId); |
| 8472 | if (phone != null) { |
| 8473 | phone.setDataRoamingEnabled(isEnabled); |
| 8474 | } |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8477 | } |
| 8478 | } |
| 8479 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8480 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8481 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8482 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8483 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8484 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8485 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8486 | boolean isAllowed = true; |
| 8487 | final long identity = Binder.clearCallingIdentity(); |
| 8488 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8489 | Phone phone = getPhone(subId); |
| 8490 | if (phone != null) { |
| 8491 | isAllowed = phone.isCspPlmnEnabled(); |
| 8492 | } |
| 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
| 8495 | } |
| 8496 | return isAllowed; |
| 8497 | } |
| 8498 | |
| 8499 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8500 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8501 | // Verify that tha callingPackage belongs to the calling UID |
| 8502 | mApp.getSystemService(AppOpsManager.class) |
| 8503 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8504 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8505 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8506 | try { |
| 8507 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8508 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8509 | } catch (SecurityException e) { |
| 8510 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8511 | // has carrier privileges on an active UICC |
| 8512 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8513 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8514 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8515 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8516 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8517 | |
| 8518 | final long identity = Binder.clearCallingIdentity(); |
| 8519 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8520 | UiccController uiccController = UiccController.getInstance(); |
| 8521 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8522 | if (hasReadPermission) { |
| 8523 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8524 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8525 | |
| 8526 | // Remove private info if the caller doesn't have access |
| 8527 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8528 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8529 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8530 | // is available |
| 8531 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8532 | if (card == null || card.getUiccProfile() == null) { |
| 8533 | // assume no access if the card or profile is unavailable |
| 8534 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8535 | continue; |
| 8536 | } |
| 8537 | UiccProfile profile = card.getUiccProfile(); |
| 8538 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8539 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8540 | filteredInfos.add(cardInfo); |
| 8541 | } else { |
| 8542 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8543 | } |
| 8544 | } |
| 8545 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
| 8548 | } |
| 8549 | } |
| 8550 | |
| 8551 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8552 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8553 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8554 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8555 | final long identity = Binder.clearCallingIdentity(); |
| 8556 | try { |
| 8557 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8558 | if (slots == null) { |
| 8559 | Rlog.i(LOG_TAG, "slots is null."); |
| 8560 | return null; |
| 8561 | } |
| 8562 | |
| 8563 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8564 | for (int i = 0; i < slots.length; i++) { |
| 8565 | UiccSlot slot = slots[i]; |
| 8566 | if (slot == null) { |
| 8567 | continue; |
| 8568 | } |
| 8569 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8570 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 | UiccCard card = slot.getUiccCard(); |
| 8572 | if (card != null) { |
| 8573 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8574 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8575 | cardId = slot.getEid(); |
| 8576 | if (TextUtils.isEmpty(cardId)) { |
| 8577 | cardId = slot.getIccId(); |
| 8578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8579 | } |
| 8580 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8581 | if (cardId != null) { |
| 8582 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8583 | // if cardId is an EID, it's all digits so this is fine |
| 8584 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8585 | } |
| 8586 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8587 | int cardState = 0; |
| 8588 | switch (slot.getCardState()) { |
| 8589 | case CARDSTATE_ABSENT: |
| 8590 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8591 | break; |
| 8592 | case CARDSTATE_PRESENT: |
| 8593 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8594 | break; |
| 8595 | case CARDSTATE_ERROR: |
| 8596 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8597 | break; |
| 8598 | case CARDSTATE_RESTRICTED: |
| 8599 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8600 | break; |
| 8601 | default: |
| 8602 | break; |
| 8603 | |
| 8604 | } |
| 8605 | |
| 8606 | infos[i] = new UiccSlotInfo( |
| 8607 | slot.isActive(), |
| 8608 | slot.isEuicc(), |
| 8609 | cardId, |
| 8610 | cardState, |
| 8611 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8612 | slot.isExtendedApduSupported(), |
| 8613 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8614 | } |
| 8615 | return infos; |
| 8616 | } finally { |
| 8617 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8618 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8619 | } |
| 8620 | |
| 8621 | @Override |
| 8622 | public boolean switchSlots(int[] physicalSlots) { |
| 8623 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8624 | |
| 8625 | final long identity = Binder.clearCallingIdentity(); |
| 8626 | try { |
| 8627 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8628 | } finally { |
| 8629 | Binder.restoreCallingIdentity(identity); |
| 8630 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8631 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8632 | |
| 8633 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8634 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8635 | final long identity = Binder.clearCallingIdentity(); |
| 8636 | try { |
| 8637 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8643 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8644 | * A test API to reload the UICC profile. |
| 8645 | * |
| 8646 | * <p>Requires that the calling app has permission |
| 8647 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8648 | * @hide |
| 8649 | */ |
| 8650 | @Override |
| 8651 | public void refreshUiccProfile(int subId) { |
| 8652 | enforceModifyPermission(); |
| 8653 | |
| 8654 | final long identity = Binder.clearCallingIdentity(); |
| 8655 | try { |
| 8656 | Phone phone = getPhone(subId); |
| 8657 | if (phone == null) { |
| 8658 | return; |
| 8659 | } |
| 8660 | UiccCard uiccCard = phone.getUiccCard(); |
| 8661 | if (uiccCard == null) { |
| 8662 | return; |
| 8663 | } |
| 8664 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8665 | if (uiccProfile == null) { |
| 8666 | return; |
| 8667 | } |
| 8668 | uiccProfile.refresh(); |
| 8669 | } finally { |
| 8670 | Binder.restoreCallingIdentity(identity); |
| 8671 | } |
| 8672 | } |
| 8673 | |
| 8674 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8675 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8676 | */ |
| 8677 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8678 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8679 | } |
| 8680 | |
| 8681 | /** |
| 8682 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8683 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8684 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8685 | */ |
| 8686 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8687 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8688 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8689 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8690 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8691 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8692 | return isDataRoamingEnabled; |
| 8693 | } |
| 8694 | |
| 8695 | /** |
| 8696 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8697 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8698 | */ |
| 8699 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8700 | List<Integer> list = TelephonyProperties.default_network(); |
| 8701 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8702 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8703 | return list.get(phoneId); |
| 8704 | } |
| 8705 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8706 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8707 | |
| 8708 | @Override |
| 8709 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8710 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8711 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8712 | |
| 8713 | final long identity = Binder.clearCallingIdentity(); |
| 8714 | try { |
| 8715 | final Phone phone = getPhone(subId); |
| 8716 | if (phone == null) { |
| 8717 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8718 | return; |
| 8719 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8720 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8721 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8722 | if (carrierPrivilegeRules == null) { |
| 8723 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8724 | } else { |
| 8725 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8726 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8727 | } finally { |
| 8728 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8729 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8730 | } |
| 8731 | |
| 8732 | @Override |
| 8733 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8734 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8735 | |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
| 8737 | try { |
| 8738 | final Phone phone = getPhone(subId); |
| 8739 | if (phone == null) { |
| 8740 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8741 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8742 | } |
| 8743 | return phone.getCarrierIdListVersion(); |
| 8744 | } finally { |
| 8745 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8746 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8747 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8748 | |
| 8749 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8750 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8751 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8752 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8753 | mApp, subId, callingPackage, callingFeatureId, |
| 8754 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8755 | return -1; |
| 8756 | } |
| 8757 | |
| 8758 | final long identity = Binder.clearCallingIdentity(); |
| 8759 | try { |
| 8760 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8761 | } finally { |
| 8762 | Binder.restoreCallingIdentity(identity); |
| 8763 | } |
| 8764 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8765 | |
| 8766 | @Override |
| 8767 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8768 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8769 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8770 | mApp, subId, "getCdmaRoamingMode"); |
| 8771 | |
| 8772 | final long identity = Binder.clearCallingIdentity(); |
| 8773 | try { |
| 8774 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8775 | } finally { |
| 8776 | Binder.restoreCallingIdentity(identity); |
| 8777 | } |
| 8778 | } |
| 8779 | |
| 8780 | @Override |
| 8781 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8783 | mApp, subId, "setCdmaRoamingMode"); |
| 8784 | |
| 8785 | final long identity = Binder.clearCallingIdentity(); |
| 8786 | try { |
| 8787 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8788 | } finally { |
| 8789 | Binder.restoreCallingIdentity(identity); |
| 8790 | } |
| 8791 | } |
| 8792 | |
| 8793 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8794 | public int getCdmaSubscriptionMode(int subId) { |
| 8795 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8796 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8797 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8798 | |
| 8799 | final long identity = Binder.clearCallingIdentity(); |
| 8800 | try { |
| 8801 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(identity); |
| 8804 | } |
| 8805 | } |
| 8806 | |
| 8807 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8808 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8810 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8811 | |
| 8812 | final long identity = Binder.clearCallingIdentity(); |
| 8813 | try { |
| 8814 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8815 | } finally { |
| 8816 | Binder.restoreCallingIdentity(identity); |
| 8817 | } |
| 8818 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8819 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8820 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8821 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8822 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8824 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8825 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8826 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8827 | } |
| 8828 | final long identity = Binder.clearCallingIdentity(); |
| 8829 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8830 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8831 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8832 | if (phone.getEmergencyNumberTracker() != null |
| 8833 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8834 | emergencyNumberListInternal.put( |
| 8835 | phone.getSubId(), |
| 8836 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8837 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8838 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8839 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8840 | } finally { |
| 8841 | Binder.restoreCallingIdentity(identity); |
| 8842 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8843 | } |
| 8844 | |
| 8845 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8846 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8847 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8848 | if (!exactMatch) { |
| 8849 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8850 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8851 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8852 | } |
| 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8855 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8856 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8857 | && phone.getEmergencyNumberTracker() |
| 8858 | .isEmergencyNumber(number, exactMatch)) { |
| 8859 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8860 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8861 | } |
| 8862 | return false; |
| 8863 | } finally { |
| 8864 | Binder.restoreCallingIdentity(identity); |
| 8865 | } |
| 8866 | } |
| 8867 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8868 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 8869 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 8870 | */ |
| 8871 | @Override |
| 8872 | public void startEmergencyCallbackMode() { |
| 8873 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8874 | "startEmergencyCallbackMode"); |
| 8875 | enforceModifyPermission(); |
| 8876 | final long identity = Binder.clearCallingIdentity(); |
| 8877 | try { |
| 8878 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8879 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 8880 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 8881 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 8882 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 8883 | gsmCdmaPhone.obtainMessage( |
| 8884 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 8885 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 8886 | } |
| 8887 | } |
| 8888 | } finally { |
| 8889 | Binder.restoreCallingIdentity(identity); |
| 8890 | } |
| 8891 | } |
| 8892 | |
| 8893 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8894 | * Update emergency number list for test mode. |
| 8895 | */ |
| 8896 | @Override |
| 8897 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8898 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8899 | "updateEmergencyNumberListTestMode"); |
| 8900 | |
| 8901 | final long identity = Binder.clearCallingIdentity(); |
| 8902 | try { |
| 8903 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8904 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8905 | if (tracker != null) { |
| 8906 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8907 | } |
| 8908 | } |
| 8909 | } finally { |
| 8910 | Binder.restoreCallingIdentity(identity); |
| 8911 | } |
| 8912 | } |
| 8913 | |
| 8914 | /** |
| 8915 | * Get the full emergency number list for test mode. |
| 8916 | */ |
| 8917 | @Override |
| 8918 | public List<String> getEmergencyNumberListTestMode() { |
| 8919 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8920 | "getEmergencyNumberListTestMode"); |
| 8921 | |
| 8922 | final long identity = Binder.clearCallingIdentity(); |
| 8923 | try { |
| 8924 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8925 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8926 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8927 | if (tracker != null) { |
| 8928 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8929 | emergencyNumbers.add(num.getNumber()); |
| 8930 | } |
| 8931 | } |
| 8932 | } |
| 8933 | return new ArrayList<>(emergencyNumbers); |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| 8938 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8939 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8940 | public int getEmergencyNumberDbVersion(int subId) { |
| 8941 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8942 | |
| 8943 | final long identity = Binder.clearCallingIdentity(); |
| 8944 | try { |
| 8945 | final Phone phone = getPhone(subId); |
| 8946 | if (phone == null) { |
| 8947 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8948 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8949 | } |
| 8950 | return phone.getEmergencyNumberDbVersion(); |
| 8951 | } finally { |
| 8952 | Binder.restoreCallingIdentity(identity); |
| 8953 | } |
| 8954 | } |
| 8955 | |
| 8956 | @Override |
| 8957 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8958 | enforceModifyPermission(); |
| 8959 | |
| 8960 | final long identity = Binder.clearCallingIdentity(); |
| 8961 | try { |
| 8962 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8963 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8964 | if (tracker != null) { |
| 8965 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8966 | } |
| 8967 | } |
| 8968 | } finally { |
| 8969 | Binder.restoreCallingIdentity(identity); |
| 8970 | } |
| 8971 | } |
| 8972 | |
| 8973 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8974 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8975 | enforceActiveEmergencySessionPermission(); |
| 8976 | |
| 8977 | final long identity = Binder.clearCallingIdentity(); |
| 8978 | try { |
| 8979 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8980 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8981 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8982 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8983 | } |
| 8984 | } |
| 8985 | } finally { |
| 8986 | Binder.restoreCallingIdentity(identity); |
| 8987 | } |
| 8988 | } |
| 8989 | |
| 8990 | @Override |
| 8991 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8992 | enforceActiveEmergencySessionPermission(); |
| 8993 | |
| 8994 | final long identity = Binder.clearCallingIdentity(); |
| 8995 | try { |
| 8996 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8997 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8998 | if (tracker != null) { |
| 8999 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9000 | } |
| 9001 | } |
| 9002 | } finally { |
| 9003 | Binder.restoreCallingIdentity(identity); |
| 9004 | } |
| 9005 | } |
| 9006 | |
| 9007 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9008 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9009 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9010 | Phone phone = getPhone(subId); |
| 9011 | if (phone == null) { |
| 9012 | return null; |
| 9013 | } |
| 9014 | final long identity = Binder.clearCallingIdentity(); |
| 9015 | try { |
| 9016 | UiccProfile profile = UiccController.getInstance() |
| 9017 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9018 | if (profile != null) { |
| 9019 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9020 | } |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
| 9024 | return null; |
| 9025 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9026 | |
| 9027 | /** |
| 9028 | * Enable or disable a modem stack. |
| 9029 | */ |
| 9030 | @Override |
| 9031 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9032 | enforceModifyPermission(); |
| 9033 | |
| 9034 | final long identity = Binder.clearCallingIdentity(); |
| 9035 | try { |
| 9036 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9037 | if (phone == null) { |
| 9038 | return false; |
| 9039 | } else { |
| 9040 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9041 | } |
| 9042 | } finally { |
| 9043 | Binder.restoreCallingIdentity(identity); |
| 9044 | } |
| 9045 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9046 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9047 | /** |
| 9048 | * Whether a modem stack is enabled or not. |
| 9049 | */ |
| 9050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9051 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9052 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9053 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9054 | if (phone == null) return false; |
| 9055 | |
| 9056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9057 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9058 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9059 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9060 | } |
| 9061 | |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9064 | try { |
| 9065 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9066 | } catch (NoSuchElementException ex) { |
| 9067 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9068 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
| 9071 | } |
| 9072 | } |
| 9073 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9074 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9075 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9076 | enforceModifyPermission(); |
| 9077 | |
| 9078 | final long identity = Binder.clearCallingIdentity(); |
| 9079 | try { |
| 9080 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9081 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9082 | .commit(); |
| 9083 | } finally { |
| 9084 | Binder.restoreCallingIdentity(identity); |
| 9085 | } |
| 9086 | } |
| 9087 | |
| 9088 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9089 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9090 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9091 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9092 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9093 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9094 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9095 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9096 | |
| 9097 | final long identity = Binder.clearCallingIdentity(); |
| 9098 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9099 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9100 | } finally { |
| 9101 | Binder.restoreCallingIdentity(identity); |
| 9102 | } |
| 9103 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9104 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9105 | @TelephonyManager.IsMultiSimSupportedResult |
| 9106 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9107 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9108 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9109 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9110 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9111 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9112 | } |
| 9113 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9114 | // supported by the modem, indicate that it is restricted. |
| 9115 | PhoneCapability staticCapability = |
| 9116 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9117 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9118 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9119 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9120 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9121 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9122 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9123 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9124 | } |
| 9125 | // Check if support of multiple SIMs is restricted by carrier |
| 9126 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9127 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9128 | } |
| 9129 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9130 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9131 | } |
| 9132 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9133 | /** |
| 9134 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9135 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9136 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9137 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9138 | * @param numOfSims number of active sims we want to switch to |
| 9139 | */ |
| 9140 | @Override |
| 9141 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9142 | if (numOfSims == 1) { |
| 9143 | enforceModifyPermission(); |
| 9144 | } else { |
| 9145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9146 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9147 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9148 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9149 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9150 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9151 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9152 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9153 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9154 | return; |
| 9155 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9156 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9157 | } finally { |
| 9158 | Binder.restoreCallingIdentity(identity); |
| 9159 | } |
| 9160 | } |
| 9161 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9162 | @Override |
| 9163 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9164 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9165 | Phone phone = getPhone(subId); |
| 9166 | if (phone == null) { |
| 9167 | return false; |
| 9168 | } |
| 9169 | final long identity = Binder.clearCallingIdentity(); |
| 9170 | try { |
| 9171 | UiccCard uiccCard = phone.getUiccCard(); |
| 9172 | if (uiccCard == null) { |
| 9173 | return false; |
| 9174 | } |
| 9175 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 9176 | if (uiccProfile == null) { |
| 9177 | return false; |
| 9178 | } |
| 9179 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9180 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9181 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9182 | } |
| 9183 | return false; |
| 9184 | } finally { |
| 9185 | Binder.restoreCallingIdentity(identity); |
| 9186 | } |
| 9187 | } |
| 9188 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9189 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9190 | * Get whether making changes to modem configurations will trigger reboot. |
| 9191 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9192 | */ |
| 9193 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9194 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9195 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9197 | mApp, subId, callingPackage, callingFeatureId, |
| 9198 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9199 | return false; |
| 9200 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9201 | final long identity = Binder.clearCallingIdentity(); |
| 9202 | try { |
| 9203 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9204 | } finally { |
| 9205 | Binder.restoreCallingIdentity(identity); |
| 9206 | } |
| 9207 | } |
| 9208 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9209 | private void updateModemStateMetrics() { |
| 9210 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9211 | // TODO: check the state for each modem if the api is ready. |
| 9212 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9213 | } |
| 9214 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9215 | @Override |
| 9216 | public int[] getSlotsMapping() { |
| 9217 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 9218 | |
| 9219 | final long identity = Binder.clearCallingIdentity(); |
| 9220 | try { |
| 9221 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 9222 | // All logical slots should have a mapping to a physical slot. |
| 9223 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 9224 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 9225 | for (int i = 0; i < slotInfos.length; i++) { |
| 9226 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 9227 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 9228 | } |
| 9229 | } |
| 9230 | return logicalSlotsMapping; |
| 9231 | } finally { |
| 9232 | Binder.restoreCallingIdentity(identity); |
| 9233 | } |
| 9234 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9235 | |
| 9236 | /** |
| 9237 | * Get the IRadio HAL Version |
| 9238 | */ |
| 9239 | @Override |
| 9240 | public int getRadioHalVersion() { |
| 9241 | Phone phone = getDefaultPhone(); |
| 9242 | if (phone == null) return -1; |
| 9243 | HalVersion hv = phone.getHalVersion(); |
| 9244 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9245 | return hv.major * 100 + hv.minor; |
| 9246 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9247 | |
| 9248 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9249 | * Get the current calling package name. |
| 9250 | * @return the current calling package name |
| 9251 | */ |
| 9252 | @Override |
| 9253 | public String getCurrentPackageName() { |
| 9254 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9255 | } |
| 9256 | |
| 9257 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9258 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9259 | * corresponding network requests on a subId. |
| 9260 | * |
| 9261 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9262 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9263 | * 2) APN is un-metered for this subscription, or |
| 9264 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9265 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9266 | * |
| 9267 | * @return whether data is allowed for a apn type. |
| 9268 | * |
| 9269 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9270 | */ |
| 9271 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9272 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9273 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9274 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9275 | |
| 9276 | // Now that all security checks passes, perform the operation as ourselves. |
| 9277 | final long identity = Binder.clearCallingIdentity(); |
| 9278 | try { |
| 9279 | Phone phone = getPhone(subId); |
| 9280 | if (phone == null) return false; |
| 9281 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9282 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9283 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9290 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9291 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9292 | |
| 9293 | // Now that all security checks passes, perform the operation as ourselves. |
| 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | Phone phone = getPhone(subId); |
| 9297 | if (phone == null) return true; // By default return true. |
| 9298 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9299 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9300 | } finally { |
| 9301 | Binder.restoreCallingIdentity(identity); |
| 9302 | } |
| 9303 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9304 | |
| 9305 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9306 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9307 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9308 | enforceModifyPermission(); |
| 9309 | long token = Binder.clearCallingIdentity(); |
| 9310 | try { |
| 9311 | Phone phone = getPhone(subscriptionId); |
| 9312 | if (phone == null) { |
| 9313 | try { |
| 9314 | if (resultCallback != null) { |
| 9315 | resultCallback.accept(false); |
| 9316 | } |
| 9317 | } catch (RemoteException e) { |
| 9318 | // ignore |
| 9319 | } |
| 9320 | return; |
| 9321 | } |
| 9322 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9323 | Pair.create(specifiers, (x) -> { |
| 9324 | try { |
| 9325 | if (resultCallback != null) { |
| 9326 | resultCallback.accept(x); |
| 9327 | } |
| 9328 | } catch (RemoteException e) { |
| 9329 | // ignore |
| 9330 | } |
| 9331 | }); |
| 9332 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9333 | } finally { |
| 9334 | Binder.restoreCallingIdentity(token); |
| 9335 | } |
| 9336 | } |
| 9337 | |
| 9338 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9339 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9340 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9341 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9342 | mApp, subId, "getSystemSelectionChannels"); |
| 9343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9344 | final long identity = Binder.clearCallingIdentity(); |
| 9345 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9346 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9347 | if (result instanceof IllegalStateException) { |
| 9348 | throw (IllegalStateException) result; |
| 9349 | } |
| 9350 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9351 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9352 | return specifiers; |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
| 9357 | |
| 9358 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9359 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9360 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9361 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9362 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9363 | if (iccRecords == null) { |
| 9364 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9365 | return false; |
| 9366 | } |
| 9367 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9368 | } |
| 9369 | |
| 9370 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9371 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9372 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9373 | if (callingPackage == null) { |
| 9374 | callingPackage = getCurrentPackageName(); |
| 9375 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9376 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9377 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9378 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9379 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9380 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9381 | } |
| 9382 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9383 | Intent intent = new Intent(); |
| 9384 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9385 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9386 | // Bring up choose default SMS subscription dialog right now |
| 9387 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9388 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9389 | mApp.startActivity(intent); |
| 9390 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9391 | |
| 9392 | @Override |
| 9393 | public String getMmsUAProfUrl(int subId) { |
| 9394 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9395 | final long identity = Binder.clearCallingIdentity(); |
| 9396 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9397 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9398 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9399 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9400 | return carrierUAProfUrl; |
| 9401 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9402 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9403 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(identity); |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | @Override |
| 9410 | public String getMmsUserAgent(int subId) { |
| 9411 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9412 | final long identity = Binder.clearCallingIdentity(); |
| 9413 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9414 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9415 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9416 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9417 | return carrierUserAgent; |
| 9418 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9419 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9420 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9425 | |
| 9426 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9427 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9428 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9429 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9432 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9433 | if (phone == null) return false; |
| 9434 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9435 | switch (policy) { |
| 9436 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9437 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9438 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9439 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9440 | default: |
| 9441 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9442 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9443 | } finally { |
| 9444 | Binder.restoreCallingIdentity(identity); |
| 9445 | } |
| 9446 | } |
| 9447 | |
| 9448 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9449 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9450 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9451 | enforceModifyPermission(); |
| 9452 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9453 | final long identity = Binder.clearCallingIdentity(); |
| 9454 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9455 | Phone phone = getPhone(subscriptionId); |
| 9456 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9457 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9458 | switch (policy) { |
| 9459 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9460 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9461 | break; |
| 9462 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9463 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9464 | break; |
| 9465 | default: |
| 9466 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9467 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9468 | } finally { |
| 9469 | Binder.restoreCallingIdentity(identity); |
| 9470 | } |
| 9471 | } |
| 9472 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9473 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9474 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9475 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9476 | * otherwise. |
| 9477 | */ |
| 9478 | @Override |
| 9479 | public void setCepEnabled(boolean isCepEnabled) { |
| 9480 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9481 | |
| 9482 | final long identity = Binder.clearCallingIdentity(); |
| 9483 | try { |
| 9484 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9485 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9486 | Phone defaultPhone = phone.getImsPhone(); |
| 9487 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9488 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9489 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9490 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9491 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9492 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9493 | + imsPhone.getMsisdn()); |
| 9494 | } |
| 9495 | } |
| 9496 | } finally { |
| 9497 | Binder.restoreCallingIdentity(identity); |
| 9498 | } |
| 9499 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9500 | |
| 9501 | /** |
| 9502 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9503 | * |
| 9504 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9505 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9506 | * before being read. |
| 9507 | */ |
| 9508 | @Override |
| 9509 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9510 | isCompressed) { |
| 9511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9512 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9513 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9514 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9515 | } |
| 9516 | if (!isImsAvailableOnDevice()) { |
| 9517 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9518 | "IMS not available on device."); |
| 9519 | } |
| 9520 | |
| 9521 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9522 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9523 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9524 | } finally { |
| 9525 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9526 | } |
| 9527 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9528 | |
| 9529 | @Override |
| 9530 | public boolean isIccLockEnabled(int subId) { |
| 9531 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9532 | |
| 9533 | // Now that all security checks passes, perform the operation as ourselves. |
| 9534 | final long identity = Binder.clearCallingIdentity(); |
| 9535 | try { |
| 9536 | Phone phone = getPhone(subId); |
| 9537 | if (phone != null && phone.getIccCard() != null) { |
| 9538 | return phone.getIccCard().getIccLockEnabled(); |
| 9539 | } else { |
| 9540 | return false; |
| 9541 | } |
| 9542 | } finally { |
| 9543 | Binder.restoreCallingIdentity(identity); |
| 9544 | } |
| 9545 | } |
| 9546 | |
| 9547 | /** |
| 9548 | * Set the ICC pin lock enabled or disabled. |
| 9549 | * |
| 9550 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9551 | * three cases: |
| 9552 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9553 | * successfully. |
| 9554 | * - Positive number and zero for remaining password attempts. |
| 9555 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9556 | * |
| 9557 | */ |
| 9558 | @Override |
| 9559 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9560 | enforceModifyPermission(); |
| 9561 | |
| 9562 | Phone phone = getPhone(subId); |
| 9563 | if (phone == null) { |
| 9564 | return 0; |
| 9565 | } |
| 9566 | // Now that all security checks passes, perform the operation as ourselves. |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9570 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9571 | return attemptsRemaining; |
| 9572 | |
| 9573 | } catch (Exception e) { |
| 9574 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9575 | } finally { |
| 9576 | Binder.restoreCallingIdentity(identity); |
| 9577 | } |
| 9578 | return 0; |
| 9579 | } |
| 9580 | |
| 9581 | /** |
| 9582 | * Change the ICC password used in ICC pin lock. |
| 9583 | * |
| 9584 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9585 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9586 | * - Positive number and zero for remaining password attempts. |
| 9587 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9588 | * |
| 9589 | */ |
| 9590 | @Override |
| 9591 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9592 | enforceModifyPermission(); |
| 9593 | |
| 9594 | Phone phone = getPhone(subId); |
| 9595 | if (phone == null) { |
| 9596 | return 0; |
| 9597 | } |
| 9598 | // Now that all security checks passes, perform the operation as ourselves. |
| 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
| 9601 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9602 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9603 | return attemptsRemaining; |
| 9604 | |
| 9605 | } catch (Exception e) { |
| 9606 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9607 | } finally { |
| 9608 | Binder.restoreCallingIdentity(identity); |
| 9609 | } |
| 9610 | return 0; |
| 9611 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9612 | |
| 9613 | /** |
| 9614 | * Request for receiving user activity notification |
| 9615 | */ |
| 9616 | @Override |
| 9617 | public void requestUserActivityNotification() { |
| 9618 | if (!mNotifyUserActivity.get() |
| 9619 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9620 | mNotifyUserActivity.set(true); |
| 9621 | } |
| 9622 | } |
| 9623 | |
| 9624 | /** |
| 9625 | * Called when userActivity is signalled in the power manager. |
| 9626 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9627 | */ |
| 9628 | @Override |
| 9629 | public void userActivity() { |
| 9630 | // *************************************** |
| 9631 | // * Inherited from PhoneWindowManager * |
| 9632 | // *************************************** |
| 9633 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9634 | // WITH ITS LOCKS HELD. |
| 9635 | // |
| 9636 | // This code must be VERY careful about the locks |
| 9637 | // it acquires. |
| 9638 | // In fact, the current code acquires way too many, |
| 9639 | // and probably has lurking deadlocks. |
| 9640 | |
| 9641 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9642 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9643 | } |
| 9644 | |
| 9645 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9646 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9647 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9648 | } |
| 9649 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9650 | |
| 9651 | @Override |
| 9652 | public boolean canConnectTo5GInDsdsMode() { |
| 9653 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9654 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9655 | |
| 9656 | @Override |
| 9657 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9658 | String callingFeatureId) { |
| 9659 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9660 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9661 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9662 | } |
| 9663 | |
| 9664 | Phone phone = getPhone(subId); |
| 9665 | if (phone == null) { |
| 9666 | throw new RuntimeException("phone is not available"); |
| 9667 | } |
| 9668 | // Now that all security checks passes, perform the operation as ourselves. |
| 9669 | final long identity = Binder.clearCallingIdentity(); |
| 9670 | try { |
| 9671 | return phone.getEquivalentHomePlmns(); |
| 9672 | } finally { |
| 9673 | Binder.restoreCallingIdentity(identity); |
| 9674 | } |
| 9675 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9676 | |
| 9677 | @Override |
| 9678 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9679 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9680 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 9681 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9682 | if (radioInterfaceCapabilities == null) { |
| 9683 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9684 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 9685 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9686 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9687 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9688 | @Override |
| 9689 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9690 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9691 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9692 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9693 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9694 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9695 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9696 | if (DBG) { |
| 9697 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9698 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9699 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9700 | } |
| 9701 | |
| 9702 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9703 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9704 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9705 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9706 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9707 | if (callback != null) { |
| 9708 | try { |
| 9709 | callback.onAuthenticationFailure( |
| 9710 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9711 | } catch (RemoteException exception) { |
| 9712 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9713 | } |
| 9714 | return; |
| 9715 | } |
| 9716 | } |
| 9717 | |
| 9718 | final long token = Binder.clearCallingIdentity(); |
| 9719 | try { |
| 9720 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9721 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9722 | forceBootStrapping, callback)); |
| 9723 | } finally { |
| 9724 | Binder.restoreCallingIdentity(token); |
| 9725 | } |
| 9726 | } |
| 9727 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9728 | /** |
| 9729 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9730 | * requested radio power state will actually be set. See {@link |
| 9731 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9732 | * |
| 9733 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9734 | * @param enable {@code true} if trying to turn radio on. |
| 9735 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9736 | * false}. |
| 9737 | */ |
| 9738 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9739 | Phone phone = getPhone(subId); |
| 9740 | if (phone != null) { |
| 9741 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9742 | return true; |
| 9743 | } |
| 9744 | return false; |
| 9745 | } |
| 9746 | |
| 9747 | private int handleDataThrottlingRequest(int subId, |
| 9748 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9749 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9750 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9751 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9752 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9753 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9754 | } |
| 9755 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9756 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9757 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9758 | if (!setRadioPowerForThermal(subId, true)) { |
| 9759 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9760 | } |
| 9761 | |
| 9762 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9763 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9764 | if (isDataThrottlingSupported) { |
| 9765 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9766 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9767 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9768 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9769 | } else if (thermalMitigationResult |
| 9770 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
| 9771 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9772 | } |
| 9773 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9774 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9775 | |
| 9776 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9777 | } |
| 9778 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9779 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 9780 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 9781 | for (String pckg : context.getResources() |
| 9782 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 9783 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 9784 | } |
| 9785 | } |
| 9786 | |
| 9787 | return sThermalMitigationAllowlistedPackages; |
| 9788 | } |
| 9789 | |
| 9790 | /** |
| 9791 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 9792 | * @param packageName name of package to be allowlisted |
| 9793 | * @param context |
| 9794 | */ |
| 9795 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 9796 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9797 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 9798 | } |
| 9799 | |
| 9800 | /** |
| 9801 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 9802 | * @param packageName name of package to remove from allowlist |
| 9803 | * @param context |
| 9804 | */ |
| 9805 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 9806 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9807 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 9808 | } |
| 9809 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9810 | /** |
| 9811 | * Thermal mitigation request to control functionalities at modem. |
| 9812 | * |
| 9813 | * @param subId the id of the subscription. |
| 9814 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9815 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9816 | * |
| 9817 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9818 | */ |
| 9819 | @Override |
| 9820 | @ThermalMitigationResult |
| 9821 | public int sendThermalMitigationRequest( |
| 9822 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9823 | ThermalMitigationRequest thermalMitigationRequest, |
| 9824 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9825 | enforceModifyPermission(); |
| 9826 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9827 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 9828 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 9829 | .contains(callingPackage)) { |
| 9830 | throw new SecurityException("Calling package must be configured in the device config. " |
| 9831 | + "calling package: " + callingPackage); |
| 9832 | } |
| 9833 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9834 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9835 | final long identity = Binder.clearCallingIdentity(); |
| 9836 | |
| 9837 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9838 | try { |
| 9839 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9840 | switch (thermalMitigationAction) { |
| 9841 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9842 | thermalMitigationResult = |
| 9843 | handleDataThrottlingRequest(subId, |
| 9844 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9845 | break; |
| 9846 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9847 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9848 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9849 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9850 | } |
| 9851 | |
| 9852 | // Ensure that radio is on. If not able to power on due to phone being |
| 9853 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9854 | if (!setRadioPowerForThermal(subId, true)) { |
| 9855 | thermalMitigationResult = |
| 9856 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9857 | break; |
| 9858 | } |
| 9859 | |
| 9860 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9861 | false); |
| 9862 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9863 | break; |
| 9864 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9865 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9866 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9867 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9868 | } |
| 9869 | |
| 9870 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9871 | if (registry != null) { |
| 9872 | TelephonyConnectionService service = |
| 9873 | registry.getTelephonyConnectionService(); |
| 9874 | Phone phone = getPhone(subId); |
| 9875 | if (phone == null) { |
| 9876 | thermalMitigationResult = |
| 9877 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9878 | break; |
| 9879 | } |
| 9880 | |
| 9881 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9882 | != TelephonyManager.CALL_STATE_IDLE |
| 9883 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9884 | || (service != null && service.isEmergencyCallPending())) { |
| 9885 | String errorMessage = "Phone state is not valid. call state = " |
| 9886 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9887 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9888 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9889 | errorMessage += service == null |
| 9890 | ? " TelephonyConnectionService is null" |
| 9891 | : " isEmergencyCallPending = " |
| 9892 | + service.isEmergencyCallPending(); |
| 9893 | Log.e(LOG_TAG, errorMessage); |
| 9894 | thermalMitigationResult = |
| 9895 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9896 | break; |
| 9897 | } |
| 9898 | } else { |
| 9899 | thermalMitigationResult = |
| 9900 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9901 | break; |
| 9902 | } |
| 9903 | |
| 9904 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9905 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9906 | if (!setRadioPowerForThermal(subId, false)) { |
| 9907 | thermalMitigationResult = |
| 9908 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9909 | break; |
| 9910 | } |
| 9911 | thermalMitigationResult = |
| 9912 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9913 | break; |
| 9914 | default: |
| 9915 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9916 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9917 | } |
| 9918 | } catch (IllegalArgumentException e) { |
| 9919 | throw e; |
| 9920 | } catch (Exception e) { |
| 9921 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9922 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9923 | } finally { |
| 9924 | Binder.restoreCallingIdentity(identity); |
| 9925 | } |
| 9926 | |
| 9927 | if (DBG) { |
| 9928 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9929 | + thermalMitigationResult); |
| 9930 | } |
| 9931 | |
| 9932 | return thermalMitigationResult; |
| 9933 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9934 | |
| 9935 | /** |
| 9936 | * Set the GbaService Package Name that Telephony will bind to. |
| 9937 | * |
| 9938 | * @param subId The sim that the GbaService is associated with. |
| 9939 | * @param packageName The name of the package to be replaced with. |
| 9940 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9941 | */ |
| 9942 | @Override |
| 9943 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9944 | enforceModifyPermission(); |
| 9945 | |
| 9946 | final long identity = Binder.clearCallingIdentity(); |
| 9947 | try { |
| 9948 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9949 | } finally { |
| 9950 | Binder.restoreCallingIdentity(identity); |
| 9951 | } |
| 9952 | } |
| 9953 | |
| 9954 | /** |
| 9955 | * Return the package name of the currently bound GbaService. |
| 9956 | * |
| 9957 | * @param subId The sim that the GbaService is associated with. |
| 9958 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9959 | */ |
| 9960 | @Override |
| 9961 | public String getBoundGbaService(int subId) { |
| 9962 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9963 | |
| 9964 | final long identity = Binder.clearCallingIdentity(); |
| 9965 | try { |
| 9966 | return getGbaManager(subId).getServicePackage(); |
| 9967 | } finally { |
| 9968 | Binder.restoreCallingIdentity(identity); |
| 9969 | } |
| 9970 | } |
| 9971 | |
| 9972 | /** |
| 9973 | * Set the release time for telephony to unbind GbaService. |
| 9974 | * |
| 9975 | * @param subId The sim that the GbaService is associated with. |
| 9976 | * @param interval The release time to unbind GbaService by millisecond. |
| 9977 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9978 | */ |
| 9979 | @Override |
| 9980 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9981 | enforceModifyPermission(); |
| 9982 | |
| 9983 | final long identity = Binder.clearCallingIdentity(); |
| 9984 | try { |
| 9985 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9986 | } finally { |
| 9987 | Binder.restoreCallingIdentity(identity); |
| 9988 | } |
| 9989 | } |
| 9990 | |
| 9991 | /** |
| 9992 | * Return the release time for telephony to unbind GbaService. |
| 9993 | * |
| 9994 | * @param subId The sim that the GbaService is associated with. |
| 9995 | * @return The release time to unbind GbaService by millisecond. |
| 9996 | */ |
| 9997 | @Override |
| 9998 | public int getGbaReleaseTime(int subId) { |
| 9999 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10000 | |
| 10001 | final long identity = Binder.clearCallingIdentity(); |
| 10002 | try { |
| 10003 | return getGbaManager(subId).getReleaseTime(); |
| 10004 | } finally { |
| 10005 | Binder.restoreCallingIdentity(identity); |
| 10006 | } |
| 10007 | } |
| 10008 | |
| 10009 | private GbaManager getGbaManager(int subId) { |
| 10010 | GbaManager instance = GbaManager.getInstance(subId); |
| 10011 | if (instance == null) { |
| 10012 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10013 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10014 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10015 | } |
| 10016 | return instance; |
| 10017 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10018 | |
| 10019 | /** |
| 10020 | * indicate whether the device and the carrier can support |
| 10021 | * RCS VoLTE single registration. |
| 10022 | */ |
| 10023 | @Override |
| 10024 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10025 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10026 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10027 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10028 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10029 | |
| 10030 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10031 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10032 | } |
| 10033 | |
| 10034 | final long identity = Binder.clearCallingIdentity(); |
| 10035 | try { |
| 10036 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10037 | if (rpm != null) { |
| 10038 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10039 | } |
| 10040 | return false; |
| 10041 | } finally { |
| 10042 | Binder.restoreCallingIdentity(identity); |
| 10043 | } |
| 10044 | } |
| 10045 | |
| 10046 | /** |
| 10047 | * Register RCS provisioning callback. |
| 10048 | */ |
| 10049 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10050 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10051 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10052 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10053 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10054 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10055 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10056 | |
| 10057 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10058 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10059 | } |
| 10060 | if (!isImsAvailableOnDevice()) { |
| 10061 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10062 | "IMS not available on device."); |
| 10063 | } |
| 10064 | |
| 10065 | final long identity = Binder.clearCallingIdentity(); |
| 10066 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10067 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10068 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10069 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10070 | "Service not available for the subscription."); |
| 10071 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10072 | } finally { |
| 10073 | Binder.restoreCallingIdentity(identity); |
| 10074 | } |
| 10075 | } |
| 10076 | |
| 10077 | /** |
| 10078 | * Unregister RCS provisioning callback. |
| 10079 | */ |
| 10080 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10081 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10082 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10083 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10084 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10085 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10086 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10087 | |
| 10088 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10089 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10090 | } |
| 10091 | if (!isImsAvailableOnDevice()) { |
| 10092 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10093 | "IMS not available on device."); |
| 10094 | } |
| 10095 | |
| 10096 | final long identity = Binder.clearCallingIdentity(); |
| 10097 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10098 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10099 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10100 | } finally { |
| 10101 | Binder.restoreCallingIdentity(identity); |
| 10102 | } |
| 10103 | } |
| 10104 | |
| 10105 | /** |
| 10106 | * trigger RCS reconfiguration. |
| 10107 | */ |
| 10108 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10109 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10110 | "triggerRcsReconfiguration", |
| 10111 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10112 | |
| 10113 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10114 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10115 | } |
| 10116 | if (!isImsAvailableOnDevice()) { |
| 10117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10118 | "IMS not available on device."); |
| 10119 | } |
| 10120 | |
| 10121 | final long identity = Binder.clearCallingIdentity(); |
| 10122 | try { |
| 10123 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10124 | } finally { |
| 10125 | Binder.restoreCallingIdentity(identity); |
| 10126 | } |
| 10127 | } |
| 10128 | |
| 10129 | /** |
| 10130 | * Provide the client configuration parameters of the RCS application. |
| 10131 | */ |
| 10132 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10133 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10134 | "setRcsClientConfiguration", |
| 10135 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10136 | |
| 10137 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10138 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10139 | } |
| 10140 | if (!isImsAvailableOnDevice()) { |
| 10141 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10142 | "IMS not available on device."); |
| 10143 | } |
| 10144 | |
| 10145 | final long identity = Binder.clearCallingIdentity(); |
| 10146 | |
| 10147 | try { |
| 10148 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10149 | if (configBinder == null) { |
| 10150 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 10151 | } else { |
| 10152 | configBinder.setRcsClientConfiguration(rcc); |
| 10153 | } |
| 10154 | } catch (RemoteException e) { |
| 10155 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 10156 | } finally { |
| 10157 | Binder.restoreCallingIdentity(identity); |
| 10158 | } |
| 10159 | } |
| 10160 | |
| 10161 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10162 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10163 | */ |
| 10164 | @Override |
| 10165 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10166 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10167 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10168 | |
| 10169 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10170 | } |
| 10171 | |
| 10172 | /** |
| 10173 | * Gets the test mode for RCS VoLTE single registration. |
| 10174 | */ |
| 10175 | @Override |
| 10176 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10177 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10178 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10179 | |
| 10180 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10181 | } |
| 10182 | |
| 10183 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10184 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10185 | */ |
| 10186 | @Override |
| 10187 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10188 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10189 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10190 | enforceModifyPermission(); |
| 10191 | |
| 10192 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10193 | : Boolean.parseBoolean(enabledStr); |
| 10194 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10195 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10196 | } |
| 10197 | |
| 10198 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10199 | * Sends a device to device communication message. Only usable via shell. |
| 10200 | * @param message message to send. |
| 10201 | * @param value message value. |
| 10202 | */ |
| 10203 | @Override |
| 10204 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10205 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10206 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10207 | enforceModifyPermission(); |
| 10208 | |
| 10209 | final long identity = Binder.clearCallingIdentity(); |
| 10210 | try { |
| 10211 | TelephonyConnectionService service = |
| 10212 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10213 | if (service == null) { |
| 10214 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10215 | return; |
| 10216 | } |
| 10217 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10218 | } finally { |
| 10219 | Binder.restoreCallingIdentity(identity); |
| 10220 | } |
| 10221 | } |
| 10222 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10223 | /** |
| 10224 | * Sets the specified device to device transport active. |
| 10225 | * @param transport The transport to set active. |
| 10226 | */ |
| 10227 | @Override |
| 10228 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10229 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10230 | "setActiveDeviceToDeviceTransport"); |
| 10231 | enforceModifyPermission(); |
| 10232 | |
| 10233 | final long identity = Binder.clearCallingIdentity(); |
| 10234 | try { |
| 10235 | TelephonyConnectionService service = |
| 10236 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10237 | if (service == null) { |
| 10238 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10239 | return; |
| 10240 | } |
| 10241 | service.setActiveDeviceToDeviceTransport(transport); |
| 10242 | } finally { |
| 10243 | Binder.restoreCallingIdentity(identity); |
| 10244 | } |
| 10245 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10246 | |
| 10247 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10248 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10249 | */ |
| 10250 | @Override |
| 10251 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10252 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10253 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10254 | } |
| 10255 | |
| 10256 | /** |
| 10257 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10258 | */ |
| 10259 | @Override |
| 10260 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10261 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10262 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10263 | enforceModifyPermission(); |
| 10264 | |
| 10265 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10266 | : Boolean.parseBoolean(enabledStr); |
| 10267 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10268 | subId, enabled); |
| 10269 | } |
| 10270 | |
| 10271 | /** |
| 10272 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10273 | */ |
| 10274 | @Override |
| 10275 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10276 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10277 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10278 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10279 | |
| 10280 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10281 | * Overrides the ims feature validation result |
| 10282 | */ |
| 10283 | @Override |
| 10284 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10285 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10286 | "setImsFeatureValidationOverride"); |
| 10287 | |
| 10288 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10289 | : Boolean.parseBoolean(enabledStr); |
| 10290 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10291 | subId, enabled); |
| 10292 | } |
| 10293 | |
| 10294 | /** |
| 10295 | * Gets the ims feature validation override value |
| 10296 | */ |
| 10297 | @Override |
| 10298 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10299 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10300 | "getImsFeatureValidationOverride"); |
| 10301 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10302 | } |
| 10303 | |
| 10304 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10305 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10306 | * their mobile plan. |
| 10307 | */ |
| 10308 | @Override |
| 10309 | public String getMobileProvisioningUrl() { |
| 10310 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10311 | final long identity = Binder.clearCallingIdentity(); |
| 10312 | try { |
| 10313 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10314 | } finally { |
| 10315 | Binder.restoreCallingIdentity(identity); |
| 10316 | } |
| 10317 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10318 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10319 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10320 | * Get the EAB contact from the EAB database. |
| 10321 | */ |
| 10322 | @Override |
| 10323 | public String getContactFromEab(String contact) { |
| 10324 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10325 | enforceModifyPermission(); |
| 10326 | final long identity = Binder.clearCallingIdentity(); |
| 10327 | try { |
| 10328 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10329 | } finally { |
| 10330 | Binder.restoreCallingIdentity(identity); |
| 10331 | } |
| 10332 | } |
| 10333 | |
| 10334 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10335 | * Remove the EAB contacts from the EAB database. |
| 10336 | */ |
| 10337 | @Override |
| 10338 | public int removeContactFromEab(int subId, String contacts) { |
| 10339 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10340 | enforceModifyPermission(); |
| 10341 | final long identity = Binder.clearCallingIdentity(); |
| 10342 | try { |
| 10343 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10344 | } finally { |
| 10345 | Binder.restoreCallingIdentity(identity); |
| 10346 | } |
| 10347 | } |
| 10348 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10349 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10350 | public boolean getDeviceUceEnabled() { |
| 10351 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10352 | final long identity = Binder.clearCallingIdentity(); |
| 10353 | try { |
| 10354 | return mApp.getDeviceUceEnabled(); |
| 10355 | } finally { |
| 10356 | Binder.restoreCallingIdentity(identity); |
| 10357 | } |
| 10358 | } |
| 10359 | |
| 10360 | @Override |
| 10361 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10362 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10363 | final long identity = Binder.clearCallingIdentity(); |
| 10364 | try { |
| 10365 | mApp.setDeviceUceEnabled(isEnabled); |
| 10366 | } finally { |
| 10367 | Binder.restoreCallingIdentity(identity); |
| 10368 | } |
| 10369 | } |
| 10370 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10371 | /** |
| 10372 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10373 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10374 | */ |
| 10375 | // Used for SHELL command only right now. |
| 10376 | @Override |
| 10377 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10378 | List<String> featureTags) { |
| 10379 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10380 | "addUceRegistrationOverrideShell"); |
| 10381 | final long identity = Binder.clearCallingIdentity(); |
| 10382 | try { |
| 10383 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10384 | new ArraySet<>(featureTags)); |
| 10385 | } catch (ImsException e) { |
| 10386 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10387 | } finally { |
| 10388 | Binder.restoreCallingIdentity(identity); |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | /** |
| 10393 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10394 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10395 | */ |
| 10396 | // Used for SHELL command only right now. |
| 10397 | @Override |
| 10398 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10399 | List<String> featureTags) { |
| 10400 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10401 | "removeUceRegistrationOverrideShell"); |
| 10402 | final long identity = Binder.clearCallingIdentity(); |
| 10403 | try { |
| 10404 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10405 | new ArraySet<>(featureTags)); |
| 10406 | } catch (ImsException e) { |
| 10407 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10408 | } finally { |
| 10409 | Binder.restoreCallingIdentity(identity); |
| 10410 | } |
| 10411 | } |
| 10412 | |
| 10413 | /** |
| 10414 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10415 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10416 | */ |
| 10417 | // Used for SHELL command only right now. |
| 10418 | @Override |
| 10419 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10420 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10421 | "clearUceRegistrationOverrideShell"); |
| 10422 | final long identity = Binder.clearCallingIdentity(); |
| 10423 | try { |
| 10424 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10425 | } catch (ImsException e) { |
| 10426 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10427 | } finally { |
| 10428 | Binder.restoreCallingIdentity(identity); |
| 10429 | } |
| 10430 | } |
| 10431 | |
| 10432 | /** |
| 10433 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10434 | */ |
| 10435 | // Used for SHELL command only right now. |
| 10436 | @Override |
| 10437 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10438 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10439 | "getLatestRcsContactUceCapabilityShell"); |
| 10440 | final long identity = Binder.clearCallingIdentity(); |
| 10441 | try { |
| 10442 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10443 | } catch (ImsException e) { |
| 10444 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10445 | } finally { |
| 10446 | Binder.restoreCallingIdentity(identity); |
| 10447 | } |
| 10448 | } |
| 10449 | |
| 10450 | /** |
| 10451 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10452 | * device does not have an active PUBLISH. |
| 10453 | */ |
| 10454 | // Used for SHELL command only right now. |
| 10455 | @Override |
| 10456 | public String getLastUcePidfXmlShell(int subId) { |
| 10457 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10458 | final long identity = Binder.clearCallingIdentity(); |
| 10459 | try { |
| 10460 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10461 | } catch (ImsException e) { |
| 10462 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10463 | } finally { |
| 10464 | Binder.restoreCallingIdentity(identity); |
| 10465 | } |
| 10466 | } |
| 10467 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10468 | /** |
| 10469 | * Remove UCE requests cannot be sent to the network status. |
| 10470 | */ |
| 10471 | // Used for SHELL command only right now. |
| 10472 | @Override |
| 10473 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10474 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10475 | final long identity = Binder.clearCallingIdentity(); |
| 10476 | try { |
| 10477 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10478 | } catch (ImsException e) { |
| 10479 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10480 | } finally { |
| 10481 | Binder.restoreCallingIdentity(identity); |
| 10482 | } |
| 10483 | } |
| 10484 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10485 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10486 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10487 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10488 | String callingPackage) { |
| 10489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10490 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10491 | |
| 10492 | final int callingUid = Binder.getCallingUid(); |
| 10493 | // Verify that tha callingPackage belongs to the calling UID |
| 10494 | mApp.getSystemService(AppOpsManager.class) |
| 10495 | .checkPackage(callingUid, callingPackage); |
| 10496 | |
| 10497 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10498 | |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10502 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10503 | |
| 10504 | if (result instanceof IllegalStateException) { |
| 10505 | throw (IllegalStateException) result; |
| 10506 | } |
| 10507 | } finally { |
| 10508 | Binder.restoreCallingIdentity(identity); |
| 10509 | } |
| 10510 | } |
| 10511 | |
| 10512 | @Override |
| 10513 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10514 | String callingPackage) { |
| 10515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10516 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10517 | |
| 10518 | final int callingUid = Binder.getCallingUid(); |
| 10519 | // Verify that tha callingPackage belongs to the calling UID |
| 10520 | mApp.getSystemService(AppOpsManager.class) |
| 10521 | .checkPackage(callingUid, callingPackage); |
| 10522 | |
| 10523 | final long identity = Binder.clearCallingIdentity(); |
| 10524 | try { |
| 10525 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10526 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10527 | |
| 10528 | if (result instanceof IllegalStateException) { |
| 10529 | throw (IllegalStateException) result; |
| 10530 | } |
| 10531 | } finally { |
| 10532 | Binder.restoreCallingIdentity(identity); |
| 10533 | } |
| 10534 | } |
| 10535 | |
| 10536 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10537 | int callingUid) { |
| 10538 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10539 | // phone/system process do not have further restriction on request |
| 10540 | return; |
| 10541 | } |
| 10542 | |
| 10543 | // Applications has restrictions on how to use the request: |
| 10544 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10545 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10546 | // This is not system caller which has been checked above |
| 10547 | throw new IllegalArgumentException( |
| 10548 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10549 | } |
| 10550 | |
| 10551 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10552 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10553 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10554 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10555 | || info.isEnabled()) { |
| 10556 | throw new IllegalArgumentException( |
| 10557 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10558 | } |
| 10559 | |
| 10560 | // Thresholds length for each RAN need in range. This has been validated in |
| 10561 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10562 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10563 | final int[] thresholds = info.getThresholds(); |
| 10564 | Objects.requireNonNull(thresholds); |
| 10565 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10566 | || thresholds.length |
| 10567 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10568 | throw new IllegalArgumentException( |
| 10569 | "thresholds length is out of range: " + thresholds.length); |
| 10570 | } |
| 10571 | } |
| 10572 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10573 | |
| 10574 | /** |
| 10575 | * Gets the current phone capability. |
| 10576 | * |
| 10577 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10578 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10579 | * It's used to evaluate possible phone config change, for example from single |
| 10580 | * SIM device to multi-SIM device. |
| 10581 | */ |
| 10582 | @Override |
| 10583 | public PhoneCapability getPhoneCapability() { |
| 10584 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10585 | final long identity = Binder.clearCallingIdentity(); |
| 10586 | try { |
| 10587 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10588 | } finally { |
| 10589 | Binder.restoreCallingIdentity(identity); |
| 10590 | } |
| 10591 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10592 | |
| 10593 | /** |
| 10594 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10595 | * required to be done shortly after the API is invoked. |
| 10596 | */ |
| 10597 | @Override |
| 10598 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10599 | public int prepareForUnattendedReboot() { |
| 10600 | enforceRebootPermission(); |
| 10601 | |
| 10602 | final long identity = Binder.clearCallingIdentity(); |
| 10603 | try { |
| 10604 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10605 | } finally { |
| 10606 | Binder.restoreCallingIdentity(identity); |
| 10607 | } |
| 10608 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 10609 | |
| 10610 | /** |
| 10611 | * Request to get the current slicing configuration including URSP rules and |
| 10612 | * NSSAIs (configured, allowed and rejected). |
| 10613 | * |
| 10614 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 10615 | */ |
| 10616 | @Override |
| 10617 | public void getSlicingConfig(ResultReceiver callback) { |
| 10618 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 10619 | |
| 10620 | final long identity = Binder.clearCallingIdentity(); |
| 10621 | try { |
| 10622 | Phone phone = getDefaultPhone(); |
| 10623 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 10624 | } finally { |
| 10625 | Binder.restoreCallingIdentity(identity); |
| 10626 | } |
| 10627 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10628 | } |