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 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 58 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 61 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 66 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 78 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 79 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 80 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 81 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 82 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 83 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 85 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 88 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 90 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrengthUpdateRequest; |
| 94 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 101 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 102 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 103 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 104 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 105 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 106 | import android.telephony.data.ApnSetting; |
| 107 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 108 | import android.telephony.gba.GbaAuthRequest; |
| 109 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 110 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 112 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 113 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 120 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 126 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 127 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 130 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 131 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 132 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 172 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 188 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 189 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 190 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 193 | import com.android.services.telephony.TelecomAccountRegistry; |
| 194 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 195 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 196 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 197 | import java.io.FileDescriptor; |
| 198 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 199 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 200 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 201 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 202 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 203 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 204 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 205 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 206 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 207 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 208 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 209 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 210 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * Implementation of the ITelephony interface. |
| 214 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 215 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 217 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 218 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 219 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 220 | |
| 221 | // Message codes used with mMainThreadHandler |
| 222 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 223 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 224 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 225 | private static final int CMD_OPEN_CHANNEL = 9; |
| 226 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 227 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 228 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 229 | private static final int CMD_NV_READ_ITEM = 13; |
| 230 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 231 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 232 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 233 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 234 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 235 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 236 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 237 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 238 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 239 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 240 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 241 | private static final int CMD_SEND_ENVELOPE = 25; |
| 242 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 243 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 244 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 245 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 246 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 247 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 248 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 249 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 250 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 251 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 252 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 254 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 255 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 256 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 257 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 258 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 259 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 260 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 261 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 262 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 263 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 264 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 265 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 266 | private static final int CMD_SWITCH_SLOTS = 50; |
| 267 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 268 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 269 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 270 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 271 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 272 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 273 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 274 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 275 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 276 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 277 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 278 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 279 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 280 | private static final int CMD_MODEM_REBOOT = 64; |
| 281 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 282 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 283 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 284 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 285 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 286 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 287 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 288 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 289 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 290 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 291 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 292 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 293 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 294 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 295 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 296 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 297 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 298 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 299 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 300 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 301 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 302 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 303 | private static final int CMD_GET_CALL_WAITING = 87; |
| 304 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 305 | private static final int CMD_SET_CALL_WAITING = 89; |
| 306 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 307 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 308 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 309 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 310 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 311 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 312 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 313 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 314 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 315 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 316 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 317 | private static final int CMD_SET_SIM_POWER = 101; |
| 318 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 319 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 320 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 321 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 322 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 323 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 324 | // Parameters of select command. |
| 325 | private static final int SELECT_COMMAND = 0xA4; |
| 326 | private static final int SELECT_P1 = 0x04; |
| 327 | private static final int SELECT_P2 = 0; |
| 328 | private static final int SELECT_P3 = 0x10; |
| 329 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | /** The singleton instance. */ |
| 331 | private static PhoneInterfaceManager sInstance; |
| 332 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 333 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 334 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 335 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 336 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 337 | private AppOpsManager mAppOps; |
| 338 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 339 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 340 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 341 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 343 | /** User Activity */ |
| 344 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 345 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 346 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 347 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 348 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 349 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 350 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 351 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 352 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 353 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 354 | // String to store multi SIM allowed |
| 355 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 356 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 357 | // The AID of ISD-R. |
| 358 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 359 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 360 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 361 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 362 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 363 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 364 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 365 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 366 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 367 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 368 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 369 | */ |
| 370 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 371 | "reset_network_erase_modem_config_enabled"; |
| 372 | |
| 373 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 374 | * A request object to use for transmitting data to an ICC. |
| 375 | */ |
| 376 | private static final class IccAPDUArgument { |
| 377 | public int channel, cla, command, p1, p2, p3; |
| 378 | public String data; |
| 379 | |
| 380 | public IccAPDUArgument(int channel, int cla, int command, |
| 381 | int p1, int p2, int p3, String data) { |
| 382 | this.channel = channel; |
| 383 | this.cla = cla; |
| 384 | this.command = command; |
| 385 | this.p1 = p1; |
| 386 | this.p2 = p2; |
| 387 | this.p3 = p3; |
| 388 | this.data = data; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 393 | * A request object to use for transmitting data to an ICC. |
| 394 | */ |
| 395 | private static final class ManualNetworkSelectionArgument { |
| 396 | public OperatorInfo operatorInfo; |
| 397 | public boolean persistSelection; |
| 398 | |
| 399 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 400 | this.operatorInfo = operatorInfo; |
| 401 | this.persistSelection = persistSelection; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 406 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 407 | * request after sending. The main thread will notify the request when it is complete. |
| 408 | */ |
| 409 | private static final class MainThreadRequest { |
| 410 | /** The argument to use for the request */ |
| 411 | public Object argument; |
| 412 | /** The result of the request that is run on the main thread */ |
| 413 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 414 | // The subscriber id that this request applies to. Defaults to |
| 415 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 416 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 418 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 419 | public Phone phone; |
| 420 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 421 | public WorkSource workSource; |
| 422 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | public MainThreadRequest(Object argument) { |
| 424 | this.argument = argument; |
| 425 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 426 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 427 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 428 | this.argument = argument; |
| 429 | if (phone != null) { |
| 430 | this.phone = phone; |
| 431 | } |
| 432 | this.workSource = workSource; |
| 433 | } |
| 434 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 435 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 436 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 437 | if (subId != null) { |
| 438 | this.subId = subId; |
| 439 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 440 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 441 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 444 | private static final class IncomingThirdPartyCallArgs { |
| 445 | public final ComponentName component; |
| 446 | public final String callId; |
| 447 | public final String callerDisplayName; |
| 448 | |
| 449 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 450 | String callerDisplayName) { |
| 451 | this.component = component; |
| 452 | this.callId = callId; |
| 453 | this.callerDisplayName = callerDisplayName; |
| 454 | } |
| 455 | } |
| 456 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | /** |
| 458 | * A handler that processes messages on the main thread in the phone process. Since many |
| 459 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 460 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 461 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 462 | * on, which will be notified when the operation completes and will contain the result of the |
| 463 | * request. |
| 464 | * |
| 465 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 466 | * note that request.result must be set to something non-null for the calling thread to |
| 467 | * unblock. |
| 468 | */ |
| 469 | private final class MainThreadHandler extends Handler { |
| 470 | @Override |
| 471 | public void handleMessage(Message msg) { |
| 472 | MainThreadRequest request; |
| 473 | Message onCompleted; |
| 474 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 475 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 477 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | |
| 479 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | case CMD_HANDLE_USSD_REQUEST: { |
| 481 | request = (MainThreadRequest) msg.obj; |
| 482 | final Phone phone = getPhoneFromRequest(request); |
| 483 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 484 | String ussdRequest = ussdObject.first; |
| 485 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 486 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | if (!isUssdApiAllowed(request.subId)) { |
| 488 | // Carrier does not support use of this API, return failure. |
| 489 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 490 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 491 | Bundle returnData = new Bundle(); |
| 492 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 493 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 494 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | request.result = true; |
| 496 | notifyRequester(request); |
| 497 | return; |
| 498 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 499 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 500 | try { |
| 501 | request.result = phone != null |
| 502 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 503 | } catch (CallStateException cse) { |
| 504 | request.result = false; |
| 505 | } |
| 506 | // Wake up the requesting thread |
| 507 | notifyRequester(request); |
| 508 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 511 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 513 | final Phone phone = getPhoneFromRequest(request); |
| 514 | request.result = phone != null ? |
| 515 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 516 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 517 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 518 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 523 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 525 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 526 | if (uiccCard == null) { |
| 527 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 528 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 532 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 533 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 535 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 536 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 538 | break; |
| 539 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | ar = (AsyncResult) msg.obj; |
| 542 | request = (MainThreadRequest) ar.userObj; |
| 543 | if (ar.exception == null && ar.result != null) { |
| 544 | request.result = ar.result; |
| 545 | } else { |
| 546 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 547 | if (ar.result == null) { |
| 548 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 549 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 551 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 552 | } else { |
| 553 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 554 | } |
| 555 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | break; |
| 558 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 560 | request = (MainThreadRequest) msg.obj; |
| 561 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 562 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | if (uiccCard == null) { |
| 564 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | } else { |
| 568 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 569 | request); |
| 570 | uiccCard.iccTransmitApduBasicChannel( |
| 571 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 572 | iccArgument.p3, iccArgument.data, onCompleted); |
| 573 | } |
| 574 | break; |
| 575 | |
| 576 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 577 | ar = (AsyncResult) msg.obj; |
| 578 | request = (MainThreadRequest) ar.userObj; |
| 579 | if (ar.exception == null && ar.result != null) { |
| 580 | request.result = ar.result; |
| 581 | } else { |
| 582 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 583 | if (ar.result == null) { |
| 584 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 585 | } else if (ar.exception instanceof CommandException) { |
| 586 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 587 | ar.exception); |
| 588 | } else { |
| 589 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 590 | } |
| 591 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | case CMD_EXCHANGE_SIM_IO: |
| 596 | request = (MainThreadRequest) msg.obj; |
| 597 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 598 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | if (uiccCard == null) { |
| 600 | loge("iccExchangeSimIO: No UICC"); |
| 601 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | } else { |
| 604 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 605 | request); |
| 606 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 607 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 608 | iccArgument.data, onCompleted); |
| 609 | } |
| 610 | break; |
| 611 | |
| 612 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 613 | ar = (AsyncResult) msg.obj; |
| 614 | request = (MainThreadRequest) ar.userObj; |
| 615 | if (ar.exception == null && ar.result != null) { |
| 616 | request.result = ar.result; |
| 617 | } else { |
| 618 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 619 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 623 | case CMD_SEND_ENVELOPE: |
| 624 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 625 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("sendEnvelopeWithStatus: No UICC"); |
| 628 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 632 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 633 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case EVENT_SEND_ENVELOPE_DONE: |
| 637 | ar = (AsyncResult) msg.obj; |
| 638 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 639 | if (ar.exception == null && ar.result != null) { |
| 640 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 641 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 642 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 643 | if (ar.result == null) { |
| 644 | loge("sendEnvelopeWithStatus: Empty response"); |
| 645 | } else if (ar.exception instanceof CommandException) { |
| 646 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 647 | ar.exception); |
| 648 | } else { |
| 649 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 650 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 651 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 652 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 653 | break; |
| 654 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | case CMD_OPEN_CHANNEL: |
| 656 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 657 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 658 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | if (uiccCard == null) { |
| 660 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 661 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 662 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 664 | } else { |
| 665 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 666 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 667 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case EVENT_OPEN_CHANNEL_DONE: |
| 672 | ar = (AsyncResult) msg.obj; |
| 673 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | int[] result = (int[]) ar.result; |
| 677 | int channelId = result[0]; |
| 678 | byte[] selectResponse = null; |
| 679 | if (result.length > 1) { |
| 680 | selectResponse = new byte[result.length - 1]; |
| 681 | for (int i = 1; i < result.length; ++i) { |
| 682 | selectResponse[i - 1] = (byte) result[i]; |
| 683 | } |
| 684 | } |
| 685 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 686 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | if (ar.result == null) { |
| 689 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | if (ar.exception != null) { |
| 692 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 693 | } |
| 694 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 695 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 696 | if (ar.exception instanceof CommandException) { |
| 697 | CommandException.Error error = |
| 698 | ((CommandException) (ar.exception)).getCommandError(); |
| 699 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 700 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 701 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 702 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 706 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 708 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 709 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case CMD_CLOSE_CHANNEL: |
| 713 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 714 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | if (uiccCard == null) { |
| 716 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 717 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | } else { |
| 720 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 721 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 722 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 727 | break; |
| 728 | |
| 729 | case CMD_NV_READ_ITEM: |
| 730 | request = (MainThreadRequest) msg.obj; |
| 731 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 732 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 733 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 739 | if (ar.exception == null && ar.result != null) { |
| 740 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | request.result = ""; |
| 743 | if (ar.result == null) { |
| 744 | loge("nvReadItem: Empty response"); |
| 745 | } else if (ar.exception instanceof CommandException) { |
| 746 | loge("nvReadItem: CommandException: " + |
| 747 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 748 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 750 | } |
| 751 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | break; |
| 754 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 755 | case CMD_NV_WRITE_ITEM: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 758 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 759 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 760 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case EVENT_NV_WRITE_ITEM_DONE: |
| 764 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 765 | break; |
| 766 | |
| 767 | case CMD_NV_WRITE_CDMA_PRL: |
| 768 | request = (MainThreadRequest) msg.obj; |
| 769 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 770 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 774 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 775 | break; |
| 776 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 777 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 778 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 779 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 780 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 783 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 784 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 787 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 788 | request = (MainThreadRequest) msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 790 | request); |
| 791 | Phone phone = getPhoneFromRequest(request); |
| 792 | if (phone != null) { |
| 793 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 794 | } else { |
| 795 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 796 | request.result = false; |
| 797 | notifyRequester(request); |
| 798 | } |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | if (ar.exception == null && ar.result != null) { |
| 806 | request.result = ar.result; |
| 807 | } else { |
| 808 | // request.result must be set to something non-null |
| 809 | // for the calling thread to unblock |
| 810 | if (request.result != null) { |
| 811 | request.result = ar.result; |
| 812 | } else { |
| 813 | request.result = false; |
| 814 | } |
| 815 | if (ar.result == null) { |
| 816 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 817 | } else if (ar.exception instanceof CommandException) { |
| 818 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 819 | + ar.exception); |
| 820 | } else { |
| 821 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 822 | } |
| 823 | } |
| 824 | notifyRequester(request); |
| 825 | break; |
| 826 | |
| 827 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 828 | request = (MainThreadRequest) msg.obj; |
| 829 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 830 | Phone phone = getPhoneFromRequest(request); |
| 831 | if (phone != null) { |
| 832 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 833 | request.workSource); |
| 834 | } else { |
| 835 | loge("enableNrDualConnectivity: No phone object"); |
| 836 | request.result = |
| 837 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 838 | notifyRequester(request); |
| 839 | } |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 844 | ar = (AsyncResult) msg.obj; |
| 845 | request = (MainThreadRequest) ar.userObj; |
| 846 | if (ar.exception == null) { |
| 847 | request.result = |
| 848 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 849 | } else { |
| 850 | request.result = |
| 851 | TelephonyManager |
| 852 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 853 | if (ar.exception instanceof CommandException) { |
| 854 | CommandException.Error error = |
| 855 | ((CommandException) (ar.exception)).getCommandError(); |
| 856 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 857 | request.result = |
| 858 | TelephonyManager |
| 859 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 860 | } |
| 861 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 862 | + ar.exception); |
| 863 | } else { |
| 864 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 865 | } |
| 866 | } |
| 867 | notifyRequester(request); |
| 868 | break; |
| 869 | } |
| 870 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 871 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 872 | request = (MainThreadRequest) msg.obj; |
| 873 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 874 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
| 880 | if (ar.exception == null && ar.result != null) { |
| 881 | request.result = ar.result; // Integer |
| 882 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 883 | // request.result must be set to something non-null |
| 884 | // for the calling thread to unblock |
| 885 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 886 | if (ar.result == null) { |
| 887 | loge("getPreferredNetworkType: Empty response"); |
| 888 | } else if (ar.exception instanceof CommandException) { |
| 889 | loge("getPreferredNetworkType: CommandException: " + |
| 890 | ar.exception); |
| 891 | } else { |
| 892 | loge("getPreferredNetworkType: Unknown exception"); |
| 893 | } |
| 894 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 895 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 901 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 902 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 906 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 907 | break; |
| 908 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 909 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 910 | request = (MainThreadRequest)msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 912 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 916 | ar = (AsyncResult)msg.obj; |
| 917 | request = (MainThreadRequest)ar.userObj; |
| 918 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 919 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 920 | break; |
| 921 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 922 | case CMD_SET_VOICEMAIL_NUMBER: |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 925 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 926 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 927 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 931 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 932 | break; |
| 933 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 934 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 937 | request); |
| 938 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 939 | break; |
| 940 | |
| 941 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 942 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 943 | break; |
| 944 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 945 | case CMD_PERFORM_NETWORK_SCAN: |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 948 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 949 | break; |
| 950 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 951 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 952 | request = (MainThreadRequest) msg.obj; |
| 953 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 954 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 955 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 956 | request.argument; |
| 957 | int callForwardingReason = args.first; |
| 958 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 959 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | } |
| 961 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 962 | ar = (AsyncResult) msg.obj; |
| 963 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | TelephonyManager.CallForwardingInfoCallback callback = |
| 965 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 966 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 967 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 969 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 970 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 971 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 972 | // any service for voice call. |
| 973 | if ((callForwardInfo.serviceClass |
| 974 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | callForwardingInfo = new CallForwardingInfo(true, |
| 976 | callForwardInfo.reason, |
| 977 | callForwardInfo.number, |
| 978 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 979 | break; |
| 980 | } |
| 981 | } |
| 982 | // Didn't find a call forward info for voice call. |
| 983 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 985 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 986 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 988 | } else { |
| 989 | if (ar.result == null) { |
| 990 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 991 | } |
| 992 | if (ar.exception != null) { |
| 993 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 994 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 995 | int errorCode = TelephonyManager |
| 996 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 997 | if (ar.exception instanceof CommandException) { |
| 998 | CommandException.Error error = |
| 999 | ((CommandException) (ar.exception)).getCommandError(); |
| 1000 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1001 | errorCode = TelephonyManager |
| 1002 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1003 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1004 | errorCode = TelephonyManager |
| 1005 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1006 | } |
| 1007 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1009 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1010 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1011 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1012 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1013 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1014 | request = (MainThreadRequest) msg.obj; |
| 1015 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1017 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1019 | request.argument).first; |
| 1020 | request.phone.setCallForwardingOption( |
| 1021 | callForwardingInfoToSet.isEnabled() |
| 1022 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1023 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1024 | callForwardingInfoToSet.getReason(), |
| 1025 | callForwardingInfoToSet.getNumber(), |
| 1026 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1027 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1029 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1031 | ar = (AsyncResult) msg.obj; |
| 1032 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | Consumer<Integer> callback = |
| 1034 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1035 | request.argument).second; |
| 1036 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1037 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1039 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | if (ar.exception instanceof CommandException) { |
| 1041 | CommandException.Error error = |
| 1042 | ((CommandException) (ar.exception)).getCommandError(); |
| 1043 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1044 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1045 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1047 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1048 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | callback.accept(errorCode); |
| 1052 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1053 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1054 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1055 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1057 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1059 | request = (MainThreadRequest) msg.obj; |
| 1060 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1061 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1062 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1065 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1069 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1070 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1071 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1072 | // Service Class is a bit mask per 3gpp 27.007. |
| 1073 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1074 | if (callForwardResults.length > 1 |
| 1075 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1077 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1079 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1080 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } else { |
| 1084 | if (ar.result == null) { |
| 1085 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1086 | } |
| 1087 | if (ar.exception != null) { |
| 1088 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1089 | } |
| 1090 | if (ar.exception instanceof CommandException) { |
| 1091 | CommandException.Error error = |
| 1092 | ((CommandException) (ar.exception)).getCommandError(); |
| 1093 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1094 | callForwardingStatus = |
| 1095 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1100 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1102 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1107 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1108 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1110 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1112 | ar = (AsyncResult) msg.obj; |
| 1113 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1115 | Consumer<Integer> callback = |
| 1116 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1117 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1118 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | if (ar.exception instanceof CommandException) { |
| 1120 | CommandException.Error error = |
| 1121 | ((CommandException) (ar.exception)).getCommandError(); |
| 1122 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1123 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1124 | } else { |
| 1125 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1126 | } |
| 1127 | } else { |
| 1128 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1129 | } |
| 1130 | } else { |
| 1131 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1132 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1133 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1134 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1136 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1137 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1138 | ar = (AsyncResult) msg.obj; |
| 1139 | request = (MainThreadRequest) ar.userObj; |
| 1140 | CellNetworkScanResult cellScanResult; |
| 1141 | if (ar.exception == null && ar.result != null) { |
| 1142 | cellScanResult = new CellNetworkScanResult( |
| 1143 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1144 | (List<OperatorInfo>) ar.result); |
| 1145 | } else { |
| 1146 | if (ar.result == null) { |
| 1147 | loge("getCellNetworkScanResults: Empty response"); |
| 1148 | } |
| 1149 | if (ar.exception != null) { |
| 1150 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1151 | } |
| 1152 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1153 | if (ar.exception instanceof CommandException) { |
| 1154 | CommandException.Error error = |
| 1155 | ((CommandException) (ar.exception)).getCommandError(); |
| 1156 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1157 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1158 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1159 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1160 | } |
| 1161 | } |
| 1162 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1163 | } |
| 1164 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1165 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | |
| 1168 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1169 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1170 | ManualNetworkSelectionArgument selArg = |
| 1171 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1172 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1173 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1174 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1175 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | |
| 1178 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1179 | ar = (AsyncResult) msg.obj; |
| 1180 | request = (MainThreadRequest) ar.userObj; |
| 1181 | if (ar.exception == null) { |
| 1182 | request.result = true; |
| 1183 | } else { |
| 1184 | request.result = false; |
| 1185 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1186 | } |
| 1187 | notifyRequester(request); |
| 1188 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1191 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1194 | if (defaultPhone != null) { |
| 1195 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1196 | } else { |
| 1197 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1198 | Bundle bundle = new Bundle(); |
| 1199 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1200 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1201 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1202 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1203 | break; |
| 1204 | |
| 1205 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1206 | ar = (AsyncResult) msg.obj; |
| 1207 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1208 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1209 | |
| 1210 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1211 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1212 | // Update the last modem activity info and the result of the request. |
| 1213 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1214 | if (isModemActivityInfoValid(info)) { |
| 1215 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1216 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1217 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1218 | .getTransmitTimeMillis(); |
| 1219 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1220 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1221 | } |
| 1222 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1223 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1224 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1225 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1226 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1227 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1228 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1229 | info.getReceiveTimeMillis() |
| 1230 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1231 | } |
| 1232 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1233 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1234 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1235 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1236 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1237 | } else { |
| 1238 | if (ar.result == null) { |
| 1239 | loge("queryModemActivityInfo: Empty response"); |
| 1240 | } else if (ar.exception instanceof CommandException) { |
| 1241 | loge("queryModemActivityInfo: CommandException: " + |
| 1242 | ar.exception); |
| 1243 | } else { |
| 1244 | loge("queryModemActivityInfo: Unknown exception"); |
| 1245 | } |
| 1246 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1247 | Bundle bundle = new Bundle(); |
| 1248 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1249 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1250 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1251 | break; |
| 1252 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1253 | case CMD_SET_ALLOWED_CARRIERS: |
| 1254 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1255 | CarrierRestrictionRules argument = |
| 1256 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1257 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1258 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1259 | break; |
| 1260 | |
| 1261 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1262 | ar = (AsyncResult) msg.obj; |
| 1263 | request = (MainThreadRequest) ar.userObj; |
| 1264 | if (ar.exception == null && ar.result != null) { |
| 1265 | request.result = ar.result; |
| 1266 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1267 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1268 | if (ar.exception instanceof CommandException) { |
| 1269 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1270 | CommandException.Error error = |
| 1271 | ((CommandException) (ar.exception)).getCommandError(); |
| 1272 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1273 | request.result = |
| 1274 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1275 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1276 | } else { |
| 1277 | loge("setAllowedCarriers: Unknown exception"); |
| 1278 | } |
| 1279 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1280 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1281 | break; |
| 1282 | |
| 1283 | case CMD_GET_ALLOWED_CARRIERS: |
| 1284 | request = (MainThreadRequest) msg.obj; |
| 1285 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1286 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1287 | break; |
| 1288 | |
| 1289 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1290 | ar = (AsyncResult) msg.obj; |
| 1291 | request = (MainThreadRequest) ar.userObj; |
| 1292 | if (ar.exception == null && ar.result != null) { |
| 1293 | request.result = ar.result; |
| 1294 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1295 | request.result = new IllegalStateException( |
| 1296 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1297 | if (ar.result == null) { |
| 1298 | loge("getAllowedCarriers: Empty response"); |
| 1299 | } else if (ar.exception instanceof CommandException) { |
| 1300 | loge("getAllowedCarriers: CommandException: " + |
| 1301 | ar.exception); |
| 1302 | } else { |
| 1303 | loge("getAllowedCarriers: Unknown exception"); |
| 1304 | } |
| 1305 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1306 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1307 | break; |
| 1308 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1309 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
| 1312 | if (ar.exception == null && ar.result != null) { |
| 1313 | request.result = ar.result; |
| 1314 | } else { |
| 1315 | request.result = new IllegalArgumentException( |
| 1316 | "Failed to retrieve Forbidden Plmns"); |
| 1317 | if (ar.result == null) { |
| 1318 | loge("getForbiddenPlmns: Empty response"); |
| 1319 | } else { |
| 1320 | loge("getForbiddenPlmns: Unknown exception"); |
| 1321 | } |
| 1322 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1323 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1324 | break; |
| 1325 | |
| 1326 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1327 | request = (MainThreadRequest) msg.obj; |
| 1328 | uiccCard = getUiccCardFromRequest(request); |
| 1329 | if (uiccCard == null) { |
| 1330 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1331 | request.result = new IllegalArgumentException( |
| 1332 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1333 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1334 | break; |
| 1335 | } |
| 1336 | Integer appType = (Integer) request.argument; |
| 1337 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1338 | if (uiccApp == null) { |
| 1339 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1340 | + appType); |
| 1341 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1342 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | } else { |
| 1345 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1346 | + " specified type -- " + appType); |
| 1347 | } |
| 1348 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1349 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1350 | onCompleted); |
| 1351 | break; |
| 1352 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1353 | case CMD_SWITCH_SLOTS: |
| 1354 | request = (MainThreadRequest) msg.obj; |
| 1355 | int[] physicalSlots = (int[]) request.argument; |
| 1356 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1357 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1358 | break; |
| 1359 | |
| 1360 | case EVENT_SWITCH_SLOTS_DONE: |
| 1361 | ar = (AsyncResult) msg.obj; |
| 1362 | request = (MainThreadRequest) ar.userObj; |
| 1363 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1364 | notifyRequester(request); |
| 1365 | break; |
| 1366 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1367 | request = (MainThreadRequest) msg.obj; |
| 1368 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1369 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1370 | break; |
| 1371 | |
| 1372 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1373 | ar = (AsyncResult) msg.obj; |
| 1374 | request = (MainThreadRequest) ar.userObj; |
| 1375 | if (ar.exception != null) { |
| 1376 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1377 | } else { |
| 1378 | int mode = ((int[]) ar.result)[0]; |
| 1379 | if (mode == 0) { |
| 1380 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1381 | } else { |
| 1382 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1383 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1384 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1385 | notifyRequester(request); |
| 1386 | break; |
| 1387 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1390 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1391 | break; |
| 1392 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1393 | ar = (AsyncResult) msg.obj; |
| 1394 | request = (MainThreadRequest) ar.userObj; |
| 1395 | if (ar.exception != null) { |
| 1396 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1397 | } else { |
| 1398 | request.result = ((int[]) ar.result)[0]; |
| 1399 | } |
| 1400 | notifyRequester(request); |
| 1401 | break; |
| 1402 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1403 | request = (MainThreadRequest) msg.obj; |
| 1404 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1405 | int mode = (int) request.argument; |
| 1406 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1407 | break; |
| 1408 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1409 | ar = (AsyncResult) msg.obj; |
| 1410 | request = (MainThreadRequest) ar.userObj; |
| 1411 | request.result = ar.exception == null; |
| 1412 | notifyRequester(request); |
| 1413 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1414 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1417 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1418 | break; |
| 1419 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception != null) { |
| 1423 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1424 | } else { |
| 1425 | request.result = ((int[]) ar.result)[0]; |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1429 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1430 | request = (MainThreadRequest) msg.obj; |
| 1431 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1432 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1433 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1434 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1435 | break; |
| 1436 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1437 | ar = (AsyncResult) msg.obj; |
| 1438 | request = (MainThreadRequest) ar.userObj; |
| 1439 | request.result = ar.exception == null; |
| 1440 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1441 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1442 | case CMD_GET_ALL_CELL_INFO: |
| 1443 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1444 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1445 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1446 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1447 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1450 | // If a timeout occurs, the response will be null |
| 1451 | request.result = (ar.exception == null && ar.result != null) |
| 1452 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1453 | synchronized (request) { |
| 1454 | request.notifyAll(); |
| 1455 | } |
| 1456 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1457 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1458 | request = (MainThreadRequest) msg.obj; |
| 1459 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1460 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1461 | break; |
| 1462 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1463 | ar = (AsyncResult) msg.obj; |
| 1464 | request = (MainThreadRequest) ar.userObj; |
| 1465 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1466 | try { |
| 1467 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1468 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1469 | cb.onError( |
| 1470 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1471 | ar.exception.getClass().getName(), |
| 1472 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1473 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1474 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1475 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1476 | } else { |
| 1477 | // use the result as returned |
| 1478 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1479 | } |
| 1480 | } catch (RemoteException re) { |
| 1481 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1482 | } |
| 1483 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1484 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1485 | request = (MainThreadRequest) msg.obj; |
| 1486 | WorkSource ws = (WorkSource) request.argument; |
| 1487 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1488 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1490 | } |
| 1491 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1492 | ar = (AsyncResult) msg.obj; |
| 1493 | request = (MainThreadRequest) ar.userObj; |
| 1494 | if (ar.exception == null) { |
| 1495 | request.result = ar.result; |
| 1496 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1497 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1498 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1499 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | synchronized (request) { |
| 1503 | request.notifyAll(); |
| 1504 | } |
| 1505 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1506 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1507 | case CMD_MODEM_REBOOT: |
| 1508 | request = (MainThreadRequest) msg.obj; |
| 1509 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1510 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1511 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1512 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1513 | handleNullReturnEvent(msg, "rebootModem"); |
| 1514 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1515 | case CMD_REQUEST_ENABLE_MODEM: |
| 1516 | request = (MainThreadRequest) msg.obj; |
| 1517 | boolean enable = (boolean) request.argument; |
| 1518 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1519 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1520 | PhoneConfigurationManager.getInstance() |
| 1521 | .enablePhone(request.phone, enable, onCompleted); |
| 1522 | break; |
| 1523 | case EVENT_ENABLE_MODEM_DONE: |
| 1524 | ar = (AsyncResult) msg.obj; |
| 1525 | request = (MainThreadRequest) ar.userObj; |
| 1526 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1527 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1528 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1529 | if ((boolean) request.result) { |
| 1530 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1531 | updateModemStateMetrics(); |
| 1532 | } else { |
| 1533 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1534 | + ar.exception); |
| 1535 | } |
| 1536 | notifyRequester(request); |
| 1537 | break; |
| 1538 | case CMD_GET_MODEM_STATUS: |
| 1539 | request = (MainThreadRequest) msg.obj; |
| 1540 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1541 | PhoneConfigurationManager.getInstance() |
| 1542 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1543 | break; |
| 1544 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1545 | ar = (AsyncResult) msg.obj; |
| 1546 | request = (MainThreadRequest) ar.userObj; |
| 1547 | int id = request.phone.getPhoneId(); |
| 1548 | if (ar.exception == null && ar.result != null) { |
| 1549 | request.result = ar.result; |
| 1550 | //update the cache as modem status has changed |
| 1551 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1552 | (boolean) request.result); |
| 1553 | } else { |
| 1554 | // Return true if modem status cannot be retrieved. For most cases, |
| 1555 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1556 | // and disable modem are not supported. Modem is always on. |
| 1557 | // TODO: this should be fixed in R to support a third |
| 1558 | // status UNKNOWN b/131631629 |
| 1559 | request.result = true; |
| 1560 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1561 | + ar.exception); |
| 1562 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1563 | notifyRequester(request); |
| 1564 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1565 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1566 | request = (MainThreadRequest) msg.obj; |
| 1567 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1568 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1569 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1570 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1571 | break; |
| 1572 | } |
| 1573 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1574 | ar = (AsyncResult) msg.obj; |
| 1575 | request = (MainThreadRequest) ar.userObj; |
| 1576 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1577 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1578 | args.second.accept(ar.exception == null); |
| 1579 | notifyRequester(request); |
| 1580 | break; |
| 1581 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1582 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1583 | request = (MainThreadRequest) msg.obj; |
| 1584 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1585 | Phone phone = getPhoneFromRequest(request); |
| 1586 | if (phone != null) { |
| 1587 | phone.getSystemSelectionChannels(onCompleted); |
| 1588 | } else { |
| 1589 | loge("getSystemSelectionChannels: No phone object"); |
| 1590 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1591 | notifyRequester(request); |
| 1592 | } |
| 1593 | break; |
| 1594 | } |
| 1595 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1596 | ar = (AsyncResult) msg.obj; |
| 1597 | request = (MainThreadRequest) ar.userObj; |
| 1598 | if (ar.exception == null && ar.result != null) { |
| 1599 | request.result = ar.result; |
| 1600 | } else { |
| 1601 | request.result = new IllegalArgumentException( |
| 1602 | "Failed to retrieve system selection channels"); |
| 1603 | if (ar.result == null) { |
| 1604 | loge("getSystemSelectionChannels: Empty response"); |
| 1605 | } else { |
| 1606 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1607 | } |
| 1608 | } |
| 1609 | notifyRequester(request); |
| 1610 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1611 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1612 | ar = (AsyncResult) msg.obj; |
| 1613 | request = (MainThreadRequest) ar.userObj; |
| 1614 | if (ar.exception == null && ar.result != null) { |
| 1615 | request.result = ar.result; |
| 1616 | } else { |
| 1617 | request.result = -1; |
| 1618 | loge("Failed to set Forbidden Plmns"); |
| 1619 | if (ar.result == null) { |
| 1620 | loge("setForbidenPlmns: Empty response"); |
| 1621 | } else if (ar.exception != null) { |
| 1622 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1623 | request.result = -1; |
| 1624 | } else { |
| 1625 | loge("setForbiddenPlmns: Unknown exception"); |
| 1626 | } |
| 1627 | } |
| 1628 | notifyRequester(request); |
| 1629 | break; |
| 1630 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1631 | request = (MainThreadRequest) msg.obj; |
| 1632 | uiccCard = getUiccCardFromRequest(request); |
| 1633 | if (uiccCard == null) { |
| 1634 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1635 | request.result = -1; |
| 1636 | notifyRequester(request); |
| 1637 | break; |
| 1638 | } |
| 1639 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1640 | (Pair<Integer, List<String>>) request.argument; |
| 1641 | appType = setFplmnsArgs.first; |
| 1642 | List<String> fplmns = setFplmnsArgs.second; |
| 1643 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1644 | if (uiccApp == null) { |
| 1645 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1646 | request.result = -1; |
| 1647 | loge("Failed to get UICC App"); |
| 1648 | notifyRequester(request); |
| 1649 | } else { |
| 1650 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1651 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1652 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1653 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1654 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1655 | case CMD_ERASE_MODEM_CONFIG: |
| 1656 | request = (MainThreadRequest) msg.obj; |
| 1657 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1658 | defaultPhone.eraseModemConfig(onCompleted); |
| 1659 | break; |
| 1660 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1661 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1662 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1663 | |
| 1664 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1665 | request = (MainThreadRequest) msg.obj; |
| 1666 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1667 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1668 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1669 | changed.first, changed.second, onCompleted); |
| 1670 | break; |
| 1671 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1672 | ar = (AsyncResult) msg.obj; |
| 1673 | request = (MainThreadRequest) ar.userObj; |
| 1674 | if (ar.exception == null) { |
| 1675 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1676 | } else { |
| 1677 | request.result = msg.arg1; |
| 1678 | } |
| 1679 | notifyRequester(request); |
| 1680 | break; |
| 1681 | |
| 1682 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1683 | request = (MainThreadRequest) msg.obj; |
| 1684 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1685 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1686 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1687 | enabled.first, enabled.second, onCompleted); |
| 1688 | break; |
| 1689 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1690 | ar = (AsyncResult) msg.obj; |
| 1691 | request = (MainThreadRequest) ar.userObj; |
| 1692 | if (ar.exception == null) { |
| 1693 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1694 | } else { |
| 1695 | request.result = msg.arg1; |
| 1696 | } |
| 1697 | notifyRequester(request); |
| 1698 | break; |
| 1699 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1700 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1701 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1702 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1703 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1704 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1705 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1706 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1707 | |
| 1708 | case CMD_SET_DATA_THROTTLING: { |
| 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1711 | DataThrottlingRequest dataThrottlingRequest = |
| 1712 | (DataThrottlingRequest) request.argument; |
| 1713 | Phone phone = getPhoneFromRequest(request); |
| 1714 | if (phone != null) { |
| 1715 | phone.setDataThrottling(onCompleted, |
| 1716 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1717 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1718 | } else { |
| 1719 | loge("setDataThrottling: No phone object"); |
| 1720 | request.result = |
| 1721 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1722 | notifyRequester(request); |
| 1723 | } |
| 1724 | |
| 1725 | break; |
| 1726 | } |
| 1727 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1728 | ar = (AsyncResult) msg.obj; |
| 1729 | request = (MainThreadRequest) ar.userObj; |
| 1730 | |
| 1731 | if (ar.exception == null) { |
| 1732 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1733 | } else if (ar.exception instanceof CommandException) { |
| 1734 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1735 | CommandException.Error error = |
| 1736 | ((CommandException) (ar.exception)).getCommandError(); |
| 1737 | |
| 1738 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1739 | request.result = TelephonyManager |
| 1740 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1741 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1742 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1743 | } else { |
| 1744 | request.result = |
| 1745 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1746 | } |
| 1747 | } else { |
| 1748 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1749 | } |
| 1750 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1751 | notifyRequester(request); |
| 1752 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1753 | |
| 1754 | case CMD_SET_SIM_POWER: { |
| 1755 | request = (MainThreadRequest) msg.obj; |
| 1756 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1757 | request = (MainThreadRequest) msg.obj; |
| 1758 | int stateToSet = |
| 1759 | ((Pair<Integer, IIntegerConsumer>) |
| 1760 | request.argument).first; |
| 1761 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1762 | break; |
| 1763 | } |
| 1764 | case EVENT_SET_SIM_POWER_DONE: { |
| 1765 | ar = (AsyncResult) msg.obj; |
| 1766 | request = (MainThreadRequest) ar.userObj; |
| 1767 | IIntegerConsumer callback = |
| 1768 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1769 | if (ar.exception != null) { |
| 1770 | loge("setSimPower exception: " + ar.exception); |
| 1771 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1772 | .RESULT_ERROR_UNKNOWN; |
| 1773 | if (ar.exception instanceof CommandException) { |
| 1774 | CommandException.Error error = |
| 1775 | ((CommandException) (ar.exception)).getCommandError(); |
| 1776 | if (error == CommandException.Error.SIM_ERR) { |
| 1777 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1778 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1779 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1780 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1781 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1782 | } else { |
| 1783 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1784 | } |
| 1785 | } |
| 1786 | try { |
| 1787 | callback.accept(errorCode); |
| 1788 | } catch (RemoteException e) { |
| 1789 | // Ignore if the remote process is no longer available to call back. |
| 1790 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1791 | } |
| 1792 | } else { |
| 1793 | try { |
| 1794 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1795 | } catch (RemoteException e) { |
| 1796 | // Ignore if the remote process is no longer available to call back. |
| 1797 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1798 | } |
| 1799 | } |
| 1800 | break; |
| 1801 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1802 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1803 | request = (MainThreadRequest) msg.obj; |
| 1804 | |
| 1805 | final Phone phone = getPhoneFromRequest(request); |
| 1806 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1807 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1808 | notifyRequester(request); |
| 1809 | break; |
| 1810 | } |
| 1811 | |
| 1812 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1813 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1814 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1815 | request); |
| 1816 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1817 | request.subId, pair.first /*callingUid*/, |
| 1818 | pair.second /*request*/, onCompleted); |
| 1819 | break; |
| 1820 | } |
| 1821 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1822 | ar = (AsyncResult) msg.obj; |
| 1823 | request = (MainThreadRequest) ar.userObj; |
| 1824 | // request.result will be the exception of ar if present, true otherwise. |
| 1825 | // Be cautious not to leave result null which will wait() forever |
| 1826 | request.result = ar.exception != null ? ar.exception : true; |
| 1827 | notifyRequester(request); |
| 1828 | break; |
| 1829 | } |
| 1830 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1831 | request = (MainThreadRequest) msg.obj; |
| 1832 | |
| 1833 | Phone phone = getPhoneFromRequest(request); |
| 1834 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1835 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1836 | notifyRequester(request); |
| 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1841 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1842 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1843 | request); |
| 1844 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1845 | request.subId, pair.first /*callingUid*/, |
| 1846 | pair.second /*request*/, onCompleted); |
| 1847 | break; |
| 1848 | } |
| 1849 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1850 | ar = (AsyncResult) msg.obj; |
| 1851 | request = (MainThreadRequest) ar.userObj; |
| 1852 | request.result = ar.exception != null ? ar.exception : true; |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1856 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1857 | default: |
| 1858 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1859 | break; |
| 1860 | } |
| 1861 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1862 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1863 | private void notifyRequester(MainThreadRequest request) { |
| 1864 | synchronized (request) { |
| 1865 | request.notifyAll(); |
| 1866 | } |
| 1867 | } |
| 1868 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1869 | private void handleNullReturnEvent(Message msg, String command) { |
| 1870 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1871 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1872 | if (ar.exception == null) { |
| 1873 | request.result = true; |
| 1874 | } else { |
| 1875 | request.result = false; |
| 1876 | if (ar.exception instanceof CommandException) { |
| 1877 | loge(command + ": CommandException: " + ar.exception); |
| 1878 | } else { |
| 1879 | loge(command + ": Unknown exception"); |
| 1880 | } |
| 1881 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1882 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | /** |
| 1887 | * Posts the specified command to be executed on the main thread, |
| 1888 | * waits for the request to complete, and returns the result. |
| 1889 | * @see #sendRequestAsync |
| 1890 | */ |
| 1891 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1892 | return sendRequest( |
| 1893 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /** |
| 1897 | * Posts the specified command to be executed on the main thread, |
| 1898 | * waits for the request to complete, and returns the result. |
| 1899 | * @see #sendRequestAsync |
| 1900 | */ |
| 1901 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1902 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1903 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /** |
| 1907 | * Posts the specified command to be executed on the main thread, |
| 1908 | * waits for the request to complete, and returns the result. |
| 1909 | * @see #sendRequestAsync |
| 1910 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1911 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1912 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * Posts the specified command to be executed on the main thread, |
| 1917 | * waits for the request to complete, and returns the result. |
| 1918 | * @see #sendRequestAsync |
| 1919 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1920 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1921 | return sendRequest(command, argument, subId, null, workSource); |
| 1922 | } |
| 1923 | |
| 1924 | /** |
| 1925 | * Posts the specified command to be executed on the main thread, |
| 1926 | * waits for the request to complete, and returns the result. |
| 1927 | * @see #sendRequestAsync |
| 1928 | */ |
| 1929 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1930 | return sendRequest( |
| 1931 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Posts the specified command to be executed on the main thread, |
| 1936 | * waits for the request to complete, and returns the result. |
| 1937 | * @see #sendRequestAsync |
| 1938 | */ |
| 1939 | private Object sendRequest( |
| 1940 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1942 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1943 | } |
| 1944 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1945 | MainThreadRequest request = null; |
| 1946 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1947 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1948 | } else if (phone != null) { |
| 1949 | request = new MainThreadRequest(argument, phone, workSource); |
| 1950 | } else { |
| 1951 | request = new MainThreadRequest(argument, subId, workSource); |
| 1952 | } |
| 1953 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1955 | msg.sendToTarget(); |
| 1956 | |
| 1957 | // Wait for the request to complete |
| 1958 | synchronized (request) { |
| 1959 | while (request.result == null) { |
| 1960 | try { |
| 1961 | request.wait(); |
| 1962 | } catch (InterruptedException e) { |
| 1963 | // Do nothing, go back and wait until the request is complete |
| 1964 | } |
| 1965 | } |
| 1966 | } |
| 1967 | return request.result; |
| 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1972 | * Posts the specified command to be executed on the main thread, and |
| 1973 | * returns immediately. |
| 1974 | * @see #sendRequest |
| 1975 | */ |
| 1976 | private void sendRequestAsync(int command) { |
| 1977 | mMainThreadHandler.sendEmptyMessage(command); |
| 1978 | } |
| 1979 | |
| 1980 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1981 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1982 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1983 | */ |
| 1984 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1985 | sendRequestAsync(command, argument, null, null); |
| 1986 | } |
| 1987 | |
| 1988 | /** |
| 1989 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1990 | * @see {@link #sendRequest(int,Object)} |
| 1991 | */ |
| 1992 | private void sendRequestAsync( |
| 1993 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1994 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1995 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1996 | msg.sendToTarget(); |
| 1997 | } |
| 1998 | |
| 1999 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2001 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2002 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2003 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2004 | synchronized (PhoneInterfaceManager.class) { |
| 2005 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2006 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 | } else { |
| 2008 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2009 | } |
| 2010 | return sInstance; |
| 2011 | } |
| 2012 | } |
| 2013 | |
| 2014 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2015 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2018 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2019 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2020 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2021 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2022 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2023 | mTelephonySharedPreferences = |
| 2024 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2025 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2026 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2027 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2028 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | publish(); |
| 2030 | } |
| 2031 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2032 | private Phone getDefaultPhone() { |
| 2033 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2034 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2035 | } |
| 2036 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | private void publish() { |
| 2038 | if (DBG) log("publish: " + this); |
| 2039 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2040 | TelephonyFrameworkInitializer |
| 2041 | .getTelephonyServiceManager() |
| 2042 | .getTelephonyServiceRegisterer() |
| 2043 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2046 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2047 | if (request.phone != null) { |
| 2048 | return request.phone; |
| 2049 | } else { |
| 2050 | return getPhoneFromSubId(request.subId); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | private Phone getPhoneFromSubId(int subId) { |
| 2055 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2056 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2059 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2060 | Phone phone = getPhoneFromRequest(request); |
| 2061 | return phone == null ? null : |
| 2062 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2063 | } |
| 2064 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2065 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2066 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2067 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2070 | private void sendEraseModemConfig(Phone phone) { |
| 2071 | if (phone != null) { |
| 2072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2073 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2074 | final long identity = Binder.clearCallingIdentity(); |
| 2075 | try { |
| 2076 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2077 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(identity); |
| 2080 | } |
| 2081 | } |
| 2082 | } |
| 2083 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2084 | private boolean isImsAvailableOnDevice() { |
| 2085 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2086 | if (pm == null) { |
| 2087 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2088 | // so do not throw error and allow. |
| 2089 | return true; |
| 2090 | } |
| 2091 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2092 | } |
| 2093 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2095 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2098 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | if (DBG) log("dial: " + number); |
| 2100 | // No permission check needed here: This is just a wrapper around the |
| 2101 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2102 | // the UI before it does anything. |
| 2103 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2104 | final long identity = Binder.clearCallingIdentity(); |
| 2105 | try { |
| 2106 | String url = createTelUrl(number); |
| 2107 | if (url == null) { |
| 2108 | return; |
| 2109 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2111 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2112 | PhoneConstants.State state = mCM.getState(subId); |
| 2113 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2114 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2115 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2116 | mApp.startActivity(intent); |
| 2117 | } |
| 2118 | } finally { |
| 2119 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2120 | } |
| 2121 | } |
| 2122 | |
| 2123 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2124 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2127 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | if (DBG) log("call: " + number); |
| 2129 | |
| 2130 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2131 | // need to do a permission check since we're calling startActivity() |
| 2132 | // from the context of the phone app. |
| 2133 | enforceCallPermission(); |
| 2134 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2135 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2136 | != AppOpsManager.MODE_ALLOWED) { |
| 2137 | return; |
| 2138 | } |
| 2139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | final long identity = Binder.clearCallingIdentity(); |
| 2141 | try { |
| 2142 | String url = createTelUrl(number); |
| 2143 | if (url == null) { |
| 2144 | return; |
| 2145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2147 | boolean isValid = false; |
| 2148 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2149 | if (slist != null) { |
| 2150 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2151 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2152 | isValid = true; |
| 2153 | break; |
| 2154 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2155 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2156 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2157 | if (!isValid) { |
| 2158 | return; |
| 2159 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2160 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2161 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2162 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2163 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2164 | mApp.startActivity(intent); |
| 2165 | } finally { |
| 2166 | Binder.restoreCallingIdentity(identity); |
| 2167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2170 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2171 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2172 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2173 | } |
| 2174 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2175 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2176 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2177 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2178 | } |
| 2179 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2180 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2182 | |
| 2183 | final long identity = Binder.clearCallingIdentity(); |
| 2184 | try { |
| 2185 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2186 | checkSimPin.start(); |
| 2187 | return checkSimPin.unlockSim(null, pin); |
| 2188 | } finally { |
| 2189 | Binder.restoreCallingIdentity(identity); |
| 2190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2193 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | |
| 2196 | final long identity = Binder.clearCallingIdentity(); |
| 2197 | try { |
| 2198 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2199 | checkSimPuk.start(); |
| 2200 | return checkSimPuk.unlockSim(puk, pin); |
| 2201 | } finally { |
| 2202 | Binder.restoreCallingIdentity(identity); |
| 2203 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2207 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | * a synchronous one. |
| 2209 | */ |
| 2210 | private static class UnlockSim extends Thread { |
| 2211 | |
| 2212 | private final IccCard mSimCard; |
| 2213 | |
| 2214 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2215 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2216 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 | |
| 2218 | // For replies from SimCard interface |
| 2219 | private Handler mHandler; |
| 2220 | |
| 2221 | // For async handler to identify request type |
| 2222 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2223 | |
| 2224 | public UnlockSim(IccCard simCard) { |
| 2225 | mSimCard = simCard; |
| 2226 | } |
| 2227 | |
| 2228 | @Override |
| 2229 | public void run() { |
| 2230 | Looper.prepare(); |
| 2231 | synchronized (UnlockSim.this) { |
| 2232 | mHandler = new Handler() { |
| 2233 | @Override |
| 2234 | public void handleMessage(Message msg) { |
| 2235 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2236 | switch (msg.what) { |
| 2237 | case SUPPLY_PIN_COMPLETE: |
| 2238 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2239 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2240 | mRetryCount = msg.arg1; |
| 2241 | if (ar.exception != null) { |
| 2242 | if (ar.exception instanceof CommandException && |
| 2243 | ((CommandException)(ar.exception)).getCommandError() |
| 2244 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2245 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2246 | } //When UiccCardApp dispose,handle message and return exception |
| 2247 | else if (ar.exception instanceof CommandException && |
| 2248 | ((CommandException) (ar.exception)).getCommandError() |
| 2249 | == CommandException.Error.ABORTED) { |
| 2250 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2251 | } else { |
| 2252 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2253 | } |
| 2254 | } else { |
| 2255 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2256 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | mDone = true; |
| 2258 | UnlockSim.this.notifyAll(); |
| 2259 | } |
| 2260 | break; |
| 2261 | } |
| 2262 | } |
| 2263 | }; |
| 2264 | UnlockSim.this.notifyAll(); |
| 2265 | } |
| 2266 | Looper.loop(); |
| 2267 | } |
| 2268 | |
| 2269 | /* |
| 2270 | * Use PIN or PUK to unlock SIM card |
| 2271 | * |
| 2272 | * If PUK is null, unlock SIM card with PIN |
| 2273 | * |
| 2274 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2275 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2276 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | |
| 2278 | while (mHandler == null) { |
| 2279 | try { |
| 2280 | wait(); |
| 2281 | } catch (InterruptedException e) { |
| 2282 | Thread.currentThread().interrupt(); |
| 2283 | } |
| 2284 | } |
| 2285 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2286 | |
| 2287 | if (puk == null) { |
| 2288 | mSimCard.supplyPin(pin, callback); |
| 2289 | } else { |
| 2290 | mSimCard.supplyPuk(puk, pin, callback); |
| 2291 | } |
| 2292 | |
| 2293 | while (!mDone) { |
| 2294 | try { |
| 2295 | Log.d(LOG_TAG, "wait for done"); |
| 2296 | wait(); |
| 2297 | } catch (InterruptedException e) { |
| 2298 | // Restore the interrupted status |
| 2299 | Thread.currentThread().interrupt(); |
| 2300 | } |
| 2301 | } |
| 2302 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2303 | int[] resultArray = new int[2]; |
| 2304 | resultArray[0] = mResult; |
| 2305 | resultArray[1] = mRetryCount; |
| 2306 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | } |
| 2308 | } |
| 2309 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2310 | /** |
| 2311 | * This method has been removed due to privacy and stability concerns. |
| 2312 | */ |
| 2313 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2315 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2316 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2319 | @Override |
| 2320 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2321 | mApp.getSystemService(AppOpsManager.class) |
| 2322 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2323 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2324 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2325 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2326 | // Callers targeting S have no business invoking this method. |
| 2327 | return; |
| 2328 | } |
| 2329 | |
| 2330 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2331 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2332 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2333 | .setCallingPackage(callingPackage) |
| 2334 | .setCallingFeatureId(null) |
| 2335 | .setCallingPid(Binder.getCallingPid()) |
| 2336 | .setCallingUid(Binder.getCallingUid()) |
| 2337 | .setMethod("updateServiceLocation") |
| 2338 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2339 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2340 | .build()); |
| 2341 | // Apps that lack location permission have no business calling this method; |
| 2342 | // however, because no permission was declared in the public API, denials must |
| 2343 | // all be "soft". |
| 2344 | switch (locationResult) { |
| 2345 | case DENIED_HARD: /* fall through */ |
| 2346 | case DENIED_SOFT: |
| 2347 | return; |
| 2348 | } |
| 2349 | |
| 2350 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | final long identity = Binder.clearCallingIdentity(); |
| 2352 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2353 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2354 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2355 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | } |
| 2357 | } finally { |
| 2358 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2359 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2362 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2363 | @Override |
| 2364 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2365 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2366 | } |
| 2367 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2368 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2369 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2370 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2371 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2372 | callingFeatureId); |
| 2373 | } |
| 2374 | |
| 2375 | @Deprecated |
| 2376 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2377 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2378 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2379 | } |
| 2380 | |
| 2381 | @Override |
| 2382 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2383 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2384 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2385 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2386 | return false; |
| 2387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2388 | |
| 2389 | final long identity = Binder.clearCallingIdentity(); |
| 2390 | try { |
| 2391 | return isRadioOnForSubscriber(subId); |
| 2392 | } finally { |
| 2393 | Binder.restoreCallingIdentity(identity); |
| 2394 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2398 | final long identity = Binder.clearCallingIdentity(); |
| 2399 | try { |
| 2400 | final Phone phone = getPhone(subId); |
| 2401 | if (phone != null) { |
| 2402 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2403 | } else { |
| 2404 | return false; |
| 2405 | } |
| 2406 | } finally { |
| 2407 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2412 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2414 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2415 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | |
| 2418 | final long identity = Binder.clearCallingIdentity(); |
| 2419 | try { |
| 2420 | final Phone phone = getPhone(subId); |
| 2421 | if (phone != null) { |
| 2422 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2423 | } |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2426 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2430 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2434 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2435 | |
| 2436 | final long identity = Binder.clearCallingIdentity(); |
| 2437 | try { |
| 2438 | final Phone phone = getPhone(subId); |
| 2439 | if (phone == null) { |
| 2440 | return false; |
| 2441 | } |
| 2442 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2443 | toggleRadioOnOffForSubscriber(subId); |
| 2444 | } |
| 2445 | return true; |
| 2446 | } finally { |
| 2447 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2448 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2450 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2451 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2452 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2453 | /* |
| 2454 | * If any of the Radios are available, it will need to be |
| 2455 | * shutdown. So return true if any Radio is available. |
| 2456 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
| 2459 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2460 | Phone phone = PhoneFactory.getPhone(i); |
| 2461 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2462 | } |
| 2463 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2464 | return false; |
| 2465 | } finally { |
| 2466 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2467 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2470 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2471 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | enforceModifyPermission(); |
| 2473 | |
| 2474 | final long identity = Binder.clearCallingIdentity(); |
| 2475 | try { |
| 2476 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2477 | logv("Shutting down Phone " + i); |
| 2478 | shutdownRadioUsingPhoneId(i); |
| 2479 | } |
| 2480 | } finally { |
| 2481 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2482 | } |
| 2483 | } |
| 2484 | |
| 2485 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2486 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2487 | if (phone != null && phone.isRadioAvailable()) { |
| 2488 | phone.shutdownRadio(); |
| 2489 | } |
| 2490 | } |
| 2491 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2493 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2494 | |
| 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
| 2497 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2498 | if (defaultPhone != null) { |
| 2499 | defaultPhone.setRadioPower(turnOn); |
| 2500 | return true; |
| 2501 | } else { |
| 2502 | loge("There's no default phone."); |
| 2503 | return false; |
| 2504 | } |
| 2505 | } finally { |
| 2506 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2507 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2508 | } |
| 2509 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2510 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | |
| 2513 | final long identity = Binder.clearCallingIdentity(); |
| 2514 | try { |
| 2515 | final Phone phone = getPhone(subId); |
| 2516 | if (phone != null) { |
| 2517 | phone.setRadioPower(turnOn); |
| 2518 | return true; |
| 2519 | } else { |
| 2520 | return false; |
| 2521 | } |
| 2522 | } finally { |
| 2523 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2527 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2528 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | public boolean enableDataConnectivity() { |
| 2530 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | |
| 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
| 2534 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2535 | final Phone phone = getPhone(subId); |
| 2536 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2537 | phone.getDataEnabledSettings().setDataEnabled( |
| 2538 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | return true; |
| 2540 | } else { |
| 2541 | return false; |
| 2542 | } |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2548 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2549 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | public boolean disableDataConnectivity() { |
| 2551 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | |
| 2553 | final long identity = Binder.clearCallingIdentity(); |
| 2554 | try { |
| 2555 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2556 | final Phone phone = getPhone(subId); |
| 2557 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2558 | phone.getDataEnabledSettings().setDataEnabled( |
| 2559 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | return true; |
| 2561 | } else { |
| 2562 | return false; |
| 2563 | } |
| 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2566 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2569 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2570 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | final Phone phone = getPhone(subId); |
| 2574 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2575 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | } else { |
| 2577 | return false; |
| 2578 | } |
| 2579 | } finally { |
| 2580 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2585 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2588 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | enforceCallPermission(); |
| 2590 | |
| 2591 | final long identity = Binder.clearCallingIdentity(); |
| 2592 | try { |
| 2593 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2594 | return; |
| 2595 | } |
| 2596 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2597 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2598 | } finally { |
| 2599 | Binder.restoreCallingIdentity(identity); |
| 2600 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2601 | }; |
| 2602 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2603 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | |
| 2606 | final long identity = Binder.clearCallingIdentity(); |
| 2607 | try { |
| 2608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2609 | return false; |
| 2610 | } |
| 2611 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2612 | } finally { |
| 2613 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2614 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2615 | } |
| 2616 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2617 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2618 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2621 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | final long identity = Binder.clearCallingIdentity(); |
| 2623 | try { |
| 2624 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2625 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2626 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
| 2629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2632 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2633 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2634 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2635 | } |
| 2636 | |
| 2637 | @Override |
| 2638 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2639 | final long identity = Binder.clearCallingIdentity(); |
| 2640 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2641 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | if (phone != null) { |
| 2643 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2644 | } else { |
| 2645 | return PhoneConstantConversions.convertDataState( |
| 2646 | PhoneConstants.DataState.DISCONNECTED); |
| 2647 | } |
| 2648 | } finally { |
| 2649 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2650 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2653 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2654 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2655 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2656 | } |
| 2657 | |
| 2658 | @Override |
| 2659 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2662 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2663 | if (phone != null) { |
| 2664 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2665 | } else { |
| 2666 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2667 | } |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2670 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2674 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2675 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2676 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2677 | |
| 2678 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2679 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2680 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2681 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2682 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2683 | .setCallingPid(Binder.getCallingPid()) |
| 2684 | .setCallingUid(Binder.getCallingUid()) |
| 2685 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2686 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2687 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2688 | .build()); |
| 2689 | switch (locationResult) { |
| 2690 | case DENIED_HARD: |
| 2691 | throw new SecurityException("Not allowed to access cell location"); |
| 2692 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2693 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2694 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2697 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | final long identity = Binder.clearCallingIdentity(); |
| 2699 | try { |
| 2700 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2701 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2702 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
| 2705 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2709 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2710 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2711 | // registered cell info, so return a NULL country instead. |
| 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2714 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2715 | // Get default phone in this case. |
| 2716 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2717 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2718 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2720 | if (phone == null) return ""; |
| 2721 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2722 | if (sst == null) return ""; |
| 2723 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2724 | if (lt == null) return ""; |
| 2725 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2726 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2727 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
| 2730 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2733 | /** |
| 2734 | * This method was removed due to potential issues caused by performing partial |
| 2735 | * updates of service state, and lack of a credible use case. |
| 2736 | * |
| 2737 | * This has the ability to break the telephony implementation by disabling notification of |
| 2738 | * changes in device connectivity. DO NOT USE THIS! |
| 2739 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2740 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | public void enableLocationUpdates() { |
| 2742 | mApp.enforceCallingOrSelfPermission( |
| 2743 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2746 | /** |
| 2747 | * This method was removed due to potential issues caused by performing partial |
| 2748 | * updates of service state, and lack of a credible use case. |
| 2749 | * |
| 2750 | * This has the ability to break the telephony implementation by disabling notification of |
| 2751 | * changes in device connectivity. DO NOT USE THIS! |
| 2752 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2753 | @Override |
| 2754 | public void disableLocationUpdates() { |
| 2755 | mApp.enforceCallingOrSelfPermission( |
| 2756 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | @Override |
| 2760 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2761 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2762 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2763 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2764 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2765 | throw new SecurityException( |
| 2766 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2767 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2768 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2769 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2771 | return null; |
| 2772 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2773 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2774 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2776 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2777 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2779 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2780 | for (CellInfo ci : info) { |
| 2781 | if (ci instanceof CellInfoGsm) { |
| 2782 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2783 | } else if (ci instanceof CellInfoWcdma) { |
| 2784 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2785 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2786 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2787 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2790 | private List<CellInfo> getCachedCellInfo() { |
| 2791 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2792 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2793 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2794 | if (info != null) cellInfos.addAll(info); |
| 2795 | } |
| 2796 | return cellInfos; |
| 2797 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | |
| 2799 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2800 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2801 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2802 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2803 | |
| 2804 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2805 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2806 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2807 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2808 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2809 | .setCallingPid(Binder.getCallingPid()) |
| 2810 | .setCallingUid(Binder.getCallingUid()) |
| 2811 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2812 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2813 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2814 | .build()); |
| 2815 | switch (locationResult) { |
| 2816 | case DENIED_HARD: |
| 2817 | throw new SecurityException("Not allowed to access cell info"); |
| 2818 | case DENIED_SOFT: |
| 2819 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2822 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2823 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2824 | return getCachedCellInfo(); |
| 2825 | } |
| 2826 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2827 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2828 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2829 | final long identity = Binder.clearCallingIdentity(); |
| 2830 | try { |
| 2831 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2832 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2833 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2834 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2835 | if (info != null) cellInfos.addAll(info); |
| 2836 | } |
| 2837 | return cellInfos; |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2843 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2844 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2845 | String callingFeatureId) { |
| 2846 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2847 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2851 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2852 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2853 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2854 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2857 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2858 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2859 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2860 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2861 | |
| 2862 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2863 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2864 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2865 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2866 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2867 | .setCallingPid(Binder.getCallingPid()) |
| 2868 | .setCallingUid(Binder.getCallingUid()) |
| 2869 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2870 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2871 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2872 | .build()); |
| 2873 | switch (locationResult) { |
| 2874 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2875 | if (TelephonyPermissions |
| 2876 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2877 | // Safetynet logging for b/154934934 |
| 2878 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2879 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2880 | throw new SecurityException("Not allowed to access cell info"); |
| 2881 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2882 | if (TelephonyPermissions |
| 2883 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2884 | // Safetynet logging for b/154934934 |
| 2885 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2886 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2887 | try { |
| 2888 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2889 | } catch (RemoteException re) { |
| 2890 | // Drop without consequences |
| 2891 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2892 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2895 | |
| 2896 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2897 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2898 | |
| 2899 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2900 | } |
| 2901 | |
| 2902 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2903 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2904 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2905 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | |
| 2907 | final long identity = Binder.clearCallingIdentity(); |
| 2908 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2909 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
| 2912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2915 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2916 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2917 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2918 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2919 | return null; |
| 2920 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2921 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2922 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2923 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2924 | return null; |
| 2925 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | |
| 2927 | final long identity = Binder.clearCallingIdentity(); |
| 2928 | try { |
| 2929 | return phone.getImei(); |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
| 2932 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2936 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2937 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2938 | String tac = null; |
| 2939 | if (phone != null) { |
| 2940 | String imei = phone.getImei(); |
| 2941 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2942 | } |
| 2943 | return tac; |
| 2944 | } |
| 2945 | |
| 2946 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2947 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2948 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2949 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2950 | return null; |
| 2951 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2952 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2953 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2954 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2955 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2956 | return null; |
| 2957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2958 | |
| 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | return phone.getMeid(); |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
| 2964 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2968 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2969 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2970 | String manufacturerCode = null; |
| 2971 | if (phone != null) { |
| 2972 | String meid = phone.getMeid(); |
| 2973 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2974 | } |
| 2975 | return manufacturerCode; |
| 2976 | } |
| 2977 | |
| 2978 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2979 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2980 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2981 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2982 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2983 | return null; |
| 2984 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2985 | int subId = phone.getSubId(); |
| 2986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2987 | mApp, subId, callingPackage, callingFeatureId, |
| 2988 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2989 | return null; |
| 2990 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | |
| 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | return phone.getDeviceSvn(); |
| 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
| 2997 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3000 | @Override |
| 3001 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | final Phone phone = getPhone(subId); |
| 3005 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(identity); |
| 3008 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | @Override |
| 3012 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | final Phone phone = getPhone(subId); |
| 3016 | return phone == null ? null : phone.getCarrierName(); |
| 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3020 | } |
| 3021 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3022 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3023 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | final Phone phone = getPhone(subId); |
| 3027 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3028 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3029 | } finally { |
| 3030 | Binder.restoreCallingIdentity(identity); |
| 3031 | } |
| 3032 | } |
| 3033 | |
| 3034 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3035 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3036 | final long identity = Binder.clearCallingIdentity(); |
| 3037 | try { |
| 3038 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3039 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
| 3042 | } |
| 3043 | } |
| 3044 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3045 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3046 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3047 | if (!isSubscriptionMccMnc) { |
| 3048 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3049 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3050 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3051 | if (phone == null) { |
| 3052 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3053 | } |
| 3054 | final long identity = Binder.clearCallingIdentity(); |
| 3055 | try { |
| 3056 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3057 | } finally { |
| 3058 | Binder.restoreCallingIdentity(identity); |
| 3059 | } |
| 3060 | } |
| 3061 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3062 | // |
| 3063 | // Internal helper methods. |
| 3064 | // |
| 3065 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3066 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3068 | * |
| 3069 | * @throws SecurityException if the caller does not have the required permission |
| 3070 | */ |
| 3071 | private void enforceModifyPermission() { |
| 3072 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3073 | } |
| 3074 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3075 | /** |
| 3076 | * Make sure the caller is system. |
| 3077 | * |
| 3078 | * @throws SecurityException if the caller is not system. |
| 3079 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3080 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3081 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3082 | throw new SecurityException("Caller must be system"); |
| 3083 | } |
| 3084 | } |
| 3085 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3086 | private void enforceActiveEmergencySessionPermission() { |
| 3087 | mApp.enforceCallingOrSelfPermission( |
| 3088 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3089 | } |
| 3090 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3091 | /** |
| 3092 | * Make sure the caller has the CALL_PHONE permission. |
| 3093 | * |
| 3094 | * @throws SecurityException if the caller does not have the required permission |
| 3095 | */ |
| 3096 | private void enforceCallPermission() { |
| 3097 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3098 | } |
| 3099 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3100 | private void enforceSettingsPermission() { |
| 3101 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | private String createTelUrl(String number) { |
| 3105 | if (TextUtils.isEmpty(number)) { |
| 3106 | return null; |
| 3107 | } |
| 3108 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3109 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3112 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3113 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3114 | } |
| 3115 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3116 | private static void logv(String msg) { |
| 3117 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3118 | } |
| 3119 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3120 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3122 | } |
| 3123 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3124 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3125 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3126 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3130 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3131 | final long identity = Binder.clearCallingIdentity(); |
| 3132 | try { |
| 3133 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3134 | if (phone == null) { |
| 3135 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3136 | } else { |
| 3137 | return phone.getPhoneType(); |
| 3138 | } |
| 3139 | } finally { |
| 3140 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3141 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
| 3144 | /** |
| 3145 | * Returns the CDMA ERI icon index to display |
| 3146 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3147 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3148 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3149 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3150 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3153 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3154 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3155 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3157 | mApp, subId, callingPackage, callingFeatureId, |
| 3158 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3159 | return -1; |
| 3160 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3161 | |
| 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
| 3164 | final Phone phone = getPhone(subId); |
| 3165 | if (phone != null) { |
| 3166 | return phone.getCdmaEriIconIndex(); |
| 3167 | } else { |
| 3168 | return -1; |
| 3169 | } |
| 3170 | } finally { |
| 3171 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3172 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | /** |
| 3176 | * Returns the CDMA ERI icon mode, |
| 3177 | * 0 - ON |
| 3178 | * 1 - FLASHING |
| 3179 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3180 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3181 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3182 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3183 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3186 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3187 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3188 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3189 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3190 | mApp, subId, callingPackage, callingFeatureId, |
| 3191 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3192 | return -1; |
| 3193 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | |
| 3195 | final long identity = Binder.clearCallingIdentity(); |
| 3196 | try { |
| 3197 | final Phone phone = getPhone(subId); |
| 3198 | if (phone != null) { |
| 3199 | return phone.getCdmaEriIconMode(); |
| 3200 | } else { |
| 3201 | return -1; |
| 3202 | } |
| 3203 | } finally { |
| 3204 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3205 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | /** |
| 3209 | * Returns the CDMA ERI text, |
| 3210 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3211 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3212 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3213 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3214 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3215 | } |
| 3216 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3217 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3218 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3219 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3221 | mApp, subId, callingPackage, callingFeatureId, |
| 3222 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3223 | return null; |
| 3224 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3225 | |
| 3226 | final long identity = Binder.clearCallingIdentity(); |
| 3227 | try { |
| 3228 | final Phone phone = getPhone(subId); |
| 3229 | if (phone != null) { |
| 3230 | return phone.getCdmaEriText(); |
| 3231 | } else { |
| 3232 | return null; |
| 3233 | } |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3236 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3240 | * Returns the CDMA MDN. |
| 3241 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3242 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3243 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3245 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3246 | |
| 3247 | final long identity = Binder.clearCallingIdentity(); |
| 3248 | try { |
| 3249 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3250 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | return phone.getLine1Number(); |
| 3252 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3253 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3254 | return null; |
| 3255 | } |
| 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | /** |
| 3262 | * Returns the CDMA MIN. |
| 3263 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3264 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3265 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3267 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | |
| 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
| 3271 | final Phone phone = getPhone(subId); |
| 3272 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3273 | return phone.getCdmaMin(); |
| 3274 | } else { |
| 3275 | return null; |
| 3276 | } |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3279 | } |
| 3280 | } |
| 3281 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3282 | @Override |
| 3283 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3284 | INumberVerificationCallback callback, String callingPackage) { |
| 3285 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3286 | != PERMISSION_GRANTED) { |
| 3287 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3288 | } |
| 3289 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3290 | |
| 3291 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3292 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3293 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3294 | + "calling package: " + callingPackage |
| 3295 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | if (range == null) { |
| 3299 | throw new NullPointerException("Range must be non-null"); |
| 3300 | } |
| 3301 | |
| 3302 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3303 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3304 | |
| 3305 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3306 | } |
| 3307 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3308 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3309 | * Returns true if CDMA provisioning needs to run. |
| 3310 | */ |
| 3311 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | final long identity = Binder.clearCallingIdentity(); |
| 3313 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3314 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(identity); |
| 3317 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3321 | * Sets the voice mail number of a given subId. |
| 3322 | */ |
| 3323 | @Override |
| 3324 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3325 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3326 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3327 | |
| 3328 | final long identity = Binder.clearCallingIdentity(); |
| 3329 | try { |
| 3330 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3331 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3332 | return success; |
| 3333 | } finally { |
| 3334 | Binder.restoreCallingIdentity(identity); |
| 3335 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3336 | } |
| 3337 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3338 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3339 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3340 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3341 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3342 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3343 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3344 | throw new SecurityException("caller must be system dialer"); |
| 3345 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3346 | |
| 3347 | final long identity = Binder.clearCallingIdentity(); |
| 3348 | try { |
| 3349 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3350 | if (phoneAccountHandle == null) { |
| 3351 | return null; |
| 3352 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3353 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | } finally { |
| 3355 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3356 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3360 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3361 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3362 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3363 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3364 | mApp, subId, callingPackage, callingFeatureId, |
| 3365 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3366 | return null; |
| 3367 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3369 | final long identity = Binder.clearCallingIdentity(); |
| 3370 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3371 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3372 | } finally { |
| 3373 | Binder.restoreCallingIdentity(identity); |
| 3374 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3378 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3379 | VisualVoicemailSmsFilterSettings settings) { |
| 3380 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | |
| 3382 | final long identity = Binder.clearCallingIdentity(); |
| 3383 | try { |
| 3384 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3385 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
| 3388 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
| 3391 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3392 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3394 | |
| 3395 | final long identity = Binder.clearCallingIdentity(); |
| 3396 | try { |
| 3397 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3398 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | } finally { |
| 3400 | Binder.restoreCallingIdentity(identity); |
| 3401 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3405 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3406 | String callingPackage, int subId) { |
| 3407 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3408 | |
| 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3412 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3419 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3421 | |
| 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3425 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
| 3428 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3432 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3433 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3434 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3435 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3436 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3437 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3438 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3439 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3440 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3441 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3442 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3443 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3444 | * Sets the voice activation state of a given subId. |
| 3445 | */ |
| 3446 | @Override |
| 3447 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3449 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | |
| 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | final Phone phone = getPhone(subId); |
| 3454 | if (phone != null) { |
| 3455 | phone.setVoiceActivationState(activationState); |
| 3456 | } else { |
| 3457 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3458 | } |
| 3459 | } finally { |
| 3460 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | /** |
| 3465 | * Sets the data activation state of a given subId. |
| 3466 | */ |
| 3467 | @Override |
| 3468 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3469 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3470 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3471 | |
| 3472 | final long identity = Binder.clearCallingIdentity(); |
| 3473 | try { |
| 3474 | final Phone phone = getPhone(subId); |
| 3475 | if (phone != null) { |
| 3476 | phone.setDataActivationState(activationState); |
| 3477 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3478 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | } |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | /** |
| 3486 | * Returns the voice activation state of a given subId. |
| 3487 | */ |
| 3488 | @Override |
| 3489 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3490 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3491 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3492 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3493 | final long identity = Binder.clearCallingIdentity(); |
| 3494 | try { |
| 3495 | if (phone != null) { |
| 3496 | return phone.getVoiceActivationState(); |
| 3497 | } else { |
| 3498 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3499 | } |
| 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | /** |
| 3506 | * Returns the data activation state of a given subId. |
| 3507 | */ |
| 3508 | @Override |
| 3509 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3510 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3511 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3512 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | if (phone != null) { |
| 3516 | return phone.getDataActivationState(); |
| 3517 | } else { |
| 3518 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3519 | } |
| 3520 | } finally { |
| 3521 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3522 | } |
| 3523 | } |
| 3524 | |
| 3525 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3526 | * Returns the unread count of voicemails for a subId |
| 3527 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3528 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3529 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3530 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3531 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3532 | mApp, subId, callingPackage, callingFeatureId, |
| 3533 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3534 | return 0; |
| 3535 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | final long identity = Binder.clearCallingIdentity(); |
| 3537 | try { |
| 3538 | final Phone phone = getPhone(subId); |
| 3539 | if (phone != null) { |
| 3540 | return phone.getVoiceMessageCount(); |
| 3541 | } else { |
| 3542 | return 0; |
| 3543 | } |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3550 | * returns true, if the device is in a state where both voice and data |
| 3551 | * are supported simultaneously. This can change based on location or network condition. |
| 3552 | */ |
| 3553 | @Override |
| 3554 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3555 | final long identity = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | final Phone phone = getPhone(subId); |
| 3558 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3559 | } finally { |
| 3560 | Binder.restoreCallingIdentity(identity); |
| 3561 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3562 | } |
| 3563 | |
| 3564 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3565 | * Send the dialer code if called from the current default dialer or the caller has |
| 3566 | * carrier privilege. |
| 3567 | * @param inputCode The dialer code to send |
| 3568 | */ |
| 3569 | @Override |
| 3570 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3571 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3572 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3573 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3574 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3575 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3576 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3577 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3578 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3579 | |
| 3580 | final long identity = Binder.clearCallingIdentity(); |
| 3581 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3582 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(identity); |
| 3585 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3588 | @Override |
| 3589 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3590 | TelephonyPermissions |
| 3591 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3592 | mApp, subId, "getNetworkSelectionMode"); |
| 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | if (!isActiveSubscription(subId)) { |
| 3596 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3597 | } |
| 3598 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3601 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3602 | } |
| 3603 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3605 | public boolean isInEmergencySmsMode() { |
| 3606 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3607 | final long identity = Binder.clearCallingIdentity(); |
| 3608 | try { |
| 3609 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3610 | if (phone.isInEmergencySmsMode()) { |
| 3611 | return true; |
| 3612 | } |
| 3613 | } |
| 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(identity); |
| 3616 | } |
| 3617 | return false; |
| 3618 | } |
| 3619 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3620 | /** |
| 3621 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3622 | * @param subId The subscription to use to check the configuration. |
| 3623 | * @param c The callback that will be used to send the result. |
| 3624 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3625 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3626 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3627 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3628 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3629 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3630 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3631 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3632 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3633 | "IMS not available on device."); |
| 3634 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3635 | final long token = Binder.clearCallingIdentity(); |
| 3636 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3637 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3638 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3639 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3640 | } catch (ImsException e) { |
| 3641 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3642 | } finally { |
| 3643 | Binder.restoreCallingIdentity(token); |
| 3644 | } |
| 3645 | } |
| 3646 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3647 | /** |
| 3648 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3649 | * @param subId The subscription to use to check the configuration. |
| 3650 | * @param c The callback that will be used to send the result. |
| 3651 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3652 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3653 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3654 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3655 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3656 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3657 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3658 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3659 | final long token = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3662 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3663 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3664 | } catch (ImsException e) { |
| 3665 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3666 | + "is inactive, ignoring unregister."); |
| 3667 | // If the subscription is no longer active, just return, since the callback |
| 3668 | // will already have been removed internally. |
| 3669 | } finally { |
| 3670 | Binder.restoreCallingIdentity(token); |
| 3671 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3674 | /** |
| 3675 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3676 | */ |
| 3677 | @Override |
| 3678 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3679 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3680 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3681 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3682 | "IMS not available on device."); |
| 3683 | } |
| 3684 | final long token = Binder.clearCallingIdentity(); |
| 3685 | try { |
| 3686 | Phone phone = getPhone(subId); |
| 3687 | if (phone == null) { |
| 3688 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3689 | + subId + "'"); |
| 3690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3691 | } |
| 3692 | phone.getImsRegistrationState(regState -> { |
| 3693 | try { |
| 3694 | consumer.accept((regState == null) |
| 3695 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3696 | } catch (RemoteException e) { |
| 3697 | // Ignore if the remote process is no longer available to call back. |
| 3698 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3699 | } |
| 3700 | }); |
| 3701 | } finally { |
| 3702 | Binder.restoreCallingIdentity(token); |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | /** |
| 3707 | * Get the transport type for the IMS service registration state. |
| 3708 | */ |
| 3709 | @Override |
| 3710 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3711 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3712 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3713 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3715 | "IMS not available on device."); |
| 3716 | } |
| 3717 | final long token = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | Phone phone = getPhone(subId); |
| 3720 | if (phone == null) { |
| 3721 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3722 | + subId + "'"); |
| 3723 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3724 | } |
| 3725 | phone.getImsRegistrationTech(regTech -> { |
| 3726 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3727 | int regTechConverted = (regTech == null) |
| 3728 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3729 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3730 | regTechConverted); |
| 3731 | try { |
| 3732 | consumer.accept(regTechConverted); |
| 3733 | } catch (RemoteException e) { |
| 3734 | // Ignore if the remote process is no longer available to call back. |
| 3735 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3736 | } |
| 3737 | }); |
| 3738 | } finally { |
| 3739 | Binder.restoreCallingIdentity(token); |
| 3740 | } |
| 3741 | } |
| 3742 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3743 | /** |
| 3744 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3745 | * @param subId The subscription to use to check the configuration. |
| 3746 | * @param c The callback that will be used to send the result. |
| 3747 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3748 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3749 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3750 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3751 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3752 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3753 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3754 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3755 | "IMS not available on device."); |
| 3756 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3758 | final long token = Binder.clearCallingIdentity(); |
| 3759 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3760 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3761 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3762 | } catch (ImsException e) { |
| 3763 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3764 | } finally { |
| 3765 | Binder.restoreCallingIdentity(token); |
| 3766 | } |
| 3767 | } |
| 3768 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3769 | /** |
| 3770 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3771 | * @param subId The subscription to use to check the configuration. |
| 3772 | * @param c The callback that will be used to send the result. |
| 3773 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3774 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3775 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3776 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3777 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3778 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3779 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3780 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3781 | |
| 3782 | final long token = Binder.clearCallingIdentity(); |
| 3783 | try { |
| 3784 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3785 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3786 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3787 | } catch (ImsException e) { |
| 3788 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3789 | + "is inactive, ignoring unregister."); |
| 3790 | // If the subscription is no longer active, just return, since the callback |
| 3791 | // will already have been removed internally. |
| 3792 | } finally { |
| 3793 | Binder.restoreCallingIdentity(token); |
| 3794 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3798 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3799 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3800 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3801 | final long token = Binder.clearCallingIdentity(); |
| 3802 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3803 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3804 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3805 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3806 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3807 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3808 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3809 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3810 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(token); |
| 3813 | } |
| 3814 | } |
| 3815 | |
| 3816 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3817 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3818 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | final long token = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | Phone phone = getPhone(subId); |
| 3822 | if (phone == null) return false; |
| 3823 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3824 | } catch (com.android.ims.ImsException e) { |
| 3825 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3826 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(token); |
| 3829 | } |
| 3830 | } |
| 3831 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3832 | /** |
| 3833 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3834 | * subscription. |
| 3835 | * @param subId The subscription to use to check the configuration. |
| 3836 | * @param callback The callback that will be used to send the result. |
| 3837 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3838 | * @param transportType The transport type of the MmTelFeature capability. |
| 3839 | */ |
| 3840 | @Override |
| 3841 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3842 | int transportType) { |
| 3843 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3844 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3845 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3846 | "IMS not available on device."); |
| 3847 | } |
| 3848 | final long token = Binder.clearCallingIdentity(); |
| 3849 | try { |
| 3850 | int slotId = getSlotIndex(subId); |
| 3851 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3852 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3853 | + subId + "'"); |
| 3854 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3855 | } |
| 3856 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3857 | transportType, aBoolean -> { |
| 3858 | try { |
| 3859 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3860 | } catch (RemoteException e) { |
| 3861 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3862 | + "running. Ignore"); |
| 3863 | } |
| 3864 | }); |
| 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(token); |
| 3867 | } |
| 3868 | } |
| 3869 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3870 | /** |
| 3871 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3872 | * @param subId The subscription to use to check the configuration. |
| 3873 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3874 | @Override |
| 3875 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3876 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3877 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3878 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3879 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3880 | final long token = Binder.clearCallingIdentity(); |
| 3881 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3882 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3883 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3884 | } catch (ImsException e) { |
| 3885 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(token); |
| 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3892 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3894 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3895 | final long identity = Binder.clearCallingIdentity(); |
| 3896 | try { |
| 3897 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3898 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3900 | } catch (ImsException e) { |
| 3901 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3902 | } finally { |
| 3903 | Binder.restoreCallingIdentity(identity); |
| 3904 | } |
| 3905 | } |
| 3906 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3907 | /** |
| 3908 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3909 | * @param subId The subscription to use to check the configuration. |
| 3910 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3912 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3913 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3914 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | final long identity = Binder.clearCallingIdentity(); |
| 3916 | try { |
| 3917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3918 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3919 | } catch (ImsException e) { |
| 3920 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3921 | } finally { |
| 3922 | Binder.restoreCallingIdentity(identity); |
| 3923 | } |
| 3924 | } |
| 3925 | |
| 3926 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3927 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3929 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3930 | final long identity = Binder.clearCallingIdentity(); |
| 3931 | try { |
| 3932 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3933 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3934 | } catch (ImsException e) { |
| 3935 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | } finally { |
| 3937 | Binder.restoreCallingIdentity(identity); |
| 3938 | } |
| 3939 | } |
| 3940 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3941 | /** |
| 3942 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3943 | * @param subId The subscription to use to check the configuration. |
| 3944 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3945 | @Override |
| 3946 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3947 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3948 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3952 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3953 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3954 | } catch (ImsException e) { |
| 3955 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(identity); |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3962 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3964 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3965 | final long identity = Binder.clearCallingIdentity(); |
| 3966 | try { |
| 3967 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3968 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3969 | } catch (ImsException e) { |
| 3970 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3971 | } finally { |
| 3972 | Binder.restoreCallingIdentity(identity); |
| 3973 | } |
| 3974 | } |
| 3975 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3976 | /** |
| 3977 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3978 | * @param subId The subscription to use to check the configuration. |
| 3979 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | @Override |
| 3981 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3982 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3983 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | final long identity = Binder.clearCallingIdentity(); |
| 3985 | try { |
| 3986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3987 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3988 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3989 | } catch (ImsException e) { |
| 3990 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3991 | } finally { |
| 3992 | Binder.restoreCallingIdentity(identity); |
| 3993 | } |
| 3994 | } |
| 3995 | |
| 3996 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3997 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3999 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | final long identity = Binder.clearCallingIdentity(); |
| 4001 | try { |
| 4002 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4003 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4004 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4005 | } catch (ImsException e) { |
| 4006 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | } finally { |
| 4008 | Binder.restoreCallingIdentity(identity); |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | @Override |
| 4013 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4015 | "setVoWiFiNonPersistent"); |
| 4016 | final long identity = Binder.clearCallingIdentity(); |
| 4017 | try { |
| 4018 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4019 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4020 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4021 | } catch (ImsException e) { |
| 4022 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | } finally { |
| 4024 | Binder.restoreCallingIdentity(identity); |
| 4025 | } |
| 4026 | } |
| 4027 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4028 | /** |
| 4029 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4030 | * @param subId The subscription to use to check the configuration. |
| 4031 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | @Override |
| 4033 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4034 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4035 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4036 | final long identity = Binder.clearCallingIdentity(); |
| 4037 | try { |
| 4038 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4039 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4041 | } catch (ImsException e) { |
| 4042 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4043 | } finally { |
| 4044 | Binder.restoreCallingIdentity(identity); |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | @Override |
| 4049 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4050 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4051 | "setVoWiFiModeSetting"); |
| 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4055 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4056 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4057 | } catch (ImsException e) { |
| 4058 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | } finally { |
| 4060 | Binder.restoreCallingIdentity(identity); |
| 4061 | } |
| 4062 | } |
| 4063 | |
| 4064 | @Override |
| 4065 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4066 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4067 | final long identity = Binder.clearCallingIdentity(); |
| 4068 | try { |
| 4069 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4070 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4071 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4072 | } catch (ImsException e) { |
| 4073 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | } finally { |
| 4075 | Binder.restoreCallingIdentity(identity); |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | @Override |
| 4080 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4082 | "setVoWiFiRoamingModeSetting"); |
| 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4086 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4087 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4088 | } catch (ImsException e) { |
| 4089 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | } finally { |
| 4091 | Binder.restoreCallingIdentity(identity); |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | @Override |
| 4096 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4098 | "setRttCapabilityEnabled"); |
| 4099 | final long identity = Binder.clearCallingIdentity(); |
| 4100 | try { |
| 4101 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4102 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4103 | } catch (ImsException e) { |
| 4104 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4105 | } finally { |
| 4106 | Binder.restoreCallingIdentity(identity); |
| 4107 | } |
| 4108 | } |
| 4109 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4110 | /** |
| 4111 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4112 | * @param subId The subscription to use to check the configuration. |
| 4113 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | @Override |
| 4115 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4116 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4117 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4118 | final long identity = Binder.clearCallingIdentity(); |
| 4119 | try { |
| 4120 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4121 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4123 | } catch (ImsException e) { |
| 4124 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
| 4127 | } |
| 4128 | } |
| 4129 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4130 | @Override |
| 4131 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4132 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4133 | final long identity = Binder.clearCallingIdentity(); |
| 4134 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4135 | if (!isImsAvailableOnDevice()) { |
| 4136 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4137 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4138 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4139 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4140 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4141 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4142 | } catch (ImsException e) { |
| 4143 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
| 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | @Override |
| 4150 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4151 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4152 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4153 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4154 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4155 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4156 | try { |
| 4157 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4158 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4159 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4160 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4161 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4162 | + "is inactive, ignoring unregister."); |
| 4163 | // If the subscription is no longer active, just return, since the callback will already |
| 4164 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
| 4168 | } |
| 4169 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4170 | |
| 4171 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4173 | message); |
| 4174 | } |
| 4175 | |
| 4176 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4177 | boolean isMmtelCapability) { |
| 4178 | Phone phone = getPhone(subId); |
| 4179 | if (phone == null) { |
| 4180 | loge("phone instance null for subid " + subId); |
| 4181 | return false; |
| 4182 | } |
| 4183 | if (isMmtelCapability) { |
| 4184 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4185 | return false; |
| 4186 | } |
| 4187 | } else { |
| 4188 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4189 | return false; |
| 4190 | } |
| 4191 | } |
| 4192 | return true; |
| 4193 | } |
| 4194 | |
| 4195 | @Override |
| 4196 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4197 | boolean isProvisioned) { |
| 4198 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4199 | |
| 4200 | final long identity = Binder.clearCallingIdentity(); |
| 4201 | try { |
| 4202 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4203 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4204 | return; |
| 4205 | } |
| 4206 | |
| 4207 | // this capability requires provisioning, route to the correct API. |
| 4208 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4209 | switch (capability) { |
| 4210 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4211 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4212 | ims.setEabProvisioned(isProvisioned); |
| 4213 | break; |
| 4214 | default: { |
| 4215 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4216 | + "rcs capability '" + capability + "', which does not require " |
| 4217 | + "provisioning."); |
| 4218 | } |
| 4219 | } |
| 4220 | } finally { |
| 4221 | Binder.restoreCallingIdentity(identity); |
| 4222 | } |
| 4223 | |
| 4224 | } |
| 4225 | |
| 4226 | |
| 4227 | @Override |
| 4228 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4229 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4230 | final long identity = Binder.clearCallingIdentity(); |
| 4231 | try { |
| 4232 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4233 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4234 | return true; |
| 4235 | } |
| 4236 | |
| 4237 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4238 | switch (capability) { |
| 4239 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4240 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4241 | return ims.isEabProvisionedOnDevice(); |
| 4242 | |
| 4243 | default: { |
| 4244 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4245 | + "capability '" + capability + "', which does not require " |
| 4246 | + "provisioning."); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | } finally { |
| 4251 | Binder.restoreCallingIdentity(identity); |
| 4252 | } |
| 4253 | } |
| 4254 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4255 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4256 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4257 | boolean isProvisioned) { |
| 4258 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4259 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4260 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4261 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4262 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4263 | final long identity = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4266 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4267 | return; |
| 4268 | } |
| 4269 | |
| 4270 | // this capability requires provisioning, route to the correct API. |
| 4271 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4272 | switch (capability) { |
| 4273 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4274 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4275 | ims.setVolteProvisioned(isProvisioned); |
| 4276 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4277 | ims.setWfcProvisioned(isProvisioned); |
| 4278 | } |
| 4279 | break; |
| 4280 | } |
| 4281 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4282 | // There is currently no difference in VT provisioning type. |
| 4283 | ims.setVtProvisioned(isProvisioned); |
| 4284 | break; |
| 4285 | } |
| 4286 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4287 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4288 | // change the capability of the feature instead if needed. |
| 4289 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4290 | == isProvisioned) { |
| 4291 | // No change in provisioning. |
| 4292 | return; |
| 4293 | } |
| 4294 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4295 | try { |
| 4296 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4297 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4298 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4299 | + ", Exception" + e.getMessage()); |
| 4300 | } |
| 4301 | break; |
| 4302 | } |
| 4303 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4304 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4305 | + "MmTel capability '" + capability + "', which does not require " |
| 4306 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4307 | } |
| 4308 | } |
| 4309 | |
| 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(identity); |
| 4312 | } |
| 4313 | } |
| 4314 | |
| 4315 | @Override |
| 4316 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4317 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4318 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4319 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4320 | } |
| 4321 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4322 | final long identity = Binder.clearCallingIdentity(); |
| 4323 | try { |
| 4324 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4325 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4326 | return true; |
| 4327 | } |
| 4328 | |
| 4329 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4330 | switch (capability) { |
| 4331 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4332 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4333 | return ims.isVolteProvisionedOnDevice(); |
| 4334 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4335 | return ims.isWfcProvisionedOnDevice(); |
| 4336 | } |
| 4337 | // This should never happen, since we are checking tech above to make sure it |
| 4338 | // is either LTE or IWLAN. |
| 4339 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4340 | + "capability."); |
| 4341 | } |
| 4342 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4343 | // There is currently no difference in VT provisioning type. |
| 4344 | return ims.isVtProvisionedOnDevice(); |
| 4345 | } |
| 4346 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4347 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4348 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4349 | } |
| 4350 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4351 | throw new IllegalArgumentException( |
| 4352 | "Tried to get provisioning for MmTel capability '" + capability |
| 4353 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | } finally { |
| 4358 | Binder.restoreCallingIdentity(identity); |
| 4359 | } |
| 4360 | } |
| 4361 | |
| 4362 | @Override |
| 4363 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4364 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4365 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4366 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4367 | } |
| 4368 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4369 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4370 | return (provisionedBits & capability) > 0; |
| 4371 | } |
| 4372 | |
| 4373 | @Override |
| 4374 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4375 | boolean isProvisioned) { |
| 4376 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4377 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4378 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4379 | } |
| 4380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4381 | "setProvisioningStatusForCapability"); |
| 4382 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4383 | // If the current provisioning status for capability already matches isProvisioned, |
| 4384 | // do nothing. |
| 4385 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4386 | return; |
| 4387 | } |
| 4388 | if (isProvisioned) { |
| 4389 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4390 | } else { |
| 4391 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | /** |
| 4396 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4397 | * technology. The bitfield should mirror the bitfield defined by |
| 4398 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4399 | */ |
| 4400 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4401 | String key = getMmTelProvisioningKey(subId, tech); |
| 4402 | // Default is no capabilities are provisioned. |
| 4403 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4404 | } |
| 4405 | |
| 4406 | /** |
| 4407 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4408 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4409 | * technology specified. |
| 4410 | * |
| 4411 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4412 | */ |
| 4413 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4414 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4415 | String key = getMmTelProvisioningKey(subId, tech); |
| 4416 | editor.putInt(key, newField); |
| 4417 | editor.commit(); |
| 4418 | } |
| 4419 | |
| 4420 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4421 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4422 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4423 | } |
| 4424 | |
| 4425 | /** |
| 4426 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4427 | * carrier associated with the subscription id. |
| 4428 | */ |
| 4429 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4430 | int capability) { |
| 4431 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4432 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4433 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4434 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4435 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4436 | false); |
| 4437 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4438 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4439 | |
| 4440 | // First check to make sure that the capability requires provisioning. |
| 4441 | switch (capability) { |
| 4442 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4443 | // intentional fallthrough |
| 4444 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4445 | if (requireVoiceVtProvisioning) { |
| 4446 | // Voice and Video requires provisioning |
| 4447 | return true; |
| 4448 | } |
| 4449 | break; |
| 4450 | } |
| 4451 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4452 | if (requireUtProvisioning) { |
| 4453 | // UT requires provisioning |
| 4454 | return true; |
| 4455 | } |
| 4456 | break; |
| 4457 | } |
| 4458 | } |
| 4459 | return false; |
| 4460 | } |
| 4461 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4462 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4463 | int capability) { |
| 4464 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4465 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4466 | |
| 4467 | boolean requireRcsProvisioning = c.getBoolean( |
| 4468 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4469 | |
| 4470 | // First check to make sure that the capability requires provisioning. |
| 4471 | switch (capability) { |
| 4472 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4473 | // intentional fallthrough |
| 4474 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4475 | if (requireRcsProvisioning) { |
| 4476 | // OPTION or PRESENCE requires provisioning |
| 4477 | return true; |
| 4478 | } |
| 4479 | break; |
| 4480 | } |
| 4481 | } |
| 4482 | return false; |
| 4483 | } |
| 4484 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4485 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4486 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4487 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4488 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4489 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4490 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4491 | final long identity = Binder.clearCallingIdentity(); |
| 4492 | try { |
| 4493 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4494 | int slotId = getSlotIndex(subId); |
| 4495 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4496 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4497 | + subId + "' for key:" + key); |
| 4498 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4499 | } |
| 4500 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4501 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4502 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4503 | + subId + "' for key:" + key); |
| 4504 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
| 4507 | } |
| 4508 | } |
| 4509 | |
| 4510 | @Override |
| 4511 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4512 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4513 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4514 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4515 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4516 | final long identity = Binder.clearCallingIdentity(); |
| 4517 | try { |
| 4518 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4519 | int slotId = getSlotIndex(subId); |
| 4520 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4521 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4522 | + subId + "' for key:" + key); |
| 4523 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4524 | } |
| 4525 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4526 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4527 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4528 | + subId + "' for key:" + key); |
| 4529 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | @Override |
| 4536 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4537 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4538 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4539 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4541 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4542 | final long identity = Binder.clearCallingIdentity(); |
| 4543 | try { |
| 4544 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4545 | int slotId = getSlotIndex(subId); |
| 4546 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4547 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4548 | + subId + "' for key:" + key); |
| 4549 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4550 | } |
| 4551 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4552 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4553 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4554 | + "' for key:" + key); |
| 4555 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4556 | } finally { |
| 4557 | Binder.restoreCallingIdentity(identity); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | @Override |
| 4562 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4563 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4564 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4565 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4567 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4568 | final long identity = Binder.clearCallingIdentity(); |
| 4569 | try { |
| 4570 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4571 | int slotId = getSlotIndex(subId); |
| 4572 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4573 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4574 | + subId + "' for key:" + key); |
| 4575 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4576 | } |
| 4577 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4578 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4579 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4580 | + "' for key:" + key); |
| 4581 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
| 4585 | } |
| 4586 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4587 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4588 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4589 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4590 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4591 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4592 | } |
| 4593 | return slotId; |
| 4594 | } |
| 4595 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4596 | private int getSlotIndex(int subId) { |
| 4597 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4598 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4599 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4600 | } |
| 4601 | return slotId; |
| 4602 | } |
| 4603 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4604 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4605 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4606 | */ |
| 4607 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4608 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4609 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4610 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4611 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4612 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4613 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4614 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4615 | mApp, subId, callingPackage, callingFeatureId, |
| 4616 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4617 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4618 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4620 | final long identity = Binder.clearCallingIdentity(); |
| 4621 | try { |
| 4622 | final Phone phone = getPhone(subId); |
| 4623 | if (phone != null) { |
| 4624 | return phone.getServiceState().getDataNetworkType(); |
| 4625 | } else { |
| 4626 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4627 | } |
| 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4631 | } |
| 4632 | |
| 4633 | /** |
| 4634 | * Returns the data network type |
| 4635 | */ |
| 4636 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4637 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4638 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4639 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | /** |
| 4643 | * Returns the data network type for a subId |
| 4644 | */ |
| 4645 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4646 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4647 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4649 | mApp, subId, callingPackage, callingFeatureId, |
| 4650 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4651 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4652 | } |
| 4653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4654 | final long identity = Binder.clearCallingIdentity(); |
| 4655 | try { |
| 4656 | final Phone phone = getPhone(subId); |
| 4657 | if (phone != null) { |
| 4658 | return phone.getServiceState().getDataNetworkType(); |
| 4659 | } else { |
| 4660 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4661 | } |
| 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4664 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4668 | * Returns the Voice network type for a subId |
| 4669 | */ |
| 4670 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4671 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4672 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4673 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4674 | mApp, subId, callingPackage, callingFeatureId, |
| 4675 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4676 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4677 | } |
| 4678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4679 | final long identity = Binder.clearCallingIdentity(); |
| 4680 | try { |
| 4681 | final Phone phone = getPhone(subId); |
| 4682 | if (phone != null) { |
| 4683 | return phone.getServiceState().getVoiceNetworkType(); |
| 4684 | } else { |
| 4685 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4686 | } |
| 4687 | } finally { |
| 4688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | /** |
| 4693 | * @return true if a ICC card is present |
| 4694 | */ |
| 4695 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4696 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4697 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4698 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4702 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4703 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4704 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4705 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | final long identity = Binder.clearCallingIdentity(); |
| 4707 | try { |
| 4708 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4709 | if (phone != null) { |
| 4710 | return phone.getIccCard().hasIccCard(); |
| 4711 | } else { |
| 4712 | return false; |
| 4713 | } |
| 4714 | } finally { |
| 4715 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4716 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | /** |
| 4720 | * Return if the current radio is LTE on CDMA. This |
| 4721 | * is a tri-state return value as for a period of time |
| 4722 | * the mode may be unknown. |
| 4723 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4724 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4725 | * @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] | 4726 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4727 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4728 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4729 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4730 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4731 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4732 | } |
| 4733 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4734 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4735 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4736 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4737 | try { |
| 4738 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4739 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4740 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4741 | } |
| 4742 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | try { |
| 4745 | final Phone phone = getPhone(subId); |
| 4746 | if (phone == null) { |
| 4747 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4748 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4749 | return TelephonyProperties.lte_on_cdma_device() |
| 4750 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4751 | } |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4754 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4757 | /** |
| 4758 | * {@hide} |
| 4759 | * Returns Default subId, 0 in the case of single standby. |
| 4760 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4761 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4762 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4765 | private int getSlotForDefaultSubscription() { |
| 4766 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4767 | } |
| 4768 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4769 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4770 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4771 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4772 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4773 | private boolean isActiveSubscription(int subId) { |
| 4774 | return mSubscriptionController.isActiveSubId(subId); |
| 4775 | } |
| 4776 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4777 | /** |
| 4778 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4779 | */ |
| 4780 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | final long identity = Binder.clearCallingIdentity(); |
| 4782 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4783 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4785 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4786 | } finally { |
| 4787 | Binder.restoreCallingIdentity(identity); |
| 4788 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | /** |
| 4792 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4793 | */ |
| 4794 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4795 | final long identity = Binder.clearCallingIdentity(); |
| 4796 | try { |
| 4797 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4798 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4799 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4800 | } finally { |
| 4801 | Binder.restoreCallingIdentity(identity); |
| 4802 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4803 | } |
| 4804 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4805 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4806 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4807 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4808 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4809 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4810 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4811 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4812 | if (phoneId == -1) { |
| 4813 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4814 | + " does not correspond to an active phone"); |
| 4815 | } |
| 4816 | return PhoneFactory.getPhone(phoneId); |
| 4817 | } |
| 4818 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4819 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4820 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4821 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4823 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4825 | if (DBG) { |
| 4826 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4827 | } |
| 4828 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4829 | p2); |
| 4830 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4831 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4832 | |
| 4833 | @Override |
| 4834 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4835 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4836 | enforceModifyPermission(); |
| 4837 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4838 | if (DBG) { |
| 4839 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4840 | } |
| 4841 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4842 | callingPackage, aid, p2); |
| 4843 | } |
| 4844 | |
| 4845 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4846 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | final long identity = Binder.clearCallingIdentity(); |
| 4848 | try { |
| 4849 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4850 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4851 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4852 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | if (bestComponent == null |
| 4854 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4855 | loge("The calling package is not allowed to access ISD-R."); |
| 4856 | throw new SecurityException( |
| 4857 | "The calling package is not allowed to access ISD-R."); |
| 4858 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4859 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4860 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4862 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4863 | null /* workSource */); |
| 4864 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4865 | return response; |
| 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4872 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4874 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4875 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4876 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4877 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4878 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4879 | @Override |
| 4880 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4881 | enforceModifyPermission(); |
| 4882 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4883 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4884 | channel); |
| 4885 | } |
| 4886 | |
| 4887 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | if (channel < 0) { |
| 4891 | return false; |
| 4892 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4893 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4894 | null /* workSource */); |
| 4895 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | return success; |
| 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4899 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4903 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4904 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4905 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4906 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4907 | if (DBG) { |
| 4908 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4909 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4910 | + p3 + " data=" + data); |
| 4911 | } |
| 4912 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4913 | command, p1, p2, p3, data); |
| 4914 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4915 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4916 | @Override |
| 4917 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4918 | int command, int p1, int p2, int p3, String data) { |
| 4919 | enforceModifyPermission(); |
| 4920 | if (DBG) { |
| 4921 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4922 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4923 | + p3 + " data=" + data); |
| 4924 | } |
| 4925 | return iccTransmitApduLogicalChannelWithPermission( |
| 4926 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4927 | data); |
| 4928 | } |
| 4929 | |
| 4930 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4931 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | final long identity = Binder.clearCallingIdentity(); |
| 4933 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4934 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | return ""; |
| 4936 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4937 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4938 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4939 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4940 | null /* workSource */); |
| 4941 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4942 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | // Append the returned status code to the end of the response payload. |
| 4944 | String s = Integer.toHexString( |
| 4945 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4946 | if (response.payload != null) { |
| 4947 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4948 | } |
| 4949 | return s; |
| 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4952 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4953 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4954 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4955 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4956 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4957 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4959 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4961 | if (DBG) { |
| 4962 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4963 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4964 | } |
| 4965 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4966 | cla, command, p1, p2, p3, data); |
| 4967 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4968 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4969 | @Override |
| 4970 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4971 | int command, int p1, int p2, int p3, String data) { |
| 4972 | enforceModifyPermission(); |
| 4973 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4974 | if (DBG) { |
| 4975 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4976 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4977 | + " data=" + data); |
| 4978 | } |
| 4979 | |
| 4980 | return iccTransmitApduBasicChannelWithPermission( |
| 4981 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4982 | p2, p3, data); |
| 4983 | } |
| 4984 | |
| 4985 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4986 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4987 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
| 4990 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4991 | && TextUtils.equals(ISDR_AID, data)) { |
| 4992 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4993 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4994 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4995 | if (bestComponent == null |
| 4996 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4997 | loge("The calling package is not allowed to select ISD-R."); |
| 4998 | throw new SecurityException( |
| 4999 | "The calling package is not allowed to select ISD-R."); |
| 5000 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5001 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5002 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5003 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5004 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5005 | null /* workSource */); |
| 5006 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5008 | // Append the returned status code to the end of the response payload. |
| 5009 | String s = Integer.toHexString( |
| 5010 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5011 | if (response.payload != null) { |
| 5012 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5013 | } |
| 5014 | return s; |
| 5015 | } finally { |
| 5016 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5017 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5021 | 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] | 5022 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5023 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5024 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5026 | final long identity = Binder.clearCallingIdentity(); |
| 5027 | try { |
| 5028 | if (DBG) { |
| 5029 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5030 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5031 | } |
| 5032 | |
| 5033 | IccIoResult response = |
| 5034 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5035 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5036 | subId); |
| 5037 | |
| 5038 | if (DBG) { |
| 5039 | log("Exchange SIM_IO [R]" + response); |
| 5040 | } |
| 5041 | |
| 5042 | byte[] result = null; |
| 5043 | int length = 2; |
| 5044 | if (response.payload != null) { |
| 5045 | length = 2 + response.payload.length; |
| 5046 | result = new byte[length]; |
| 5047 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5048 | } else { |
| 5049 | result = new byte[length]; |
| 5050 | } |
| 5051 | |
| 5052 | result[length - 1] = (byte) response.sw2; |
| 5053 | result[length - 2] = (byte) response.sw1; |
| 5054 | return result; |
| 5055 | } finally { |
| 5056 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5057 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5058 | } |
| 5059 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5060 | /** |
| 5061 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5062 | * on a particular subscription |
| 5063 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5064 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5065 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5067 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5068 | return null; |
| 5069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5070 | |
| 5071 | final long identity = Binder.clearCallingIdentity(); |
| 5072 | try { |
| 5073 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5074 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5075 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5076 | return null; |
| 5077 | } |
| 5078 | Object response = sendRequest( |
| 5079 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5080 | if (response instanceof String[]) { |
| 5081 | return (String[]) response; |
| 5082 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5083 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5084 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5085 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5086 | } finally { |
| 5087 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5088 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5089 | } |
| 5090 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5091 | /** |
| 5092 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5093 | * subscription. |
| 5094 | * |
| 5095 | * @param subId the id of the subscription. |
| 5096 | * @param appType the uicc app type, must be USIM or SIM. |
| 5097 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5098 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5099 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5100 | * @return number of fplmns that is successfully written to the SIM. |
| 5101 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5102 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5103 | String callingFeatureId) { |
| 5104 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5105 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5106 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5107 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5108 | } |
| 5109 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5110 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5111 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5112 | } |
| 5113 | if (fplmns == null) { |
| 5114 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5115 | } |
| 5116 | for (String fplmn : fplmns) { |
| 5117 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5118 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5119 | } |
| 5120 | } |
| 5121 | final long identity = Binder.clearCallingIdentity(); |
| 5122 | try { |
| 5123 | Object response = sendRequest( |
| 5124 | CMD_SET_FORBIDDEN_PLMNS, |
| 5125 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5126 | subId); |
| 5127 | return (int) response; |
| 5128 | } finally { |
| 5129 | Binder.restoreCallingIdentity(identity); |
| 5130 | } |
| 5131 | } |
| 5132 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5133 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5134 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5135 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5136 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5137 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | final long identity = Binder.clearCallingIdentity(); |
| 5139 | try { |
| 5140 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5141 | if (response.payload == null) { |
| 5142 | return ""; |
| 5143 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5144 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | // Append the returned status code to the end of the response payload. |
| 5146 | String s = Integer.toHexString( |
| 5147 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5148 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5149 | return s; |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
| 5152 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5155 | /** |
| 5156 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5157 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5158 | * |
| 5159 | * @param itemID the ID of the item to read |
| 5160 | * @return the NV item as a String, or null on error. |
| 5161 | */ |
| 5162 | @Override |
| 5163 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5164 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5166 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5167 | |
| 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
| 5170 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5171 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5172 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5173 | return value; |
| 5174 | } finally { |
| 5175 | Binder.restoreCallingIdentity(identity); |
| 5176 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | /** |
| 5180 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5181 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5182 | * |
| 5183 | * @param itemID the ID of the item to read |
| 5184 | * @param itemValue the value to write, as a String |
| 5185 | * @return true on success; false on any failure |
| 5186 | */ |
| 5187 | @Override |
| 5188 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5189 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5191 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | |
| 5193 | final long identity = Binder.clearCallingIdentity(); |
| 5194 | try { |
| 5195 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5196 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5197 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5199 | return success; |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | /** |
| 5206 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5207 | * Used for device configuration by some CDMA operators. |
| 5208 | * |
| 5209 | * @param preferredRoamingList byte array containing the new PRL |
| 5210 | * @return true on success; false on any failure |
| 5211 | */ |
| 5212 | @Override |
| 5213 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5215 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5216 | |
| 5217 | final long identity = Binder.clearCallingIdentity(); |
| 5218 | try { |
| 5219 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5220 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5221 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5222 | return success; |
| 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
| 5225 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5229 | * 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] | 5230 | * Used for device configuration by some CDMA operators. |
| 5231 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5232 | * @param slotIndex - device slot. |
| 5233 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5234 | * @return true on success; false on any failure |
| 5235 | */ |
| 5236 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5237 | public boolean resetModemConfig(int slotIndex) { |
| 5238 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5239 | if (phone != null) { |
| 5240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5241 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5243 | final long identity = Binder.clearCallingIdentity(); |
| 5244 | try { |
| 5245 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5246 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5247 | return success; |
| 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
| 5250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5252 | return false; |
| 5253 | } |
| 5254 | |
| 5255 | /** |
| 5256 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5257 | * |
| 5258 | * @param slotIndex - device slot. |
| 5259 | * |
| 5260 | * @return true on success; false on any failure |
| 5261 | */ |
| 5262 | @Override |
| 5263 | public boolean rebootModem(int slotIndex) { |
| 5264 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5265 | if (phone != null) { |
| 5266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5267 | mApp, phone.getSubId(), "rebootModem"); |
| 5268 | |
| 5269 | final long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5272 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5273 | return success; |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
| 5277 | } |
| 5278 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5279 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5280 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5281 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5282 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5283 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5284 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5285 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5286 | return new String[0]; |
| 5287 | } |
| 5288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | final long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5291 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | } finally { |
| 5293 | Binder.restoreCallingIdentity(identity); |
| 5294 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5295 | } |
| 5296 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5297 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5298 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5299 | * {@link #disableIms(int)}. |
| 5300 | * @param slotIndex device slot. |
| 5301 | */ |
| 5302 | public void resetIms(int slotIndex) { |
| 5303 | enforceModifyPermission(); |
| 5304 | |
| 5305 | final long identity = Binder.clearCallingIdentity(); |
| 5306 | try { |
| 5307 | if (mImsResolver == null) { |
| 5308 | // may happen if the does not support IMS. |
| 5309 | return; |
| 5310 | } |
| 5311 | mImsResolver.disableIms(slotIndex); |
| 5312 | mImsResolver.enableIms(slotIndex); |
| 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
| 5316 | } |
| 5317 | |
| 5318 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5319 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5320 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5321 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5322 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5323 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5324 | |
| 5325 | final long identity = Binder.clearCallingIdentity(); |
| 5326 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5327 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5328 | // may happen if the device does not support IMS. |
| 5329 | return; |
| 5330 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5331 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5338 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5339 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5340 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5341 | public void disableIms(int slotId) { |
| 5342 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5346 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5347 | // may happen if the device does not support IMS. |
| 5348 | return; |
| 5349 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5350 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5357 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5358 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5359 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5360 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5361 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5362 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | |
| 5364 | final long identity = Binder.clearCallingIdentity(); |
| 5365 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5366 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5367 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5368 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5369 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5370 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
| 5373 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5374 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5375 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5376 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5377 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5378 | @Override |
| 5379 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5380 | enforceModifyPermission(); |
| 5381 | |
| 5382 | final long identity = Binder.clearCallingIdentity(); |
| 5383 | try { |
| 5384 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5385 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
| 5389 | } |
| 5390 | |
| 5391 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5392 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5393 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5394 | */ |
| 5395 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5396 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5397 | |
| 5398 | final long identity = Binder.clearCallingIdentity(); |
| 5399 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5400 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5401 | // may happen if the device does not support IMS. |
| 5402 | return null; |
| 5403 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5404 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | } finally { |
| 5406 | Binder.restoreCallingIdentity(identity); |
| 5407 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5408 | } |
| 5409 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5410 | /** |
| 5411 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5412 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5413 | */ |
| 5414 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5415 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | |
| 5417 | final long identity = Binder.clearCallingIdentity(); |
| 5418 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5419 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5420 | // may happen if the device does not support IMS. |
| 5421 | return null; |
| 5422 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5423 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
| 5426 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5427 | } |
| 5428 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5429 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5430 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5431 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5432 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5433 | * @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] | 5434 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5435 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5436 | * @param packageName The name of the package that the current configuration will be replaced |
| 5437 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5438 | * @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] | 5439 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5441 | int[] featureTypes, String packageName) { |
| 5442 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5443 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5444 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5445 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5446 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5447 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5450 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5451 | // may happen if the device does not support IMS. |
| 5452 | return false; |
| 5453 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5454 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5455 | for (int featureType : featureTypes) { |
| 5456 | featureConfig.put(featureType, packageName); |
| 5457 | } |
| 5458 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5459 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5466 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5467 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5468 | * |
| 5469 | * This should only be used for testing. |
| 5470 | * |
| 5471 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5472 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5473 | */ |
| 5474 | @Override |
| 5475 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5476 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5477 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5478 | "clearCarrierImsServiceOverride"); |
| 5479 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5480 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5481 | "clearCarrierImsServiceOverride"); |
| 5482 | |
| 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
| 5485 | if (mImsResolver == null) { |
| 5486 | // may happen if the device does not support IMS. |
| 5487 | return false; |
| 5488 | } |
| 5489 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5490 | } finally { |
| 5491 | Binder.restoreCallingIdentity(identity); |
| 5492 | } |
| 5493 | } |
| 5494 | |
| 5495 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5496 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5497 | * |
| 5498 | * @param slotId The slot that the ImsService is associated with. |
| 5499 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5500 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5501 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5502 | * @return the package name of the ImsService configuration. |
| 5503 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5504 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5505 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5506 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5507 | TelephonyPermissions |
| 5508 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5509 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5510 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | final long identity = Binder.clearCallingIdentity(); |
| 5513 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5514 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5515 | // may happen if the device does not support IMS. |
| 5516 | return ""; |
| 5517 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5518 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5519 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5520 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | } finally { |
| 5522 | Binder.restoreCallingIdentity(identity); |
| 5523 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5524 | } |
| 5525 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5526 | /** |
| 5527 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5528 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5529 | * @param callback A callback with an integer containing the |
| 5530 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5531 | */ |
| 5532 | @Override |
| 5533 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5534 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5535 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5537 | "IMS not available on device."); |
| 5538 | } |
| 5539 | final long token = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | int slotId = getSlotIndex(subId); |
| 5542 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5543 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5544 | + subId + "'"); |
| 5545 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5546 | } |
| 5547 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5548 | try { |
| 5549 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5550 | } catch (RemoteException e) { |
| 5551 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5552 | + "Ignore"); |
| 5553 | } |
| 5554 | }); |
| 5555 | } finally { |
| 5556 | Binder.restoreCallingIdentity(token); |
| 5557 | } |
| 5558 | } |
| 5559 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5560 | /** |
| 5561 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5562 | */ |
| 5563 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5564 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | |
| 5566 | final long identity = Binder.clearCallingIdentity(); |
| 5567 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5568 | // NOTE: Before S, this method only set the default phone. |
| 5569 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5570 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5571 | phone.setImsRegistrationState(registered); |
| 5572 | } |
| 5573 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(identity); |
| 5576 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5577 | } |
| 5578 | |
| 5579 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5580 | * Set the network selection mode to automatic. |
| 5581 | * |
| 5582 | */ |
| 5583 | @Override |
| 5584 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5585 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5586 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | |
| 5588 | final long identity = Binder.clearCallingIdentity(); |
| 5589 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5590 | if (!isActiveSubscription(subId)) { |
| 5591 | return; |
| 5592 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5594 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5600 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5601 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5602 | * |
| 5603 | * @param subId the id of the subscription. |
| 5604 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5605 | * the operator to attach to. |
| 5606 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5607 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5608 | * normal network selection next time. |
| 5609 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5610 | */ |
| 5611 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5612 | public boolean setNetworkSelectionModeManual( |
| 5613 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5615 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5616 | |
| 5617 | if (!isActiveSubscription(subId)) { |
| 5618 | return false; |
| 5619 | } |
| 5620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | final long identity = Binder.clearCallingIdentity(); |
| 5622 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5623 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5625 | if (DBG) { |
| 5626 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5627 | + " operator: " + operatorInfo); |
| 5628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5629 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5633 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5634 | /** |
| 5635 | * Get the manual network selection |
| 5636 | * |
| 5637 | * @param subId the id of the subscription. |
| 5638 | * |
| 5639 | * @return the previously saved user selected PLMN |
| 5640 | */ |
| 5641 | @Override |
| 5642 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5643 | TelephonyPermissions |
| 5644 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5645 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5646 | |
| 5647 | final long identity = Binder.clearCallingIdentity(); |
| 5648 | try { |
| 5649 | if (!isActiveSubscription(subId)) { |
| 5650 | return ""; |
| 5651 | } |
| 5652 | |
| 5653 | final Phone phone = getPhone(subId); |
| 5654 | if (phone == null) { |
| 5655 | return ""; |
| 5656 | } |
| 5657 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5658 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5659 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5660 | } finally { |
| 5661 | Binder.restoreCallingIdentity(identity); |
| 5662 | } |
| 5663 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5664 | |
| 5665 | /** |
| 5666 | * Scans for available networks. |
| 5667 | */ |
| 5668 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5669 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5670 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5671 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5672 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5673 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5674 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5675 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5676 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5677 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5678 | .setCallingPid(Binder.getCallingPid()) |
| 5679 | .setCallingUid(Binder.getCallingUid()) |
| 5680 | .setMethod("getCellNetworkScanResults") |
| 5681 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5682 | .build()); |
| 5683 | switch (locationResult) { |
| 5684 | case DENIED_HARD: |
| 5685 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5686 | case DENIED_SOFT: |
| 5687 | return null; |
| 5688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5689 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5690 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5691 | try { |
| 5692 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5693 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5701 | * Get the call forwarding info, given the call forwarding reason. |
| 5702 | */ |
| 5703 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5704 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5705 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5706 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5707 | long identity = Binder.clearCallingIdentity(); |
| 5708 | try { |
| 5709 | if (DBG) { |
| 5710 | log("getCallForwarding: subId " + subId |
| 5711 | + " callForwardingReason" + callForwardingReason); |
| 5712 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5713 | |
| 5714 | Phone phone = getPhone(subId); |
| 5715 | if (phone == null) { |
| 5716 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5717 | callback.onError( |
| 5718 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5719 | } catch (RemoteException e) { |
| 5720 | // ignore |
| 5721 | } |
| 5722 | return; |
| 5723 | } |
| 5724 | |
| 5725 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5726 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5727 | @Override |
| 5728 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5729 | try { |
| 5730 | callback.onCallForwardingInfoAvailable(info); |
| 5731 | } catch (RemoteException e) { |
| 5732 | // ignore |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | @Override |
| 5737 | public void onError(int error) { |
| 5738 | try { |
| 5739 | callback.onError(error); |
| 5740 | } catch (RemoteException e) { |
| 5741 | // ignore |
| 5742 | } |
| 5743 | } |
| 5744 | }); |
| 5745 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5746 | } finally { |
| 5747 | Binder.restoreCallingIdentity(identity); |
| 5748 | } |
| 5749 | } |
| 5750 | |
| 5751 | /** |
| 5752 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5753 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5754 | */ |
| 5755 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5756 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5757 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5758 | enforceModifyPermission(); |
| 5759 | long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
| 5761 | if (DBG) { |
| 5762 | log("setCallForwarding: subId " + subId |
| 5763 | + " callForwardingInfo" + callForwardingInfo); |
| 5764 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5765 | |
| 5766 | Phone phone = getPhone(subId); |
| 5767 | if (phone == null) { |
| 5768 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5769 | callback.accept( |
| 5770 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5771 | } catch (RemoteException e) { |
| 5772 | // ignore |
| 5773 | } |
| 5774 | return; |
| 5775 | } |
| 5776 | |
| 5777 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5778 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5779 | |
| 5780 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5781 | } finally { |
| 5782 | Binder.restoreCallingIdentity(identity); |
| 5783 | } |
| 5784 | } |
| 5785 | |
| 5786 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5787 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5788 | */ |
| 5789 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5790 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5791 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5792 | long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5794 | |
| 5795 | Phone phone = getPhone(subId); |
| 5796 | if (phone == null) { |
| 5797 | try { |
| 5798 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5799 | } catch (RemoteException e) { |
| 5800 | // ignore |
| 5801 | } |
| 5802 | return; |
| 5803 | } |
| 5804 | |
| 5805 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5806 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5807 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5808 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
| 5812 | } |
| 5813 | |
| 5814 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5815 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5816 | */ |
| 5817 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5818 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5819 | enforceModifyPermission(); |
| 5820 | long identity = Binder.clearCallingIdentity(); |
| 5821 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5822 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5823 | |
| 5824 | Phone phone = getPhone(subId); |
| 5825 | if (phone == null) { |
| 5826 | try { |
| 5827 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5828 | } catch (RemoteException e) { |
| 5829 | // ignore |
| 5830 | } |
| 5831 | return; |
| 5832 | } |
| 5833 | |
| 5834 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5835 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5836 | |
| 5837 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5838 | } finally { |
| 5839 | Binder.restoreCallingIdentity(identity); |
| 5840 | } |
| 5841 | } |
| 5842 | |
| 5843 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5844 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5845 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5846 | * @param subId id of the subscription |
| 5847 | * @param request contains the radio access networks with bands/channels to scan |
| 5848 | * @param messenger callback messenger for scan results or errors |
| 5849 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5850 | * @return the id of the requested scan which can be used to stop the scan. |
| 5851 | */ |
| 5852 | @Override |
| 5853 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5854 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5856 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5857 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5858 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5859 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5860 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5861 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5862 | .setCallingPid(Binder.getCallingPid()) |
| 5863 | .setCallingUid(Binder.getCallingUid()) |
| 5864 | .setMethod("requestNetworkScan") |
| 5865 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5866 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5867 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5868 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5869 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5870 | if (e != null) { |
| 5871 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5872 | throw e; |
| 5873 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5874 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5875 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5876 | } |
| 5877 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5879 | int callingUid = Binder.getCallingUid(); |
| 5880 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
| 5883 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5884 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5885 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(identity); |
| 5888 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5891 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5892 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5893 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5894 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5895 | boolean hasNetworkScanPermission = |
| 5896 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5897 | == PERMISSION_GRANTED; |
| 5898 | |
| 5899 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5900 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5901 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5905 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5906 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5907 | return new SecurityException("Specific channels must not be" |
| 5908 | + " scanned without location access."); |
| 5909 | } |
| 5910 | } |
| 5911 | } |
| 5912 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5913 | return null; |
| 5914 | } |
| 5915 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5916 | /** |
| 5917 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5918 | * |
| 5919 | * @param subId id of the subscription |
| 5920 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5921 | */ |
| 5922 | @Override |
| 5923 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5924 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5925 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5926 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5927 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | final long identity = Binder.clearCallingIdentity(); |
| 5929 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5930 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5931 | } finally { |
| 5932 | Binder.restoreCallingIdentity(identity); |
| 5933 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5937 | * Get the calculated preferred network type. |
| 5938 | * Used for debugging incorrect network type. |
| 5939 | * |
| 5940 | * @return the preferred network type, defined in RILConstants.java. |
| 5941 | */ |
| 5942 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5943 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5944 | final Phone defaultPhone = getDefaultPhone(); |
| 5945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5946 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5947 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5948 | } |
| 5949 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5950 | final long identity = Binder.clearCallingIdentity(); |
| 5951 | try { |
| 5952 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5953 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5957 | } |
| 5958 | |
| 5959 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5960 | * Get the preferred network type. |
| 5961 | * Used for device configuration by some CDMA operators. |
| 5962 | * |
| 5963 | * @return the preferred network type, defined in RILConstants.java. |
| 5964 | */ |
| 5965 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5966 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5967 | TelephonyPermissions |
| 5968 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5969 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | |
| 5971 | final long identity = Binder.clearCallingIdentity(); |
| 5972 | try { |
| 5973 | if (DBG) log("getPreferredNetworkType"); |
| 5974 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5975 | int networkType = (result != null ? result[0] : -1); |
| 5976 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5977 | return networkType; |
| 5978 | } finally { |
| 5979 | Binder.restoreCallingIdentity(identity); |
| 5980 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | /** |
| 5984 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5985 | * |
| 5986 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5987 | * @return true on success; false on any failure. |
| 5988 | */ |
| 5989 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5990 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5991 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5992 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | |
| 5994 | final long identity = Binder.clearCallingIdentity(); |
| 5995 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5996 | Boolean success = (Boolean) sendRequest( |
| 5997 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5998 | |
| 5999 | if (success) { |
| 6000 | Settings.Global.putInt(mApp.getContentResolver(), |
| 6001 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 6002 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6003 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 6004 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 6007 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6008 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6009 | |
| 6010 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6011 | * Get the allowed network types that store in the telephony provider. |
| 6012 | * |
| 6013 | * @param subId the id of the subscription. |
| 6014 | * @return allowedNetworkTypes the allowed network types. |
| 6015 | */ |
| 6016 | @Override |
| 6017 | public long getAllowedNetworkTypes(int subId) { |
| 6018 | TelephonyPermissions |
| 6019 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6020 | mApp, subId, "getAllowedNetworkTypes"); |
| 6021 | |
| 6022 | final long identity = Binder.clearCallingIdentity(); |
| 6023 | try { |
| 6024 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6025 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6026 | } finally { |
| 6027 | Binder.restoreCallingIdentity(identity); |
| 6028 | } |
| 6029 | } |
| 6030 | |
| 6031 | /** |
| 6032 | * Set the allowed network types. |
| 6033 | * |
| 6034 | * @param subId the id of the subscription. |
| 6035 | * @param allowedNetworkTypes the allowed network types. |
| 6036 | * @return true on success; false on any failure. |
| 6037 | */ |
| 6038 | @Override |
| 6039 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6041 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6042 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6043 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6044 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6045 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6046 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6047 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6048 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6049 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6050 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6054 | * Get the allowed network types for certain reason. |
| 6055 | * |
| 6056 | * @param subId the id of the subscription. |
| 6057 | * @param reason the reason the allowed network type change is taking place |
| 6058 | * @return the allowed network types. |
| 6059 | */ |
| 6060 | @Override |
| 6061 | public long getAllowedNetworkTypesForReason(int subId, |
| 6062 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6063 | TelephonyPermissions |
| 6064 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6065 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6066 | final long identity = Binder.clearCallingIdentity(); |
| 6067 | try { |
| 6068 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6069 | } finally { |
| 6070 | Binder.restoreCallingIdentity(identity); |
| 6071 | } |
| 6072 | } |
| 6073 | |
| 6074 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6075 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6076 | * @param subId subscription id of the sim card |
| 6077 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6078 | * This can be passed following states |
| 6079 | * <ol> |
| 6080 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6081 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6082 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6083 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6084 | * </ol> |
| 6085 | * @return operation result. |
| 6086 | */ |
| 6087 | @Override |
| 6088 | public int setNrDualConnectivityState(int subId, |
| 6089 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6090 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6091 | mApp, subId, "enableNRDualConnectivity"); |
| 6092 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6093 | final long identity = Binder.clearCallingIdentity(); |
| 6094 | try { |
| 6095 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6096 | nrDualConnectivityState, subId, |
| 6097 | workSource); |
| 6098 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6099 | return result; |
| 6100 | } finally { |
| 6101 | Binder.restoreCallingIdentity(identity); |
| 6102 | } |
| 6103 | } |
| 6104 | |
| 6105 | /** |
| 6106 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6107 | * @return true if dual connectivity is enabled else false |
| 6108 | */ |
| 6109 | @Override |
| 6110 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6111 | TelephonyPermissions |
| 6112 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6113 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6114 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6115 | final long identity = Binder.clearCallingIdentity(); |
| 6116 | try { |
| 6117 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6118 | null, subId, workSource); |
| 6119 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6120 | return isEnabled; |
| 6121 | } finally { |
| 6122 | Binder.restoreCallingIdentity(identity); |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6127 | * get carrier bandwidth per primary and secondary carrier |
| 6128 | * @param subId subscription id of the sim card |
| 6129 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6130 | */ |
| 6131 | @Override |
| 6132 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6133 | TelephonyPermissions |
| 6134 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6135 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6136 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6137 | final long identity = Binder.clearCallingIdentity(); |
| 6138 | try { |
| 6139 | CarrierBandwidth carrierBandwidth = |
| 6140 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6141 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6142 | return carrierBandwidth; |
| 6143 | } finally { |
| 6144 | Binder.restoreCallingIdentity(identity); |
| 6145 | } |
| 6146 | } |
| 6147 | |
| 6148 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6149 | * Get the effective allowed network types on the device. |
| 6150 | * This API will return an intersection of allowed network types for all reasons, |
| 6151 | * including the configuration done through setAllowedNetworkTypes |
| 6152 | * |
| 6153 | * @param subId the id of the subscription. |
| 6154 | * @return the allowed network types |
| 6155 | */ |
| 6156 | @Override |
| 6157 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6158 | TelephonyPermissions |
| 6159 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6160 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6161 | final long identity = Binder.clearCallingIdentity(); |
| 6162 | try { |
| 6163 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6164 | } finally { |
| 6165 | Binder.restoreCallingIdentity(identity); |
| 6166 | } |
| 6167 | } |
| 6168 | |
| 6169 | /** |
| 6170 | * Set the allowed network types of the device and |
| 6171 | * provide the reason triggering the allowed network change. |
| 6172 | * |
| 6173 | * @param subId the id of the subscription. |
| 6174 | * @param reason the reason the allowed network type change is taking place |
| 6175 | * @param allowedNetworkTypes the allowed network types. |
| 6176 | * @return true on success; false on any failure. |
| 6177 | */ |
| 6178 | @Override |
| 6179 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6180 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6181 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6182 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6183 | final long identity = Binder.clearCallingIdentity(); |
| 6184 | try { |
| 6185 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6186 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6187 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6188 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6189 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6190 | } finally { |
| 6191 | Binder.restoreCallingIdentity(identity); |
| 6192 | } |
| 6193 | } |
| 6194 | |
| 6195 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6196 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6197 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6198 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6199 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6200 | * @hide |
| 6201 | */ |
| 6202 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6203 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6204 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6206 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6207 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6208 | if (phone != null) { |
| 6209 | return phone.hasMatchedTetherApnSetting(); |
| 6210 | } else { |
| 6211 | return false; |
| 6212 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6213 | } finally { |
| 6214 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6215 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6216 | } |
| 6217 | |
| 6218 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6219 | * Enable or disable always reporting signal strength changes from radio. |
| 6220 | * |
| 6221 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6222 | */ |
| 6223 | @Override |
| 6224 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6225 | enforceModifyPermission(); |
| 6226 | enforceSystemCaller(); |
| 6227 | |
| 6228 | final long identity = Binder.clearCallingIdentity(); |
| 6229 | final Phone phone = getPhone(subId); |
| 6230 | try { |
| 6231 | if (phone != null) { |
| 6232 | if (DBG) { |
| 6233 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6234 | + " isEnable=" + isEnable); |
| 6235 | } |
| 6236 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6237 | } else { |
| 6238 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6239 | + subId); |
| 6240 | } |
| 6241 | } finally { |
| 6242 | Binder.restoreCallingIdentity(identity); |
| 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6247 | * Get the user enabled state of Mobile Data. |
| 6248 | * |
| 6249 | * TODO: remove and use isUserDataEnabled. |
| 6250 | * This can't be removed now because some vendor codes |
| 6251 | * calls through ITelephony directly while they should |
| 6252 | * use TelephonyManager. |
| 6253 | * |
| 6254 | * @return true on enabled |
| 6255 | */ |
| 6256 | @Override |
| 6257 | public boolean getDataEnabled(int subId) { |
| 6258 | return isUserDataEnabled(subId); |
| 6259 | } |
| 6260 | |
| 6261 | /** |
| 6262 | * Get whether mobile data is enabled per user setting. |
| 6263 | * |
| 6264 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6265 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6266 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6267 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6268 | * |
| 6269 | * @return {@code true} if data is enabled else {@code false} |
| 6270 | */ |
| 6271 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6272 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6273 | try { |
| 6274 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6275 | null); |
| 6276 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6278 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6279 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | |
| 6281 | final long identity = Binder.clearCallingIdentity(); |
| 6282 | try { |
| 6283 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6284 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6285 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6286 | if (phone != null) { |
| 6287 | boolean retVal = phone.isUserDataEnabled(); |
| 6288 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6289 | return retVal; |
| 6290 | } else { |
| 6291 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6292 | return false; |
| 6293 | } |
| 6294 | } finally { |
| 6295 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6296 | } |
| 6297 | } |
| 6298 | |
| 6299 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6300 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6301 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6302 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6303 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6304 | * @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] | 6305 | */ |
| 6306 | @Override |
| 6307 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6308 | try { |
| 6309 | try { |
| 6310 | mApp.enforceCallingOrSelfPermission( |
| 6311 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6312 | null); |
| 6313 | } catch (Exception e) { |
| 6314 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6315 | "isDataEnabled"); |
| 6316 | } |
| 6317 | } catch (Exception e) { |
| 6318 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6319 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | |
| 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
| 6323 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6324 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6325 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6326 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6327 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6329 | return retVal; |
| 6330 | } else { |
| 6331 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6332 | return false; |
| 6333 | } |
| 6334 | } finally { |
| 6335 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6336 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6337 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6338 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6339 | /** |
| 6340 | * Check if data is enabled for a specific reason |
| 6341 | * @param subId Subscription index |
| 6342 | * @param reason the reason the data enable change is taking place |
| 6343 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6344 | */ |
| 6345 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6346 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6347 | @TelephonyManager.DataEnabledReason int reason) { |
| 6348 | try { |
| 6349 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6350 | null); |
| 6351 | } catch (Exception e) { |
| 6352 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6353 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6354 | } |
| 6355 | |
| 6356 | |
| 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
| 6359 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6360 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6361 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6362 | + " reason=" + reason); |
| 6363 | } |
| 6364 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6365 | if (phone != null) { |
| 6366 | boolean retVal; |
| 6367 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6368 | retVal = phone.isUserDataEnabled(); |
| 6369 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6370 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6371 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6372 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6373 | return retVal; |
| 6374 | } else { |
| 6375 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6376 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6377 | + subId + " retVal=false"); |
| 6378 | } |
| 6379 | return false; |
| 6380 | } |
| 6381 | } finally { |
| 6382 | Binder.restoreCallingIdentity(identity); |
| 6383 | } |
| 6384 | } |
| 6385 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6386 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6387 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6388 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6389 | // Skip the check if it's one of these special uids |
| 6390 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6391 | } |
| 6392 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6393 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6394 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6395 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6396 | || subController == null) return privilegeFromSim; |
| 6397 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6398 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6399 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6400 | |
| 6401 | final long identity = Binder.clearCallingIdentity(); |
| 6402 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6403 | int subId = phone.getSubId(); |
| 6404 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6405 | // A test override is in place for the privileges for this subId, so don't try to |
| 6406 | // read the subscription privileges. |
| 6407 | return privilegeFromSim; |
| 6408 | } |
| 6409 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6410 | SubscriptionManager subManager = (SubscriptionManager) |
| 6411 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6412 | for (String pkg : packages) { |
| 6413 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6414 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6415 | } |
| 6416 | } |
| 6417 | return privilegeFromSim; |
| 6418 | } finally { |
| 6419 | Binder.restoreCallingIdentity(identity); |
| 6420 | } |
| 6421 | } |
| 6422 | |
| 6423 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6424 | String pkgName) { |
| 6425 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6426 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6427 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6428 | || subController == null) return privilegeFromSim; |
| 6429 | |
| 6430 | final long identity = Binder.clearCallingIdentity(); |
| 6431 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6432 | int subId = phone.getSubId(); |
| 6433 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6434 | // A test override is in place for the privileges for this subId, so don't try to |
| 6435 | // read the subscription privileges. |
| 6436 | return privilegeFromSim; |
| 6437 | } |
| 6438 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | SubscriptionManager subManager = (SubscriptionManager) |
| 6440 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6441 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6442 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6443 | } finally { |
| 6444 | Binder.restoreCallingIdentity(identity); |
| 6445 | } |
| 6446 | } |
| 6447 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6448 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6449 | public int getCarrierPrivilegeStatus(int subId) { |
| 6450 | final Phone phone = getPhone(subId); |
| 6451 | if (phone == null) { |
| 6452 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6453 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6454 | } |
| 6455 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6456 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6457 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6458 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6459 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6460 | |
| 6461 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6462 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6463 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6464 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6465 | |
| 6466 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6467 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6468 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6469 | final Phone phone = getPhone(subId); |
| 6470 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6471 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6472 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6473 | } |
| 6474 | UiccProfile profile = |
| 6475 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6476 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6477 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6478 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6479 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6480 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6481 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6482 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6486 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6487 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6488 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6489 | } |
| 6490 | |
| 6491 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6492 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6493 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6494 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6495 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6496 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6497 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6498 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6499 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | @Override |
| 6503 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6504 | if (TextUtils.isEmpty(pkgName)) |
| 6505 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6506 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6507 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6508 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6509 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6510 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6511 | continue; |
| 6512 | } |
| 6513 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6514 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6515 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6516 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6517 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6518 | break; |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6523 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6524 | |
| 6525 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6526 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6527 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6528 | loge("phoneId " + phoneId + " is not valid."); |
| 6529 | return null; |
| 6530 | } |
| 6531 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6532 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6533 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6534 | return null ; |
| 6535 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6536 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6537 | } |
| 6538 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6539 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6540 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6541 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6542 | List<String> privilegedPackages = new ArrayList<>(); |
| 6543 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6544 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6545 | // has UICC in that slot. |
| 6546 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6547 | if (card.hasCarrierPrivilegeRules()) { |
| 6548 | if (packages == null) { |
| 6549 | // Only check packages in user 0 for now |
| 6550 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6551 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6552 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6553 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6554 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6555 | } |
| 6556 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6557 | PackageInfo pkgInfo = packages.get(p); |
| 6558 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6559 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6560 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6561 | privilegedPackages.add(pkgInfo.packageName); |
| 6562 | } |
| 6563 | } |
| 6564 | } |
| 6565 | } |
| 6566 | return privilegedPackages; |
| 6567 | } |
| 6568 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6569 | @Override |
| 6570 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6571 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6572 | |
| 6573 | final long identity = Binder.clearCallingIdentity(); |
| 6574 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6575 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6576 | try { |
| 6577 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6578 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6579 | } |
| 6580 | } finally { |
| 6581 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6582 | } |
| 6583 | return privilegedPackages; |
| 6584 | } |
| 6585 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6586 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6587 | final Phone phone = getPhone(subId); |
| 6588 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6589 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6590 | return null; |
| 6591 | } |
| 6592 | String iccId = card.getIccId(); |
| 6593 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6594 | return null; |
| 6595 | } |
| 6596 | return iccId; |
| 6597 | } |
| 6598 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6599 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6600 | public void setCallComposerStatus(int subId, int status) { |
| 6601 | enforceModifyPermission(); |
| 6602 | |
| 6603 | final long identity = Binder.clearCallingIdentity(); |
| 6604 | try { |
| 6605 | Phone phone = getPhone(subId); |
| 6606 | if (phone != null) { |
| 6607 | Phone defaultPhone = phone.getImsPhone(); |
| 6608 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6609 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6610 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6611 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6612 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6613 | } |
| 6614 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6615 | } catch (ImsException e) { |
| 6616 | throw new ServiceSpecificException(e.getCode()); |
| 6617 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6618 | Binder.restoreCallingIdentity(identity); |
| 6619 | } |
| 6620 | } |
| 6621 | |
| 6622 | @Override |
| 6623 | public int getCallComposerStatus(int subId) { |
| 6624 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6625 | |
| 6626 | final long identity = Binder.clearCallingIdentity(); |
| 6627 | try { |
| 6628 | Phone phone = getPhone(subId); |
| 6629 | if (phone != null) { |
| 6630 | Phone defaultPhone = phone.getImsPhone(); |
| 6631 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6632 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6633 | return imsPhone.getCallComposerStatus(); |
| 6634 | } |
| 6635 | } |
| 6636 | } finally { |
| 6637 | Binder.restoreCallingIdentity(identity); |
| 6638 | } |
| 6639 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6640 | } |
| 6641 | |
| 6642 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6643 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6644 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6645 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6646 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | final long identity = Binder.clearCallingIdentity(); |
| 6649 | try { |
| 6650 | final String iccId = getIccId(subId); |
| 6651 | final Phone phone = getPhone(subId); |
| 6652 | if (phone == null) { |
| 6653 | return false; |
| 6654 | } |
| 6655 | final String subscriberId = phone.getSubscriberId(); |
| 6656 | |
| 6657 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6658 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | + subscriberId + " to " + number); |
| 6660 | } |
| 6661 | |
| 6662 | if (TextUtils.isEmpty(iccId)) { |
| 6663 | return false; |
| 6664 | } |
| 6665 | |
| 6666 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6667 | |
| 6668 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6669 | if (alphaTag == null) { |
| 6670 | editor.remove(alphaTagPrefKey); |
| 6671 | } else { |
| 6672 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6673 | } |
| 6674 | |
| 6675 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6676 | // track all merged IMSIs based on line number |
| 6677 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6678 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6679 | if (number == null) { |
| 6680 | editor.remove(numberPrefKey); |
| 6681 | editor.remove(subscriberPrefKey); |
| 6682 | } else { |
| 6683 | editor.putString(numberPrefKey, number); |
| 6684 | editor.putString(subscriberPrefKey, subscriberId); |
| 6685 | } |
| 6686 | |
| 6687 | editor.commit(); |
| 6688 | return true; |
| 6689 | } finally { |
| 6690 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6691 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6692 | } |
| 6693 | |
| 6694 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6695 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6696 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6697 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6698 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6699 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6700 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6701 | return null; |
| 6702 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6704 | final long identity = Binder.clearCallingIdentity(); |
| 6705 | try { |
| 6706 | String iccId = getIccId(subId); |
| 6707 | if (iccId != null) { |
| 6708 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6709 | if (DBG_MERGE) { |
| 6710 | log("getLine1NumberForDisplay returning " |
| 6711 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6712 | } |
| 6713 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6715 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6716 | return null; |
| 6717 | } finally { |
| 6718 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6719 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6720 | } |
| 6721 | |
| 6722 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6723 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6724 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6725 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6726 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6727 | return null; |
| 6728 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6730 | final long identity = Binder.clearCallingIdentity(); |
| 6731 | try { |
| 6732 | String iccId = getIccId(subId); |
| 6733 | if (iccId != null) { |
| 6734 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6735 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6736 | } |
| 6737 | return null; |
| 6738 | } finally { |
| 6739 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6740 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6741 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6742 | |
| 6743 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6744 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6745 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6746 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6747 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6749 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6750 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6751 | return null; |
| 6752 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6753 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6754 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6755 | // the process, where TelephonyManager was instantiated. |
| 6756 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6757 | final long identity = Binder.clearCallingIdentity(); |
| 6758 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6759 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6761 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6762 | |
| 6763 | // Figure out what subscribers are currently active |
| 6764 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6765 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6766 | // Only consider subs which match the current subId |
| 6767 | // This logic can be simplified. See b/131189269 for progress. |
| 6768 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6769 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | |
| 6772 | // First pass, find a number override for an active subscriber |
| 6773 | String mergeNumber = null; |
| 6774 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6775 | for (String key : prefs.keySet()) { |
| 6776 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6777 | final String subscriberId = (String) prefs.get(key); |
| 6778 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6779 | final String iccId = key.substring( |
| 6780 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6781 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6782 | mergeNumber = (String) prefs.get(numberKey); |
| 6783 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6784 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | + " for active subscriber " + subscriberId); |
| 6786 | } |
| 6787 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6788 | break; |
| 6789 | } |
| 6790 | } |
| 6791 | } |
| 6792 | } |
| 6793 | |
| 6794 | // Shortcut when no active merged subscribers |
| 6795 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6796 | return null; |
| 6797 | } |
| 6798 | |
| 6799 | // Second pass, find all subscribers under that line override |
| 6800 | final ArraySet<String> result = new ArraySet<>(); |
| 6801 | for (String key : prefs.keySet()) { |
| 6802 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6803 | final String number = (String) prefs.get(key); |
| 6804 | if (mergeNumber.equals(number)) { |
| 6805 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6806 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6807 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6808 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6809 | result.add(subscriberId); |
| 6810 | } |
| 6811 | } |
| 6812 | } |
| 6813 | } |
| 6814 | |
| 6815 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6816 | Arrays.sort(resultArray); |
| 6817 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6818 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6819 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6820 | } |
| 6821 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6822 | } finally { |
| 6823 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6824 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6825 | } |
| 6826 | |
| 6827 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6828 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6829 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6830 | |
| 6831 | final long identity = Binder.clearCallingIdentity(); |
| 6832 | try { |
| 6833 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6834 | TelephonyManager.class); |
| 6835 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6836 | if (subscriberId == null) { |
| 6837 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6838 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6839 | + subId); |
| 6840 | } |
| 6841 | return null; |
| 6842 | } |
| 6843 | |
| 6844 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6845 | .getSubscriptionInfo(subId); |
| 6846 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6847 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6848 | if (groupUuid == null) { |
| 6849 | return new String[]{subscriberId}; |
| 6850 | } |
| 6851 | |
| 6852 | // Get all subscriberIds from the group. |
| 6853 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6854 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6855 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6856 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6857 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6858 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6859 | if (subscriberId != null) { |
| 6860 | mergedSubscriberIds.add(subscriberId); |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6865 | } finally { |
| 6866 | Binder.restoreCallingIdentity(identity); |
| 6867 | |
| 6868 | } |
| 6869 | } |
| 6870 | |
| 6871 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6872 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6873 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6874 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6875 | |
| 6876 | final long identity = Binder.clearCallingIdentity(); |
| 6877 | try { |
| 6878 | final Phone phone = getPhone(subId); |
| 6879 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6880 | } finally { |
| 6881 | Binder.restoreCallingIdentity(identity); |
| 6882 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6883 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6884 | |
| 6885 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6886 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6887 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6888 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6889 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6890 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6891 | |
| 6892 | final long identity = Binder.clearCallingIdentity(); |
| 6893 | try { |
| 6894 | final Phone phone = getPhone(subId); |
| 6895 | if (phone == null) { |
| 6896 | return false; |
| 6897 | } |
| 6898 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6899 | cdmaNonRoamingList); |
| 6900 | } finally { |
| 6901 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6902 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6903 | } |
| 6904 | |
| 6905 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6906 | @Deprecated |
| 6907 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6908 | enforceModifyPermission(); |
| 6909 | |
| 6910 | int returnValue = 0; |
| 6911 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6912 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6913 | if(result.exception == null) { |
| 6914 | if (result.result != null) { |
| 6915 | byte[] responseData = (byte[])(result.result); |
| 6916 | if(responseData.length > oemResp.length) { |
| 6917 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6918 | responseData.length + "bytes. Buffer Size is " + |
| 6919 | oemResp.length + "bytes."); |
| 6920 | } |
| 6921 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6922 | returnValue = responseData.length; |
| 6923 | } |
| 6924 | } else { |
| 6925 | CommandException ex = (CommandException) result.exception; |
| 6926 | returnValue = ex.getCommandError().ordinal(); |
| 6927 | if(returnValue > 0) returnValue *= -1; |
| 6928 | } |
| 6929 | } catch (RuntimeException e) { |
| 6930 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6931 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6932 | if(returnValue > 0) returnValue *= -1; |
| 6933 | } |
| 6934 | |
| 6935 | return returnValue; |
| 6936 | } |
| 6937 | |
| 6938 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6939 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6940 | try { |
| 6941 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6942 | } catch (RuntimeException e) { |
| 6943 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6948 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6949 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6950 | try { |
| 6951 | TelephonyPermissions |
| 6952 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6953 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6954 | } catch (SecurityException e) { |
| 6955 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6956 | throw e; |
| 6957 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6958 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6959 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6960 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6961 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6962 | final long identity = Binder.clearCallingIdentity(); |
| 6963 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6964 | TelephonyPermissions |
| 6965 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6966 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6967 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6968 | } finally { |
| 6969 | Binder.restoreCallingIdentity(identity); |
| 6970 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6971 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6972 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6973 | |
| 6974 | @Override |
| 6975 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6976 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6977 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6978 | |
| 6979 | final long identity = Binder.clearCallingIdentity(); |
| 6980 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6981 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6982 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6983 | } finally { |
| 6984 | Binder.restoreCallingIdentity(identity); |
| 6985 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6986 | } |
| 6987 | |
| 6988 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6989 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6990 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6991 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6992 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6993 | return false; |
| 6994 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6995 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | final long identity = Binder.clearCallingIdentity(); |
| 6997 | try { |
| 6998 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6999 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7000 | // In the long run, we may instead need to check if there exists a connection service |
| 7001 | // which can support video calling. |
| 7002 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7003 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7004 | return imsManager.isVtEnabledByPlatform() |
| 7005 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7006 | && imsManager.isVtEnabledByUser(); |
| 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
| 7009 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7010 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7011 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7012 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7013 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7014 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7015 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7016 | mApp, subId, callingPackage, callingFeatureId, |
| 7017 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | return false; |
| 7019 | } |
| 7020 | |
| 7021 | final long identity = Binder.clearCallingIdentity(); |
| 7022 | try { |
| 7023 | CarrierConfigManager configManager = |
| 7024 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7025 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7026 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7027 | } finally { |
| 7028 | Binder.restoreCallingIdentity(identity); |
| 7029 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7030 | } |
| 7031 | |
| 7032 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7033 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7034 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7035 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7036 | return false; |
| 7037 | } |
| 7038 | |
| 7039 | final long identity = Binder.clearCallingIdentity(); |
| 7040 | try { |
| 7041 | CarrierConfigManager configManager = |
| 7042 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7043 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7044 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7045 | } finally { |
| 7046 | Binder.restoreCallingIdentity(identity); |
| 7047 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7048 | } |
| 7049 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7050 | @Override |
| 7051 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7052 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7053 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7054 | } |
| 7055 | |
| 7056 | @Override |
| 7057 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | final long identity = Binder.clearCallingIdentity(); |
| 7059 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7060 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7064 | } |
| 7065 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7066 | /** |
| 7067 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7068 | * support for the feature and device firmware support. |
| 7069 | * |
| 7070 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7071 | */ |
| 7072 | @Override |
| 7073 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7074 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7075 | final Phone phone = getPhone(subscriptionId); |
| 7076 | if (phone == null) { |
| 7077 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7078 | return false; |
| 7079 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7081 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7083 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7084 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7085 | return isCarrierSupported && isDeviceSupported; |
| 7086 | } finally { |
| 7087 | Binder.restoreCallingIdentity(identity); |
| 7088 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7089 | } |
| 7090 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7091 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7092 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7093 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7094 | * 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] | 7095 | */ |
| 7096 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7097 | final long identity = Binder.clearCallingIdentity(); |
| 7098 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7099 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7100 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7101 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7102 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7103 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7104 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | } finally { |
| 7106 | Binder.restoreCallingIdentity(identity); |
| 7107 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7108 | } |
| 7109 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7110 | @Deprecated |
| 7111 | @Override |
| 7112 | public String getDeviceId(String callingPackage) { |
| 7113 | return getDeviceIdWithFeature(callingPackage, null); |
| 7114 | } |
| 7115 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7116 | /** |
| 7117 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7118 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7119 | * |
| 7120 | * <p>Requires Permission: |
| 7121 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7122 | */ |
| 7123 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7124 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7125 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7126 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7127 | return null; |
| 7128 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7129 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7130 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7131 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7132 | return null; |
| 7133 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | |
| 7135 | final long identity = Binder.clearCallingIdentity(); |
| 7136 | try { |
| 7137 | return phone.getDeviceId(); |
| 7138 | } finally { |
| 7139 | Binder.restoreCallingIdentity(identity); |
| 7140 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7141 | } |
| 7142 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7143 | /** |
| 7144 | * {@hide} |
| 7145 | * Returns the IMS Registration Status on a particular subid |
| 7146 | * |
| 7147 | * @param subId |
| 7148 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7149 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7150 | Phone phone = getPhone(subId); |
| 7151 | if (phone != null) { |
| 7152 | return phone.isImsRegistered(); |
| 7153 | } else { |
| 7154 | return false; |
| 7155 | } |
| 7156 | } |
| 7157 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7158 | @Override |
| 7159 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
| 7162 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7166 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7167 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7168 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7169 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7170 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7171 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7172 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7173 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7174 | } |
| 7175 | final long identity = Binder.clearCallingIdentity(); |
| 7176 | try { |
| 7177 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7178 | } finally { |
| 7179 | Binder.restoreCallingIdentity(identity); |
| 7180 | } |
| 7181 | } |
| 7182 | |
| 7183 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7184 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7185 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7186 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7187 | final long identity = Binder.clearCallingIdentity(); |
| 7188 | try { |
| 7189 | Phone phone = getPhone(subscriptionId); |
| 7190 | if (phone == null) { |
| 7191 | return null; |
| 7192 | } |
| 7193 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7194 | } finally { |
| 7195 | Binder.restoreCallingIdentity(identity); |
| 7196 | } |
| 7197 | } |
| 7198 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7199 | /** |
| 7200 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7201 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7202 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | final long identity = Binder.clearCallingIdentity(); |
| 7204 | try { |
| 7205 | Phone phone = getPhone(subId); |
| 7206 | if (phone != null) { |
| 7207 | return phone.isWifiCallingEnabled(); |
| 7208 | } else { |
| 7209 | return false; |
| 7210 | } |
| 7211 | } finally { |
| 7212 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7213 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7214 | } |
| 7215 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7216 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7217 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7218 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7219 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
| 7222 | Phone phone = getPhone(subId); |
| 7223 | if (phone != null) { |
| 7224 | return phone.isVideoEnabled(); |
| 7225 | } else { |
| 7226 | return false; |
| 7227 | } |
| 7228 | } finally { |
| 7229 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7230 | } |
| 7231 | } |
| 7232 | |
| 7233 | /** |
| 7234 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7235 | * defined in {@link ImsRegistrationImplBase}. |
| 7236 | */ |
| 7237 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | final long identity = Binder.clearCallingIdentity(); |
| 7239 | try { |
| 7240 | Phone phone = getPhone(subId); |
| 7241 | if (phone != null) { |
| 7242 | return phone.getImsRegistrationTech(); |
| 7243 | } else { |
| 7244 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7245 | } |
| 7246 | } finally { |
| 7247 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7248 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7249 | } |
| 7250 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7251 | @Override |
| 7252 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7253 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7254 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7255 | return; |
| 7256 | } |
| 7257 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7258 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7259 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7260 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7261 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7262 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7263 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7264 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7265 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7266 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7267 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7268 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7269 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7270 | // There has been issues when Sms raw table somehow stores orphan |
| 7271 | // fragments. They lead to garbled message when new fragments come |
| 7272 | // in and combined with those stale ones. In case this happens again, |
| 7273 | // user can reset all network settings which will clean up this table. |
| 7274 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7275 | // Clean up IMS settings as well here. |
| 7276 | int slotId = getSlotIndex(subId); |
| 7277 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7278 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7279 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7280 | |
| 7281 | // Erase modem config if erase modem on network setting is enabled. |
| 7282 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7283 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7284 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7285 | sendEraseModemConfig(getDefaultPhone()); |
| 7286 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7289 | } |
| 7290 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7291 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7292 | private void cleanUpSmsRawTable(Context context) { |
| 7293 | ContentResolver resolver = context.getContentResolver(); |
| 7294 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7295 | resolver.delete(uri, null, null); |
| 7296 | } |
| 7297 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7298 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7299 | public String getSimLocaleForSubscriber(int subId) { |
| 7300 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7301 | final Phone phone = getPhone(subId); |
| 7302 | if (phone == null) { |
| 7303 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7304 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7306 | final long identity = Binder.clearCallingIdentity(); |
| 7307 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7308 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7309 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7310 | if (info == null) { |
| 7311 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7312 | return null; |
| 7313 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7314 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7315 | // preferences (EF-PL and EF-LI)... |
| 7316 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7317 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7318 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7319 | if (localeFromDefaultSim != null) { |
| 7320 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7321 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7322 | + localeFromDefaultSim); |
| 7323 | return localeFromDefaultSim.toLanguageTag(); |
| 7324 | } else { |
| 7325 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7326 | } |
| 7327 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7329 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7330 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7331 | // the SIM and carrier preferences does not include a country we add the country |
| 7332 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7333 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7334 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7335 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7336 | return mccLocale.toLanguageTag(); |
| 7337 | } |
| 7338 | |
| 7339 | if (DBG) log("No locale found - returning null"); |
| 7340 | return null; |
| 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
| 7343 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7347 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7348 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7349 | } |
| 7350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7351 | /** |
| 7352 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7353 | */ |
| 7354 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7355 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7356 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7357 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7358 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7359 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7360 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7361 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7362 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7363 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7364 | * representing the state of the modem. |
| 7365 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7366 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7367 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7368 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7369 | */ |
| 7370 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7371 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7372 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7373 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7374 | |
| 7375 | final long identity = Binder.clearCallingIdentity(); |
| 7376 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7377 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7380 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7381 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7382 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7383 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7384 | // less than total activity duration. |
| 7385 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7386 | if (info == null) { |
| 7387 | return false; |
| 7388 | } |
| 7389 | int activityDurationMs = |
| 7390 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7391 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7392 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7393 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7394 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7395 | } |
| 7396 | return (info.isValid() |
| 7397 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7398 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7399 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7400 | && (totalTxTimeMs <= activityDurationMs)); |
| 7401 | } |
| 7402 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7403 | /** |
| 7404 | * {@hide} |
| 7405 | * Returns the service state information on specified subscription. |
| 7406 | */ |
| 7407 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7408 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7409 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7411 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7412 | return null; |
| 7413 | } |
| 7414 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7415 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7416 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7417 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7418 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7419 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7420 | .setCallingPid(Binder.getCallingPid()) |
| 7421 | .setCallingUid(Binder.getCallingUid()) |
| 7422 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7423 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7424 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7425 | .build()); |
| 7426 | |
| 7427 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7428 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7429 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7430 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7431 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7432 | .setCallingPid(Binder.getCallingPid()) |
| 7433 | .setCallingUid(Binder.getCallingUid()) |
| 7434 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7435 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7436 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7437 | .build()); |
| 7438 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7439 | boolean hasFinePermission = |
| 7440 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7441 | boolean hasCoarsePermission = |
| 7442 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | final long identity = Binder.clearCallingIdentity(); |
| 7445 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7446 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7447 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7448 | Rlog.d(LOG_TAG, |
| 7449 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7450 | return null; |
| 7451 | } |
| 7452 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | final Phone phone = getPhone(subId); |
| 7454 | if (phone == null) { |
| 7455 | return null; |
| 7456 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7457 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7458 | ServiceState ss = phone.getServiceState(); |
| 7459 | |
| 7460 | // Scrub out the location info in ServiceState depending on what level of access |
| 7461 | // the caller has. |
| 7462 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7463 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7464 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | } finally { |
| 7466 | Binder.restoreCallingIdentity(identity); |
| 7467 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7468 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7469 | |
| 7470 | /** |
| 7471 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7472 | * |
| 7473 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7474 | * voicemail ringtone. |
| 7475 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7476 | * PhoneAccount. |
| 7477 | */ |
| 7478 | @Override |
| 7479 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | final long identity = Binder.clearCallingIdentity(); |
| 7481 | try { |
| 7482 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7483 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7484 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7486 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
| 7490 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7491 | } |
| 7492 | |
| 7493 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7494 | * Sets the per-account voicemail ringtone. |
| 7495 | * |
| 7496 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7497 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7498 | * |
| 7499 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7500 | * voicemail ringtone. |
| 7501 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7502 | * PhoneAccount. |
| 7503 | */ |
| 7504 | @Override |
| 7505 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7506 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7507 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7509 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7510 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7512 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7513 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | |
| 7516 | final long identity = Binder.clearCallingIdentity(); |
| 7517 | try { |
| 7518 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7519 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7520 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | } |
| 7522 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7523 | } finally { |
| 7524 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7525 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7529 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7530 | * |
| 7531 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7532 | * voicemail vibration setting. |
| 7533 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7534 | */ |
| 7535 | @Override |
| 7536 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | final long identity = Binder.clearCallingIdentity(); |
| 7538 | try { |
| 7539 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7540 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7541 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7545 | } finally { |
| 7546 | Binder.restoreCallingIdentity(identity); |
| 7547 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7548 | } |
| 7549 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7550 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7551 | * Sets the per-account voicemail vibration. |
| 7552 | * |
| 7553 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7554 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7555 | * |
| 7556 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7557 | * voicemail vibration setting. |
| 7558 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7559 | * specific PhoneAccount. |
| 7560 | */ |
| 7561 | @Override |
| 7562 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7563 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7564 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7565 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7566 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7567 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7569 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7570 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7571 | } |
| 7572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | final long identity = Binder.clearCallingIdentity(); |
| 7574 | try { |
| 7575 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7576 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7577 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7578 | } |
| 7579 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7580 | } finally { |
| 7581 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7582 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7583 | } |
| 7584 | |
| 7585 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7586 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7587 | * |
| 7588 | * @throws SecurityException if the caller does not have the required permission |
| 7589 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7590 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7591 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7592 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7596 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7597 | * permission. |
| 7598 | * |
| 7599 | * @throws SecurityException if the caller does not have the required permission |
| 7600 | */ |
| 7601 | private void enforceSendSmsPermission() { |
| 7602 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7603 | } |
| 7604 | |
| 7605 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7606 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7607 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7608 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7609 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7610 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | final long identity = Binder.clearCallingIdentity(); |
| 7612 | try { |
| 7613 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7614 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7615 | if (componentName == null) { |
| 7616 | throw new SecurityException( |
| 7617 | "Caller not current active visual voicemail package[null]"); |
| 7618 | } |
| 7619 | String vvmPackage = componentName.getPackageName(); |
| 7620 | if (!callingPackage.equals(vvmPackage)) { |
| 7621 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7622 | + vvmPackage + "]"); |
| 7623 | } |
| 7624 | } finally { |
| 7625 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7626 | } |
| 7627 | } |
| 7628 | |
| 7629 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7630 | * Return the application ID for the app type. |
| 7631 | * |
| 7632 | * @param subId the subscription ID that this request applies to. |
| 7633 | * @param appType the uicc app type. |
| 7634 | * @return Application ID for specificied app type, or null if no uicc. |
| 7635 | */ |
| 7636 | @Override |
| 7637 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7638 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7639 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7640 | |
| 7641 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7642 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7643 | if (phone == null) { |
| 7644 | return null; |
| 7645 | } |
| 7646 | String aid = null; |
| 7647 | try { |
| 7648 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7649 | .getApplicationByType(appType).getAid(); |
| 7650 | } catch (Exception e) { |
| 7651 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7652 | } |
| 7653 | return aid; |
| 7654 | } finally { |
| 7655 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7656 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7659 | /** |
| 7660 | * Return the Electronic Serial Number. |
| 7661 | * |
| 7662 | * @param subId the subscription ID that this request applies to. |
| 7663 | * @return ESN or null if error. |
| 7664 | */ |
| 7665 | @Override |
| 7666 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7667 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7668 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7669 | |
| 7670 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7671 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | if (phone == null) { |
| 7673 | return null; |
| 7674 | } |
| 7675 | String esn = null; |
| 7676 | try { |
| 7677 | esn = phone.getEsn(); |
| 7678 | } catch (Exception e) { |
| 7679 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7680 | } |
| 7681 | return esn; |
| 7682 | } finally { |
| 7683 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7684 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7685 | } |
| 7686 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7687 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7688 | * Return the Preferred Roaming List Version. |
| 7689 | * |
| 7690 | * @param subId the subscription ID that this request applies to. |
| 7691 | * @return PRLVersion or null if error. |
| 7692 | */ |
| 7693 | @Override |
| 7694 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7695 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7696 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7697 | |
| 7698 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7699 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | if (phone == null) { |
| 7701 | return null; |
| 7702 | } |
| 7703 | String cdmaPrlVersion = null; |
| 7704 | try { |
| 7705 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7706 | } catch (Exception e) { |
| 7707 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7708 | } |
| 7709 | return cdmaPrlVersion; |
| 7710 | } finally { |
| 7711 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7712 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7713 | } |
| 7714 | |
| 7715 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7716 | * Get snapshot of Telephony histograms |
| 7717 | * @return List of Telephony histograms |
| 7718 | * @hide |
| 7719 | */ |
| 7720 | @Override |
| 7721 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7723 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | |
| 7725 | final long identity = Binder.clearCallingIdentity(); |
| 7726 | try { |
| 7727 | return RIL.getTelephonyRILTimingHistograms(); |
| 7728 | } finally { |
| 7729 | Binder.restoreCallingIdentity(identity); |
| 7730 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7731 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7732 | |
| 7733 | /** |
| 7734 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7735 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7736 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7737 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7738 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7739 | * @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] | 7740 | */ |
| 7741 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7742 | @TelephonyManager.SetCarrierRestrictionResult |
| 7743 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7744 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7745 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7746 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7747 | if (carrierRestrictionRules == null) { |
| 7748 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7749 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7750 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | final long identity = Binder.clearCallingIdentity(); |
| 7752 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7753 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7754 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7755 | } finally { |
| 7756 | Binder.restoreCallingIdentity(identity); |
| 7757 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7758 | } |
| 7759 | |
| 7760 | /** |
| 7761 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7762 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7763 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7764 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7765 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7766 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7767 | */ |
| 7768 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7769 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7770 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7771 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | |
| 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7775 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7776 | if (response instanceof CarrierRestrictionRules) { |
| 7777 | return (CarrierRestrictionRules) response; |
| 7778 | } |
| 7779 | // Response is an Exception of some kind, |
| 7780 | // which is signalled to the user as a NULL retval |
| 7781 | return null; |
| 7782 | } catch (Exception e) { |
| 7783 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7784 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | } finally { |
| 7786 | Binder.restoreCallingIdentity(identity); |
| 7787 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7788 | } |
| 7789 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7790 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7791 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7792 | * @param subId the subscription ID that this action applies to. |
| 7793 | * @param enabled control enable or disable radio. |
| 7794 | * {@hide} |
| 7795 | */ |
| 7796 | @Override |
| 7797 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7798 | enforceModifyPermission(); |
| 7799 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | |
| 7801 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7802 | if (phone == null) { |
| 7803 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7804 | return; |
| 7805 | } |
| 7806 | try { |
| 7807 | phone.carrierActionSetRadioEnabled(enabled); |
| 7808 | } catch (Exception e) { |
| 7809 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 | } finally { |
| 7811 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7812 | } |
| 7813 | } |
| 7814 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7815 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7816 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7817 | * network status based on which carrier apps could apply actions accordingly, |
| 7818 | * enable/disable default url handler for example. |
| 7819 | * |
| 7820 | * @param subId the subscription ID that this action applies to. |
| 7821 | * @param report control start/stop reporting the default network status. |
| 7822 | * {@hide} |
| 7823 | */ |
| 7824 | @Override |
| 7825 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7826 | enforceModifyPermission(); |
| 7827 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7828 | |
| 7829 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7830 | if (phone == null) { |
| 7831 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7832 | return; |
| 7833 | } |
| 7834 | try { |
| 7835 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7836 | } catch (Exception e) { |
| 7837 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7838 | } finally { |
| 7839 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7840 | } |
| 7841 | } |
| 7842 | |
| 7843 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7844 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7845 | * @param subId the subscription ID that this action applies to. |
| 7846 | * {@hide} |
| 7847 | */ |
| 7848 | @Override |
| 7849 | public void carrierActionResetAll(int subId) { |
| 7850 | enforceModifyPermission(); |
| 7851 | final Phone phone = getPhone(subId); |
| 7852 | if (phone == null) { |
| 7853 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7854 | return; |
| 7855 | } |
| 7856 | try { |
| 7857 | phone.carrierActionResetAll(); |
| 7858 | } catch (Exception e) { |
| 7859 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7860 | } |
| 7861 | } |
| 7862 | |
| 7863 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7864 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7865 | * bug report is being generated. |
| 7866 | */ |
| 7867 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7868 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7869 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7870 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7871 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7872 | + Binder.getCallingPid() |
| 7873 | + ", uid=" + Binder.getCallingUid() |
| 7874 | + "without permission " |
| 7875 | + android.Manifest.permission.DUMP); |
| 7876 | return; |
| 7877 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7878 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7879 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7880 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7881 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7882 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7883 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7884 | @NonNull String[] args) { |
| 7885 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7886 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7887 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7888 | } |
| 7889 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7890 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7891 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7892 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7893 | * @param reason the reason the data enable change is taking place |
| 7894 | * @param enabled True if enabling the data, otherwise disabling. |
| 7895 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7896 | */ |
| 7897 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7898 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7899 | boolean enabled) { |
| 7900 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7901 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7902 | try { |
| 7903 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7904 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7905 | } catch (SecurityException se) { |
| 7906 | enforceModifyPermission(); |
| 7907 | } |
| 7908 | } else { |
| 7909 | enforceModifyPermission(); |
| 7910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7911 | |
| 7912 | final long identity = Binder.clearCallingIdentity(); |
| 7913 | try { |
| 7914 | Phone phone = getPhone(subId); |
| 7915 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7916 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7917 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7918 | } else { |
| 7919 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7920 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7921 | } |
| 7922 | } finally { |
| 7923 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7924 | } |
| 7925 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7926 | |
| 7927 | /** |
| 7928 | * Get Client request stats |
| 7929 | * @return List of Client Request Stats |
| 7930 | * @hide |
| 7931 | */ |
| 7932 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7933 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7934 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7936 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7937 | return null; |
| 7938 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7939 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7941 | final long identity = Binder.clearCallingIdentity(); |
| 7942 | try { |
| 7943 | if (phone != null) { |
| 7944 | return phone.getClientRequestStats(); |
| 7945 | } |
| 7946 | |
| 7947 | return null; |
| 7948 | } finally { |
| 7949 | Binder.restoreCallingIdentity(identity); |
| 7950 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7951 | } |
| 7952 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7953 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7954 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7955 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7956 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7957 | |
| 7958 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7959 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7960 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7961 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7962 | * @param state State of SIM (power down, power up, pass through) |
| 7963 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7964 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7965 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7966 | * |
| 7967 | **/ |
| 7968 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7969 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7970 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7971 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7972 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7973 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7975 | final long identity = Binder.clearCallingIdentity(); |
| 7976 | try { |
| 7977 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7978 | phone.setSimPowerState(state, null, workSource); |
| 7979 | } |
| 7980 | } finally { |
| 7981 | Binder.restoreCallingIdentity(identity); |
| 7982 | } |
| 7983 | } |
| 7984 | |
| 7985 | /** |
| 7986 | * Set SIM card power state. |
| 7987 | * |
| 7988 | * @param slotIndex SIM slot id. |
| 7989 | * @param state State of SIM (power down, power up, pass through) |
| 7990 | * @param callback callback to trigger after success or failure |
| 7991 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7992 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7993 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7994 | * |
| 7995 | **/ |
| 7996 | @Override |
| 7997 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7998 | IIntegerConsumer callback) { |
| 7999 | enforceModifyPermission(); |
| 8000 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8001 | |
| 8002 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8003 | |
| 8004 | final long identity = Binder.clearCallingIdentity(); |
| 8005 | try { |
| 8006 | if (phone != null) { |
| 8007 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8008 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8009 | } |
| 8010 | } finally { |
| 8011 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8012 | } |
| 8013 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8014 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8015 | private boolean isUssdApiAllowed(int subId) { |
| 8016 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8017 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8018 | if (configManager == null) { |
| 8019 | return false; |
| 8020 | } |
| 8021 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8022 | if (pb == null) { |
| 8023 | return false; |
| 8024 | } |
| 8025 | return pb.getBoolean( |
| 8026 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8027 | } |
| 8028 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8029 | /** |
| 8030 | * Check if phone is in emergency callback mode |
| 8031 | * @return true if phone is in emergency callback mode |
| 8032 | * @param subId sub id |
| 8033 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8034 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8035 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8036 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8037 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8038 | |
| 8039 | final long identity = Binder.clearCallingIdentity(); |
| 8040 | try { |
| 8041 | if (phone != null) { |
| 8042 | return phone.isInEcm(); |
| 8043 | } else { |
| 8044 | return false; |
| 8045 | } |
| 8046 | } finally { |
| 8047 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8048 | } |
| 8049 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8050 | |
| 8051 | /** |
| 8052 | * Get the current signal strength information for the given subscription. |
| 8053 | * Because this information is not updated when the device is in a low power state |
| 8054 | * it should not be relied-upon to be current. |
| 8055 | * @param subId Subscription index |
| 8056 | * @return the most recent cached signal strength info from the modem |
| 8057 | */ |
| 8058 | @Override |
| 8059 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8060 | final long identity = Binder.clearCallingIdentity(); |
| 8061 | try { |
| 8062 | Phone p = getPhone(subId); |
| 8063 | if (p == null) { |
| 8064 | return null; |
| 8065 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8066 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8067 | return p.getSignalStrength(); |
| 8068 | } finally { |
| 8069 | Binder.restoreCallingIdentity(identity); |
| 8070 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8071 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8072 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8073 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8074 | * Get the current modem radio state for the given slot. |
| 8075 | * @param slotIndex slot index. |
| 8076 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8077 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8078 | * @return the current radio power state from the modem |
| 8079 | */ |
| 8080 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8081 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8082 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8083 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8084 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8085 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8086 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8087 | } |
| 8088 | |
| 8089 | final long identity = Binder.clearCallingIdentity(); |
| 8090 | try { |
| 8091 | return phone.getRadioPowerState(); |
| 8092 | } finally { |
| 8093 | Binder.restoreCallingIdentity(identity); |
| 8094 | } |
| 8095 | } |
| 8096 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8097 | } |
| 8098 | |
| 8099 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8100 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8101 | * |
| 8102 | * <p>Requires one of the following permissions: |
| 8103 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8104 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8105 | * privileges. |
| 8106 | * |
| 8107 | * @param subId subscription id |
| 8108 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8109 | * {@code false}. |
| 8110 | */ |
| 8111 | @Override |
| 8112 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8113 | try { |
| 8114 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8115 | null); |
| 8116 | } catch (Exception e) { |
| 8117 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8118 | mApp, subId, "isDataRoamingEnabled"); |
| 8119 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8120 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8121 | boolean isEnabled = false; |
| 8122 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8123 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8124 | Phone phone = getPhone(subId); |
| 8125 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8126 | } finally { |
| 8127 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8128 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8129 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8130 | } |
| 8131 | |
| 8132 | |
| 8133 | /** |
| 8134 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8135 | * |
| 8136 | * <p> Requires permission: |
| 8137 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8138 | * privileges. |
| 8139 | * |
| 8140 | * @param subId subscription id |
| 8141 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8142 | */ |
| 8143 | @Override |
| 8144 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8146 | mApp, subId, "setDataRoamingEnabled"); |
| 8147 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8148 | final long identity = Binder.clearCallingIdentity(); |
| 8149 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8150 | Phone phone = getPhone(subId); |
| 8151 | if (phone != null) { |
| 8152 | phone.setDataRoamingEnabled(isEnabled); |
| 8153 | } |
| 8154 | } finally { |
| 8155 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8156 | } |
| 8157 | } |
| 8158 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8159 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8160 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8161 | TelephonyPermissions |
| 8162 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8163 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8164 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8165 | boolean isAllowed = true; |
| 8166 | final long identity = Binder.clearCallingIdentity(); |
| 8167 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8168 | Phone phone = getPhone(subId); |
| 8169 | if (phone != null) { |
| 8170 | isAllowed = phone.isCspPlmnEnabled(); |
| 8171 | } |
| 8172 | } finally { |
| 8173 | Binder.restoreCallingIdentity(identity); |
| 8174 | } |
| 8175 | return isAllowed; |
| 8176 | } |
| 8177 | |
| 8178 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8179 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8180 | // Verify that tha callingPackage belongs to the calling UID |
| 8181 | mApp.getSystemService(AppOpsManager.class) |
| 8182 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8183 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8184 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8185 | try { |
| 8186 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8187 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8188 | } catch (SecurityException e) { |
| 8189 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8190 | // has carrier privileges on an active UICC |
| 8191 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8192 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8193 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8194 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8195 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8196 | |
| 8197 | final long identity = Binder.clearCallingIdentity(); |
| 8198 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8199 | UiccController uiccController = UiccController.getInstance(); |
| 8200 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8201 | if (hasReadPermission) { |
| 8202 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8203 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8204 | |
| 8205 | // Remove private info if the caller doesn't have access |
| 8206 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8207 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8208 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8209 | // is available |
| 8210 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8211 | if (card == null || card.getUiccProfile() == null) { |
| 8212 | // assume no access if the card or profile is unavailable |
| 8213 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8214 | continue; |
| 8215 | } |
| 8216 | UiccProfile profile = card.getUiccProfile(); |
| 8217 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8218 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8219 | filteredInfos.add(cardInfo); |
| 8220 | } else { |
| 8221 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8222 | } |
| 8223 | } |
| 8224 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8225 | } finally { |
| 8226 | Binder.restoreCallingIdentity(identity); |
| 8227 | } |
| 8228 | } |
| 8229 | |
| 8230 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8231 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8232 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8233 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8234 | final long identity = Binder.clearCallingIdentity(); |
| 8235 | try { |
| 8236 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8237 | if (slots == null) { |
| 8238 | Rlog.i(LOG_TAG, "slots is null."); |
| 8239 | return null; |
| 8240 | } |
| 8241 | |
| 8242 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8243 | for (int i = 0; i < slots.length; i++) { |
| 8244 | UiccSlot slot = slots[i]; |
| 8245 | if (slot == null) { |
| 8246 | continue; |
| 8247 | } |
| 8248 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8249 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8250 | UiccCard card = slot.getUiccCard(); |
| 8251 | if (card != null) { |
| 8252 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8253 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8254 | cardId = slot.getEid(); |
| 8255 | if (TextUtils.isEmpty(cardId)) { |
| 8256 | cardId = slot.getIccId(); |
| 8257 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8258 | } |
| 8259 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8260 | if (cardId != null) { |
| 8261 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8262 | // if cardId is an EID, it's all digits so this is fine |
| 8263 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8264 | } |
| 8265 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8266 | int cardState = 0; |
| 8267 | switch (slot.getCardState()) { |
| 8268 | case CARDSTATE_ABSENT: |
| 8269 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8270 | break; |
| 8271 | case CARDSTATE_PRESENT: |
| 8272 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8273 | break; |
| 8274 | case CARDSTATE_ERROR: |
| 8275 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8276 | break; |
| 8277 | case CARDSTATE_RESTRICTED: |
| 8278 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8279 | break; |
| 8280 | default: |
| 8281 | break; |
| 8282 | |
| 8283 | } |
| 8284 | |
| 8285 | infos[i] = new UiccSlotInfo( |
| 8286 | slot.isActive(), |
| 8287 | slot.isEuicc(), |
| 8288 | cardId, |
| 8289 | cardState, |
| 8290 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8291 | slot.isExtendedApduSupported(), |
| 8292 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | } |
| 8294 | return infos; |
| 8295 | } finally { |
| 8296 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8297 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8298 | } |
| 8299 | |
| 8300 | @Override |
| 8301 | public boolean switchSlots(int[] physicalSlots) { |
| 8302 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8303 | |
| 8304 | final long identity = Binder.clearCallingIdentity(); |
| 8305 | try { |
| 8306 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8307 | } finally { |
| 8308 | Binder.restoreCallingIdentity(identity); |
| 8309 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8310 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8311 | |
| 8312 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8313 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8314 | final long identity = Binder.clearCallingIdentity(); |
| 8315 | try { |
| 8316 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | } |
| 8320 | } |
| 8321 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8322 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8323 | * A test API to reload the UICC profile. |
| 8324 | * |
| 8325 | * <p>Requires that the calling app has permission |
| 8326 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8327 | * @hide |
| 8328 | */ |
| 8329 | @Override |
| 8330 | public void refreshUiccProfile(int subId) { |
| 8331 | enforceModifyPermission(); |
| 8332 | |
| 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
| 8335 | Phone phone = getPhone(subId); |
| 8336 | if (phone == null) { |
| 8337 | return; |
| 8338 | } |
| 8339 | UiccCard uiccCard = phone.getUiccCard(); |
| 8340 | if (uiccCard == null) { |
| 8341 | return; |
| 8342 | } |
| 8343 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8344 | if (uiccProfile == null) { |
| 8345 | return; |
| 8346 | } |
| 8347 | uiccProfile.refresh(); |
| 8348 | } finally { |
| 8349 | Binder.restoreCallingIdentity(identity); |
| 8350 | } |
| 8351 | } |
| 8352 | |
| 8353 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8354 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8355 | */ |
| 8356 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8357 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8358 | } |
| 8359 | |
| 8360 | /** |
| 8361 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8362 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8363 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8364 | */ |
| 8365 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8366 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8367 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8368 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8369 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8370 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8371 | return isDataRoamingEnabled; |
| 8372 | } |
| 8373 | |
| 8374 | /** |
| 8375 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8376 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8377 | */ |
| 8378 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8379 | List<Integer> list = TelephonyProperties.default_network(); |
| 8380 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8381 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8382 | return list.get(phoneId); |
| 8383 | } |
| 8384 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8385 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8386 | |
| 8387 | @Override |
| 8388 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8389 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8390 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | |
| 8392 | final long identity = Binder.clearCallingIdentity(); |
| 8393 | try { |
| 8394 | final Phone phone = getPhone(subId); |
| 8395 | if (phone == null) { |
| 8396 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8397 | return; |
| 8398 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8399 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8400 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8401 | if (carrierPrivilegeRules == null) { |
| 8402 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8403 | } else { |
| 8404 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8406 | } finally { |
| 8407 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8408 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8409 | } |
| 8410 | |
| 8411 | @Override |
| 8412 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8413 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8414 | |
| 8415 | final long identity = Binder.clearCallingIdentity(); |
| 8416 | try { |
| 8417 | final Phone phone = getPhone(subId); |
| 8418 | if (phone == null) { |
| 8419 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8420 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8421 | } |
| 8422 | return phone.getCarrierIdListVersion(); |
| 8423 | } finally { |
| 8424 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8425 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8426 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8427 | |
| 8428 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8429 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8430 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8431 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8432 | mApp, subId, callingPackage, callingFeatureId, |
| 8433 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8434 | return -1; |
| 8435 | } |
| 8436 | |
| 8437 | final long identity = Binder.clearCallingIdentity(); |
| 8438 | try { |
| 8439 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8440 | } finally { |
| 8441 | Binder.restoreCallingIdentity(identity); |
| 8442 | } |
| 8443 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8444 | |
| 8445 | @Override |
| 8446 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8447 | TelephonyPermissions |
| 8448 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8449 | mApp, subId, "getCdmaRoamingMode"); |
| 8450 | |
| 8451 | final long identity = Binder.clearCallingIdentity(); |
| 8452 | try { |
| 8453 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8454 | } finally { |
| 8455 | Binder.restoreCallingIdentity(identity); |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | @Override |
| 8460 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8462 | mApp, subId, "setCdmaRoamingMode"); |
| 8463 | |
| 8464 | final long identity = Binder.clearCallingIdentity(); |
| 8465 | try { |
| 8466 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8467 | } finally { |
| 8468 | Binder.restoreCallingIdentity(identity); |
| 8469 | } |
| 8470 | } |
| 8471 | |
| 8472 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8473 | public int getCdmaSubscriptionMode(int subId) { |
| 8474 | TelephonyPermissions |
| 8475 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8476 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8477 | |
| 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
| 8483 | } |
| 8484 | } |
| 8485 | |
| 8486 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8487 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8489 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8490 | |
| 8491 | final long identity = Binder.clearCallingIdentity(); |
| 8492 | try { |
| 8493 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8494 | } finally { |
| 8495 | Binder.restoreCallingIdentity(identity); |
| 8496 | } |
| 8497 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8498 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8499 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8500 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8501 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8503 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8504 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8505 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8506 | } |
| 8507 | final long identity = Binder.clearCallingIdentity(); |
| 8508 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8509 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8510 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8511 | if (phone.getEmergencyNumberTracker() != null |
| 8512 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8513 | emergencyNumberListInternal.put( |
| 8514 | phone.getSubId(), |
| 8515 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8516 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8517 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8518 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8519 | } finally { |
| 8520 | Binder.restoreCallingIdentity(identity); |
| 8521 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
| 8524 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8525 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8526 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8527 | if (!exactMatch) { |
| 8528 | TelephonyPermissions |
| 8529 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8530 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8531 | } |
| 8532 | final long identity = Binder.clearCallingIdentity(); |
| 8533 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8534 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8535 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8536 | && phone.getEmergencyNumberTracker() |
| 8537 | .isEmergencyNumber(number, exactMatch)) { |
| 8538 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8539 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8540 | } |
| 8541 | return false; |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
| 8545 | } |
| 8546 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8547 | /** |
| 8548 | * Update emergency number list for test mode. |
| 8549 | */ |
| 8550 | @Override |
| 8551 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8552 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8553 | "updateEmergencyNumberListTestMode"); |
| 8554 | |
| 8555 | final long identity = Binder.clearCallingIdentity(); |
| 8556 | try { |
| 8557 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8558 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8559 | if (tracker != null) { |
| 8560 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8561 | } |
| 8562 | } |
| 8563 | } finally { |
| 8564 | Binder.restoreCallingIdentity(identity); |
| 8565 | } |
| 8566 | } |
| 8567 | |
| 8568 | /** |
| 8569 | * Get the full emergency number list for test mode. |
| 8570 | */ |
| 8571 | @Override |
| 8572 | public List<String> getEmergencyNumberListTestMode() { |
| 8573 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8574 | "getEmergencyNumberListTestMode"); |
| 8575 | |
| 8576 | final long identity = Binder.clearCallingIdentity(); |
| 8577 | try { |
| 8578 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8579 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8580 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8581 | if (tracker != null) { |
| 8582 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8583 | emergencyNumbers.add(num.getNumber()); |
| 8584 | } |
| 8585 | } |
| 8586 | } |
| 8587 | return new ArrayList<>(emergencyNumbers); |
| 8588 | } finally { |
| 8589 | Binder.restoreCallingIdentity(identity); |
| 8590 | } |
| 8591 | } |
| 8592 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8593 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8594 | public int getEmergencyNumberDbVersion(int subId) { |
| 8595 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8596 | |
| 8597 | final long identity = Binder.clearCallingIdentity(); |
| 8598 | try { |
| 8599 | final Phone phone = getPhone(subId); |
| 8600 | if (phone == null) { |
| 8601 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8602 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8603 | } |
| 8604 | return phone.getEmergencyNumberDbVersion(); |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
| 8608 | } |
| 8609 | |
| 8610 | @Override |
| 8611 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8612 | enforceModifyPermission(); |
| 8613 | |
| 8614 | final long identity = Binder.clearCallingIdentity(); |
| 8615 | try { |
| 8616 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8617 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8618 | if (tracker != null) { |
| 8619 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8620 | } |
| 8621 | } |
| 8622 | } finally { |
| 8623 | Binder.restoreCallingIdentity(identity); |
| 8624 | } |
| 8625 | } |
| 8626 | |
| 8627 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8628 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8629 | enforceActiveEmergencySessionPermission(); |
| 8630 | |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
| 8633 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8634 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8635 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8636 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8637 | } |
| 8638 | } |
| 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | @Override |
| 8645 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8646 | enforceActiveEmergencySessionPermission(); |
| 8647 | |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8651 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8652 | if (tracker != null) { |
| 8653 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8654 | } |
| 8655 | } |
| 8656 | } finally { |
| 8657 | Binder.restoreCallingIdentity(identity); |
| 8658 | } |
| 8659 | } |
| 8660 | |
| 8661 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8662 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8663 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8664 | Phone phone = getPhone(subId); |
| 8665 | if (phone == null) { |
| 8666 | return null; |
| 8667 | } |
| 8668 | final long identity = Binder.clearCallingIdentity(); |
| 8669 | try { |
| 8670 | UiccProfile profile = UiccController.getInstance() |
| 8671 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8672 | if (profile != null) { |
| 8673 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8674 | } |
| 8675 | } finally { |
| 8676 | Binder.restoreCallingIdentity(identity); |
| 8677 | } |
| 8678 | return null; |
| 8679 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8680 | |
| 8681 | /** |
| 8682 | * Enable or disable a modem stack. |
| 8683 | */ |
| 8684 | @Override |
| 8685 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8686 | enforceModifyPermission(); |
| 8687 | |
| 8688 | final long identity = Binder.clearCallingIdentity(); |
| 8689 | try { |
| 8690 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8691 | if (phone == null) { |
| 8692 | return false; |
| 8693 | } else { |
| 8694 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8695 | } |
| 8696 | } finally { |
| 8697 | Binder.restoreCallingIdentity(identity); |
| 8698 | } |
| 8699 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8700 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8701 | /** |
| 8702 | * Whether a modem stack is enabled or not. |
| 8703 | */ |
| 8704 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8705 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8706 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8707 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8708 | if (phone == null) return false; |
| 8709 | |
| 8710 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8711 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8712 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8713 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8714 | } |
| 8715 | |
| 8716 | final long identity = Binder.clearCallingIdentity(); |
| 8717 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8718 | try { |
| 8719 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8720 | } catch (NoSuchElementException ex) { |
| 8721 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8722 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8723 | } finally { |
| 8724 | Binder.restoreCallingIdentity(identity); |
| 8725 | } |
| 8726 | } |
| 8727 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8728 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8729 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8730 | enforceModifyPermission(); |
| 8731 | |
| 8732 | final long identity = Binder.clearCallingIdentity(); |
| 8733 | try { |
| 8734 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8735 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8736 | .commit(); |
| 8737 | } finally { |
| 8738 | Binder.restoreCallingIdentity(identity); |
| 8739 | } |
| 8740 | } |
| 8741 | |
| 8742 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8743 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8744 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8745 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8746 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8747 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8748 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8749 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8750 | |
| 8751 | final long identity = Binder.clearCallingIdentity(); |
| 8752 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8753 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8754 | } finally { |
| 8755 | Binder.restoreCallingIdentity(identity); |
| 8756 | } |
| 8757 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8758 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8759 | @TelephonyManager.IsMultiSimSupportedResult |
| 8760 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8761 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8762 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8763 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8764 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8765 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8766 | } |
| 8767 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8768 | // supported by the modem, indicate that it is restricted. |
| 8769 | PhoneCapability staticCapability = |
| 8770 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8771 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8772 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8773 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8774 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8775 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8776 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8777 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8778 | } |
| 8779 | // Check if support of multiple SIMs is restricted by carrier |
| 8780 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8781 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8782 | } |
| 8783 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8784 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8785 | } |
| 8786 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8787 | /** |
| 8788 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8789 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8790 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8791 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8792 | * @param numOfSims number of active sims we want to switch to |
| 8793 | */ |
| 8794 | @Override |
| 8795 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8796 | if (numOfSims == 1) { |
| 8797 | enforceModifyPermission(); |
| 8798 | } else { |
| 8799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8800 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8801 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8802 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8803 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8804 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8805 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8806 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8807 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8808 | return; |
| 8809 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8810 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8811 | } finally { |
| 8812 | Binder.restoreCallingIdentity(identity); |
| 8813 | } |
| 8814 | } |
| 8815 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8816 | @Override |
| 8817 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8818 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8819 | Phone phone = getPhone(subId); |
| 8820 | if (phone == null) { |
| 8821 | return false; |
| 8822 | } |
| 8823 | final long identity = Binder.clearCallingIdentity(); |
| 8824 | try { |
| 8825 | UiccCard uiccCard = phone.getUiccCard(); |
| 8826 | if (uiccCard == null) { |
| 8827 | return false; |
| 8828 | } |
| 8829 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8830 | if (uiccProfile == null) { |
| 8831 | return false; |
| 8832 | } |
| 8833 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8834 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8835 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8836 | } |
| 8837 | return false; |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
| 8840 | } |
| 8841 | } |
| 8842 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8843 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8844 | * Get whether making changes to modem configurations will trigger reboot. |
| 8845 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8846 | */ |
| 8847 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8848 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8849 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8850 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8851 | mApp, subId, callingPackage, callingFeatureId, |
| 8852 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8853 | return false; |
| 8854 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8855 | final long identity = Binder.clearCallingIdentity(); |
| 8856 | try { |
| 8857 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8858 | } finally { |
| 8859 | Binder.restoreCallingIdentity(identity); |
| 8860 | } |
| 8861 | } |
| 8862 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8863 | private void updateModemStateMetrics() { |
| 8864 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8865 | // TODO: check the state for each modem if the api is ready. |
| 8866 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8867 | } |
| 8868 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8869 | @Override |
| 8870 | public int[] getSlotsMapping() { |
| 8871 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8872 | |
| 8873 | final long identity = Binder.clearCallingIdentity(); |
| 8874 | try { |
| 8875 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8876 | // All logical slots should have a mapping to a physical slot. |
| 8877 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8878 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8879 | for (int i = 0; i < slotInfos.length; i++) { |
| 8880 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8881 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8882 | } |
| 8883 | } |
| 8884 | return logicalSlotsMapping; |
| 8885 | } finally { |
| 8886 | Binder.restoreCallingIdentity(identity); |
| 8887 | } |
| 8888 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8889 | |
| 8890 | /** |
| 8891 | * Get the IRadio HAL Version |
| 8892 | */ |
| 8893 | @Override |
| 8894 | public int getRadioHalVersion() { |
| 8895 | Phone phone = getDefaultPhone(); |
| 8896 | if (phone == null) return -1; |
| 8897 | HalVersion hv = phone.getHalVersion(); |
| 8898 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8899 | return hv.major * 100 + hv.minor; |
| 8900 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8901 | |
| 8902 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8903 | * Get the current calling package name. |
| 8904 | * @return the current calling package name |
| 8905 | */ |
| 8906 | @Override |
| 8907 | public String getCurrentPackageName() { |
| 8908 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8909 | } |
| 8910 | |
| 8911 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8912 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8913 | * corresponding network requests on a subId. |
| 8914 | * |
| 8915 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8916 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8917 | * 2) APN is un-metered for this subscription, or |
| 8918 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8919 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8920 | * |
| 8921 | * @return whether data is allowed for a apn type. |
| 8922 | * |
| 8923 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8924 | */ |
| 8925 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8926 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8927 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8928 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8929 | |
| 8930 | // Now that all security checks passes, perform the operation as ourselves. |
| 8931 | final long identity = Binder.clearCallingIdentity(); |
| 8932 | try { |
| 8933 | Phone phone = getPhone(subId); |
| 8934 | if (phone == null) return false; |
| 8935 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8936 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8937 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8938 | } finally { |
| 8939 | Binder.restoreCallingIdentity(identity); |
| 8940 | } |
| 8941 | } |
| 8942 | |
| 8943 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8944 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8945 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8946 | |
| 8947 | // Now that all security checks passes, perform the operation as ourselves. |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | Phone phone = getPhone(subId); |
| 8951 | if (phone == null) return true; // By default return true. |
| 8952 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8953 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8954 | } finally { |
| 8955 | Binder.restoreCallingIdentity(identity); |
| 8956 | } |
| 8957 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8958 | |
| 8959 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8960 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8961 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8962 | enforceModifyPermission(); |
| 8963 | long token = Binder.clearCallingIdentity(); |
| 8964 | try { |
| 8965 | Phone phone = getPhone(subscriptionId); |
| 8966 | if (phone == null) { |
| 8967 | try { |
| 8968 | if (resultCallback != null) { |
| 8969 | resultCallback.accept(false); |
| 8970 | } |
| 8971 | } catch (RemoteException e) { |
| 8972 | // ignore |
| 8973 | } |
| 8974 | return; |
| 8975 | } |
| 8976 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8977 | Pair.create(specifiers, (x) -> { |
| 8978 | try { |
| 8979 | if (resultCallback != null) { |
| 8980 | resultCallback.accept(x); |
| 8981 | } |
| 8982 | } catch (RemoteException e) { |
| 8983 | // ignore |
| 8984 | } |
| 8985 | }); |
| 8986 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8987 | } finally { |
| 8988 | Binder.restoreCallingIdentity(token); |
| 8989 | } |
| 8990 | } |
| 8991 | |
| 8992 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8993 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8994 | TelephonyPermissions |
| 8995 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8996 | mApp, subId, "getSystemSelectionChannels"); |
| 8997 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8998 | final long identity = Binder.clearCallingIdentity(); |
| 8999 | try { |
| 9000 | List<RadioAccessSpecifier> specifiers = |
| 9001 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9002 | null, subId, workSource); |
| 9003 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9004 | return specifiers; |
| 9005 | } finally { |
| 9006 | Binder.restoreCallingIdentity(identity); |
| 9007 | } |
| 9008 | } |
| 9009 | |
| 9010 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9011 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9012 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9013 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9014 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9015 | if (iccRecords == null) { |
| 9016 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9017 | return false; |
| 9018 | } |
| 9019 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9020 | } |
| 9021 | |
| 9022 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9023 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9024 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9025 | if (callingPackage == null) { |
| 9026 | callingPackage = getCurrentPackageName(); |
| 9027 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9028 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9029 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9030 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9031 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9032 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9033 | } |
| 9034 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9035 | Intent intent = new Intent(); |
| 9036 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9037 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9038 | // Bring up choose default SMS subscription dialog right now |
| 9039 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9040 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9041 | mApp.startActivity(intent); |
| 9042 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9043 | |
| 9044 | @Override |
| 9045 | public String getMmsUAProfUrl(int subId) { |
| 9046 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9047 | final long identity = Binder.clearCallingIdentity(); |
| 9048 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9049 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9050 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9051 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9052 | return carrierUAProfUrl; |
| 9053 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9054 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9055 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9056 | } finally { |
| 9057 | Binder.restoreCallingIdentity(identity); |
| 9058 | } |
| 9059 | } |
| 9060 | |
| 9061 | @Override |
| 9062 | public String getMmsUserAgent(int subId) { |
| 9063 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9064 | final long identity = Binder.clearCallingIdentity(); |
| 9065 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9066 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9067 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9068 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9069 | return carrierUserAgent; |
| 9070 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9071 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9072 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9073 | } finally { |
| 9074 | Binder.restoreCallingIdentity(identity); |
| 9075 | } |
| 9076 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9077 | |
| 9078 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9079 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9080 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9081 | |
| 9082 | final long identity = Binder.clearCallingIdentity(); |
| 9083 | try { |
| 9084 | Phone phone = getPhone(subscriptionId); |
| 9085 | if (phone == null) return false; |
| 9086 | |
| 9087 | switch (policy) { |
| 9088 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9089 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9090 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9091 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9092 | default: |
| 9093 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9094 | } |
| 9095 | } finally { |
| 9096 | Binder.restoreCallingIdentity(identity); |
| 9097 | } |
| 9098 | } |
| 9099 | |
| 9100 | @Override |
| 9101 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9102 | boolean enabled) { |
| 9103 | enforceModifyPermission(); |
| 9104 | |
| 9105 | final long identity = Binder.clearCallingIdentity(); |
| 9106 | try { |
| 9107 | Phone phone = getPhone(subscriptionId); |
| 9108 | if (phone == null) return; |
| 9109 | |
| 9110 | switch (policy) { |
| 9111 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9112 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9113 | break; |
| 9114 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9115 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9116 | break; |
| 9117 | default: |
| 9118 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9119 | } |
| 9120 | } finally { |
| 9121 | Binder.restoreCallingIdentity(identity); |
| 9122 | } |
| 9123 | } |
| 9124 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9125 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9126 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9127 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9128 | * otherwise. |
| 9129 | */ |
| 9130 | @Override |
| 9131 | public void setCepEnabled(boolean isCepEnabled) { |
| 9132 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9133 | |
| 9134 | final long identity = Binder.clearCallingIdentity(); |
| 9135 | try { |
| 9136 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9137 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9138 | Phone defaultPhone = phone.getImsPhone(); |
| 9139 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9140 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9141 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9142 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9143 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9144 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9145 | + imsPhone.getMsisdn()); |
| 9146 | } |
| 9147 | } |
| 9148 | } finally { |
| 9149 | Binder.restoreCallingIdentity(identity); |
| 9150 | } |
| 9151 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9152 | |
| 9153 | /** |
| 9154 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9155 | * |
| 9156 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9157 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9158 | * before being read. |
| 9159 | */ |
| 9160 | @Override |
| 9161 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9162 | isCompressed) { |
| 9163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9164 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9165 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9166 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9167 | } |
| 9168 | if (!isImsAvailableOnDevice()) { |
| 9169 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9170 | "IMS not available on device."); |
| 9171 | } |
| 9172 | |
| 9173 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9174 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9175 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9176 | } finally { |
| 9177 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9178 | } |
| 9179 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9180 | |
| 9181 | @Override |
| 9182 | public boolean isIccLockEnabled(int subId) { |
| 9183 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9184 | |
| 9185 | // Now that all security checks passes, perform the operation as ourselves. |
| 9186 | final long identity = Binder.clearCallingIdentity(); |
| 9187 | try { |
| 9188 | Phone phone = getPhone(subId); |
| 9189 | if (phone != null && phone.getIccCard() != null) { |
| 9190 | return phone.getIccCard().getIccLockEnabled(); |
| 9191 | } else { |
| 9192 | return false; |
| 9193 | } |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
| 9197 | } |
| 9198 | |
| 9199 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9200 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9201 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9202 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9203 | * three cases: |
| 9204 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9205 | * successfully. |
| 9206 | * - Positive number and zero for remaining password attempts. |
| 9207 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9208 | * |
| 9209 | */ |
| 9210 | @Override |
| 9211 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9212 | enforceModifyPermission(); |
| 9213 | |
| 9214 | Phone phone = getPhone(subId); |
| 9215 | if (phone == null) { |
| 9216 | return 0; |
| 9217 | } |
| 9218 | // Now that all security checks passes, perform the operation as ourselves. |
| 9219 | final long identity = Binder.clearCallingIdentity(); |
| 9220 | try { |
| 9221 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9222 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9223 | return attemptsRemaining; |
| 9224 | |
| 9225 | } catch (Exception e) { |
| 9226 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9227 | } finally { |
| 9228 | Binder.restoreCallingIdentity(identity); |
| 9229 | } |
| 9230 | return 0; |
| 9231 | } |
| 9232 | |
| 9233 | /** |
| 9234 | * Change the ICC password used in ICC pin lock. |
| 9235 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9236 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9237 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9238 | * - Positive number and zero for remaining password attempts. |
| 9239 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9240 | * |
| 9241 | */ |
| 9242 | @Override |
| 9243 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9244 | enforceModifyPermission(); |
| 9245 | |
| 9246 | Phone phone = getPhone(subId); |
| 9247 | if (phone == null) { |
| 9248 | return 0; |
| 9249 | } |
| 9250 | // Now that all security checks passes, perform the operation as ourselves. |
| 9251 | final long identity = Binder.clearCallingIdentity(); |
| 9252 | try { |
| 9253 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9254 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9255 | return attemptsRemaining; |
| 9256 | |
| 9257 | } catch (Exception e) { |
| 9258 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9259 | } finally { |
| 9260 | Binder.restoreCallingIdentity(identity); |
| 9261 | } |
| 9262 | return 0; |
| 9263 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9264 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9265 | /** |
| 9266 | * Request for receiving user activity notification |
| 9267 | */ |
| 9268 | @Override |
| 9269 | public void requestUserActivityNotification() { |
| 9270 | if (!mNotifyUserActivity.get() |
| 9271 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9272 | mNotifyUserActivity.set(true); |
| 9273 | } |
| 9274 | } |
| 9275 | |
| 9276 | /** |
| 9277 | * Called when userActivity is signalled in the power manager. |
| 9278 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9279 | */ |
| 9280 | @Override |
| 9281 | public void userActivity() { |
| 9282 | // *************************************** |
| 9283 | // * Inherited from PhoneWindowManager * |
| 9284 | // *************************************** |
| 9285 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9286 | // WITH ITS LOCKS HELD. |
| 9287 | // |
| 9288 | // This code must be VERY careful about the locks |
| 9289 | // it acquires. |
| 9290 | // In fact, the current code acquires way too many, |
| 9291 | // and probably has lurking deadlocks. |
| 9292 | |
| 9293 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9294 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9295 | } |
| 9296 | |
| 9297 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9298 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9299 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9300 | } |
| 9301 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9302 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9303 | @Override |
| 9304 | public boolean canConnectTo5GInDsdsMode() { |
| 9305 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9306 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9307 | |
| 9308 | @Override |
| 9309 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9310 | String callingFeatureId) { |
| 9311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9312 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9313 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9314 | } |
| 9315 | |
| 9316 | Phone phone = getPhone(subId); |
| 9317 | if (phone == null) { |
| 9318 | throw new RuntimeException("phone is not available"); |
| 9319 | } |
| 9320 | // Now that all security checks passes, perform the operation as ourselves. |
| 9321 | final long identity = Binder.clearCallingIdentity(); |
| 9322 | try { |
| 9323 | return phone.getEquivalentHomePlmns(); |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9328 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9329 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9330 | public boolean isRadioInterfaceCapabilitySupported( |
| 9331 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9332 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9333 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9334 | if (radioInterfaceCapabilities == null) { |
| 9335 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9336 | } else { |
| 9337 | return radioInterfaceCapabilities.isSupported(capability); |
| 9338 | } |
| 9339 | } |
| 9340 | |
| 9341 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9342 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9343 | UaSecurityProtocolIdentifier securityProtocol, |
| 9344 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9345 | throws RemoteException { |
| 9346 | enforceModifyPermission(); |
| 9347 | if (DBG) { |
| 9348 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9349 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9350 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9351 | } |
| 9352 | |
| 9353 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9354 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9355 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9356 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9357 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9358 | if (callback != null) { |
| 9359 | try { |
| 9360 | callback.onAuthenticationFailure( |
| 9361 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9362 | } catch (RemoteException exception) { |
| 9363 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9364 | } |
| 9365 | return; |
| 9366 | } |
| 9367 | } |
| 9368 | |
| 9369 | final long token = Binder.clearCallingIdentity(); |
| 9370 | try { |
| 9371 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9372 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9373 | forceBootStrapping, callback)); |
| 9374 | } finally { |
| 9375 | Binder.restoreCallingIdentity(token); |
| 9376 | } |
| 9377 | } |
| 9378 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9379 | /** |
| 9380 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9381 | * requested radio power state will actually be set. See {@link |
| 9382 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9383 | * |
| 9384 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9385 | * @param enable {@code true} if trying to turn radio on. |
| 9386 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9387 | * false}. |
| 9388 | */ |
| 9389 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9390 | Phone phone = getPhone(subId); |
| 9391 | if (phone != null) { |
| 9392 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9393 | return true; |
| 9394 | } |
| 9395 | return false; |
| 9396 | } |
| 9397 | |
| 9398 | private int handleDataThrottlingRequest(int subId, |
| 9399 | DataThrottlingRequest dataThrottlingRequest) { |
| 9400 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9401 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9402 | if (!setRadioPowerForThermal(subId, true)) { |
| 9403 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9404 | } |
| 9405 | |
| 9406 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9407 | |
| 9408 | int thermalMitigationResult = |
| 9409 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9410 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9411 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9412 | } |
| 9413 | return thermalMitigationResult; |
| 9414 | } |
| 9415 | |
| 9416 | /** |
| 9417 | * Thermal mitigation request to control functionalities at modem. |
| 9418 | * |
| 9419 | * @param subId the id of the subscription. |
| 9420 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9421 | * |
| 9422 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9423 | */ |
| 9424 | @Override |
| 9425 | @ThermalMitigationResult |
| 9426 | public int sendThermalMitigationRequest( |
| 9427 | int subId, |
| 9428 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9429 | enforceModifyPermission(); |
| 9430 | |
| 9431 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9432 | final long identity = Binder.clearCallingIdentity(); |
| 9433 | |
| 9434 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9435 | try { |
| 9436 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9437 | switch (thermalMitigationAction) { |
| 9438 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9439 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9440 | handleDataThrottlingRequest(subId, |
| 9441 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9442 | break; |
| 9443 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9444 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9445 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9446 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9447 | } |
| 9448 | |
| 9449 | // Ensure that radio is on. If not able to power on due to phone being |
| 9450 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9451 | if (!setRadioPowerForThermal(subId, true)) { |
| 9452 | thermalMitigationResult = |
| 9453 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9454 | break; |
| 9455 | } |
| 9456 | |
| 9457 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9458 | false); |
| 9459 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9460 | break; |
| 9461 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9462 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9463 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9464 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9465 | } |
| 9466 | |
| 9467 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9468 | if (registry != null) { |
| 9469 | TelephonyConnectionService service = |
| 9470 | registry.getTelephonyConnectionService(); |
| 9471 | Phone phone = getPhone(subId); |
| 9472 | if (phone == null) { |
| 9473 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9474 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9475 | break; |
| 9476 | } |
| 9477 | |
| 9478 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9479 | != TelephonyManager.CALL_STATE_IDLE |
| 9480 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9481 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9482 | String errorMessage = "Phone state is not valid. call state = " |
| 9483 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9484 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9485 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9486 | errorMessage += service == null |
| 9487 | ? " TelephonyConnectionService is null" |
| 9488 | : " isEmergencyCallPending = " |
| 9489 | + service.isEmergencyCallPending(); |
| 9490 | Log.e(LOG_TAG, errorMessage); |
| 9491 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9492 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9493 | break; |
| 9494 | } |
| 9495 | } else { |
| 9496 | thermalMitigationResult = |
| 9497 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9498 | break; |
| 9499 | } |
| 9500 | |
| 9501 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9502 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9503 | if (!setRadioPowerForThermal(subId, false)) { |
| 9504 | thermalMitigationResult = |
| 9505 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9506 | break; |
| 9507 | } |
| 9508 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9509 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9510 | break; |
| 9511 | default: |
| 9512 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9513 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9514 | } |
| 9515 | } catch (IllegalArgumentException e) { |
| 9516 | throw e; |
| 9517 | } catch (Exception e) { |
| 9518 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9519 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9520 | } finally { |
| 9521 | Binder.restoreCallingIdentity(identity); |
| 9522 | } |
| 9523 | |
| 9524 | if (DBG) { |
| 9525 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9526 | + thermalMitigationResult); |
| 9527 | } |
| 9528 | |
| 9529 | return thermalMitigationResult; |
| 9530 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9531 | |
| 9532 | /** |
| 9533 | * Set the GbaService Package Name that Telephony will bind to. |
| 9534 | * |
| 9535 | * @param subId The sim that the GbaService is associated with. |
| 9536 | * @param packageName The name of the package to be replaced with. |
| 9537 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9538 | */ |
| 9539 | @Override |
| 9540 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9541 | enforceModifyPermission(); |
| 9542 | |
| 9543 | final long identity = Binder.clearCallingIdentity(); |
| 9544 | try { |
| 9545 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9546 | } finally { |
| 9547 | Binder.restoreCallingIdentity(identity); |
| 9548 | } |
| 9549 | } |
| 9550 | |
| 9551 | /** |
| 9552 | * Return the package name of the currently bound GbaService. |
| 9553 | * |
| 9554 | * @param subId The sim that the GbaService is associated with. |
| 9555 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9556 | */ |
| 9557 | @Override |
| 9558 | public String getBoundGbaService(int subId) { |
| 9559 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9560 | |
| 9561 | final long identity = Binder.clearCallingIdentity(); |
| 9562 | try { |
| 9563 | return getGbaManager(subId).getServicePackage(); |
| 9564 | } finally { |
| 9565 | Binder.restoreCallingIdentity(identity); |
| 9566 | } |
| 9567 | } |
| 9568 | |
| 9569 | /** |
| 9570 | * Set the release time for telephony to unbind GbaService. |
| 9571 | * |
| 9572 | * @param subId The sim that the GbaService is associated with. |
| 9573 | * @param interval The release time to unbind GbaService by millisecond. |
| 9574 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9575 | */ |
| 9576 | @Override |
| 9577 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9578 | enforceModifyPermission(); |
| 9579 | |
| 9580 | final long identity = Binder.clearCallingIdentity(); |
| 9581 | try { |
| 9582 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9583 | } finally { |
| 9584 | Binder.restoreCallingIdentity(identity); |
| 9585 | } |
| 9586 | } |
| 9587 | |
| 9588 | /** |
| 9589 | * Return the release time for telephony to unbind GbaService. |
| 9590 | * |
| 9591 | * @param subId The sim that the GbaService is associated with. |
| 9592 | * @return The release time to unbind GbaService by millisecond. |
| 9593 | */ |
| 9594 | @Override |
| 9595 | public int getGbaReleaseTime(int subId) { |
| 9596 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9597 | |
| 9598 | final long identity = Binder.clearCallingIdentity(); |
| 9599 | try { |
| 9600 | return getGbaManager(subId).getReleaseTime(); |
| 9601 | } finally { |
| 9602 | Binder.restoreCallingIdentity(identity); |
| 9603 | } |
| 9604 | } |
| 9605 | |
| 9606 | private GbaManager getGbaManager(int subId) { |
| 9607 | GbaManager instance = GbaManager.getInstance(subId); |
| 9608 | if (instance == null) { |
| 9609 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9610 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9611 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9612 | } |
| 9613 | return instance; |
| 9614 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9615 | |
| 9616 | /** |
| 9617 | * indicate whether the device and the carrier can support |
| 9618 | * RCS VoLTE single registration. |
| 9619 | */ |
| 9620 | @Override |
| 9621 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9622 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9623 | |
| 9624 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9625 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9626 | } |
| 9627 | |
| 9628 | final long identity = Binder.clearCallingIdentity(); |
| 9629 | try { |
| 9630 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9631 | if (rpm != null) { |
| 9632 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9633 | } |
| 9634 | return false; |
| 9635 | } finally { |
| 9636 | Binder.restoreCallingIdentity(identity); |
| 9637 | } |
| 9638 | } |
| 9639 | |
| 9640 | /** |
| 9641 | * Register RCS provisioning callback. |
| 9642 | */ |
| 9643 | @Override |
| 9644 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9645 | IRcsConfigCallback callback) { |
| 9646 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9647 | |
| 9648 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9649 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9650 | } |
| 9651 | if (!isImsAvailableOnDevice()) { |
| 9652 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9653 | "IMS not available on device."); |
| 9654 | } |
| 9655 | |
| 9656 | final long identity = Binder.clearCallingIdentity(); |
| 9657 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9658 | if (!RcsProvisioningMonitor.getInstance() |
| 9659 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9660 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9661 | "Service not available for the subscription."); |
| 9662 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9663 | } finally { |
| 9664 | Binder.restoreCallingIdentity(identity); |
| 9665 | } |
| 9666 | } |
| 9667 | |
| 9668 | /** |
| 9669 | * Unregister RCS provisioning callback. |
| 9670 | */ |
| 9671 | @Override |
| 9672 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9673 | IRcsConfigCallback callback) { |
| 9674 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9675 | |
| 9676 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9677 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9678 | } |
| 9679 | if (!isImsAvailableOnDevice()) { |
| 9680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9681 | "IMS not available on device."); |
| 9682 | } |
| 9683 | |
| 9684 | final long identity = Binder.clearCallingIdentity(); |
| 9685 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9686 | RcsProvisioningMonitor.getInstance() |
| 9687 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9688 | } finally { |
| 9689 | Binder.restoreCallingIdentity(identity); |
| 9690 | } |
| 9691 | } |
| 9692 | |
| 9693 | /** |
| 9694 | * trigger RCS reconfiguration. |
| 9695 | */ |
| 9696 | public void triggerRcsReconfiguration(int subId) { |
| 9697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9698 | mApp, subId, "triggerRcsReconfiguration"); |
| 9699 | |
| 9700 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9701 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9702 | } |
| 9703 | if (!isImsAvailableOnDevice()) { |
| 9704 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9705 | "IMS not available on device."); |
| 9706 | } |
| 9707 | |
| 9708 | final long identity = Binder.clearCallingIdentity(); |
| 9709 | try { |
| 9710 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9711 | } finally { |
| 9712 | Binder.restoreCallingIdentity(identity); |
| 9713 | } |
| 9714 | } |
| 9715 | |
| 9716 | /** |
| 9717 | * Provide the client configuration parameters of the RCS application. |
| 9718 | */ |
| 9719 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9721 | mApp, subId, "setRcsClientConfiguration"); |
| 9722 | |
| 9723 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9724 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9725 | } |
| 9726 | if (!isImsAvailableOnDevice()) { |
| 9727 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9728 | "IMS not available on device."); |
| 9729 | } |
| 9730 | |
| 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | |
| 9733 | try { |
| 9734 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9735 | if (configBinder == null) { |
| 9736 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9737 | } else { |
| 9738 | configBinder.setRcsClientConfiguration(rcc); |
| 9739 | } |
| 9740 | } catch (RemoteException e) { |
| 9741 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9742 | } finally { |
| 9743 | Binder.restoreCallingIdentity(identity); |
| 9744 | } |
| 9745 | } |
| 9746 | |
| 9747 | /** |
| 9748 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9749 | */ |
| 9750 | @Override |
| 9751 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9752 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9753 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9754 | enforceModifyPermission(); |
| 9755 | |
| 9756 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9757 | : Boolean.parseBoolean(enabledStr); |
| 9758 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9759 | } |
| 9760 | |
| 9761 | /** |
| 9762 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9763 | */ |
| 9764 | @Override |
| 9765 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9766 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9767 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9768 | } |
| 9769 | |
| 9770 | /** |
| 9771 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9772 | */ |
| 9773 | @Override |
| 9774 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9775 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9776 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9777 | enforceModifyPermission(); |
| 9778 | |
| 9779 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9780 | : Boolean.parseBoolean(enabledStr); |
| 9781 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9782 | subId, enabled); |
| 9783 | } |
| 9784 | |
| 9785 | /** |
| 9786 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9787 | */ |
| 9788 | @Override |
| 9789 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9790 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9791 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9792 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9793 | |
| 9794 | /** |
| 9795 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9796 | * their mobile plan. |
| 9797 | */ |
| 9798 | @Override |
| 9799 | public String getMobileProvisioningUrl() { |
| 9800 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9801 | final long identity = Binder.clearCallingIdentity(); |
| 9802 | try { |
| 9803 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9804 | } finally { |
| 9805 | Binder.restoreCallingIdentity(identity); |
| 9806 | } |
| 9807 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9808 | |
| 9809 | @Override |
| 9810 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9811 | String callingPackage) { |
| 9812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9813 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9814 | |
| 9815 | final int callingUid = Binder.getCallingUid(); |
| 9816 | // Verify that tha callingPackage belongs to the calling UID |
| 9817 | mApp.getSystemService(AppOpsManager.class) |
| 9818 | .checkPackage(callingUid, callingPackage); |
| 9819 | |
| 9820 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9821 | |
| 9822 | final long identity = Binder.clearCallingIdentity(); |
| 9823 | try { |
| 9824 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9825 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9826 | |
| 9827 | if (result instanceof IllegalStateException) { |
| 9828 | throw (IllegalStateException) result; |
| 9829 | } |
| 9830 | } finally { |
| 9831 | Binder.restoreCallingIdentity(identity); |
| 9832 | } |
| 9833 | } |
| 9834 | |
| 9835 | @Override |
| 9836 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9837 | String callingPackage) { |
| 9838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9839 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9840 | |
| 9841 | final int callingUid = Binder.getCallingUid(); |
| 9842 | // Verify that tha callingPackage belongs to the calling UID |
| 9843 | mApp.getSystemService(AppOpsManager.class) |
| 9844 | .checkPackage(callingUid, callingPackage); |
| 9845 | |
| 9846 | final long identity = Binder.clearCallingIdentity(); |
| 9847 | try { |
| 9848 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9849 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9850 | |
| 9851 | if (result instanceof IllegalStateException) { |
| 9852 | throw (IllegalStateException) result; |
| 9853 | } |
| 9854 | } finally { |
| 9855 | Binder.restoreCallingIdentity(identity); |
| 9856 | } |
| 9857 | } |
| 9858 | |
| 9859 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9860 | int callingUid) { |
| 9861 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9862 | // phone/system process do not have further restriction on request |
| 9863 | return; |
| 9864 | } |
| 9865 | |
| 9866 | // Applications has restrictions on how to use the request: |
| 9867 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9868 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9869 | // This is not system caller which has been checked above |
| 9870 | throw new IllegalArgumentException( |
| 9871 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9872 | } |
| 9873 | |
| 9874 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9875 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9876 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9877 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9878 | || info.isEnabled()) { |
| 9879 | throw new IllegalArgumentException( |
| 9880 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9881 | } |
| 9882 | |
| 9883 | // Thresholds length for each RAN need in range. This has been validated in |
| 9884 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9885 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9886 | final int[] thresholds = info.getThresholds(); |
| 9887 | Objects.requireNonNull(thresholds); |
| 9888 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9889 | || thresholds.length |
| 9890 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9891 | throw new IllegalArgumentException( |
| 9892 | "thresholds length is out of range: " + thresholds.length); |
| 9893 | } |
| 9894 | } |
| 9895 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9896 | } |