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; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame^] | 133 | import com.android.ims.rcs.uce.eab.EabUtil; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 173 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 187 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 189 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 191 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 194 | import com.android.services.telephony.TelecomAccountRegistry; |
| 195 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 196 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 197 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 198 | import java.io.FileDescriptor; |
| 199 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 202 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 203 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 204 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 205 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 207 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 208 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 210 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 211 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Implementation of the ITelephony interface. |
| 215 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 216 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 218 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 219 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 220 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | |
| 222 | // Message codes used with mMainThreadHandler |
| 223 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 224 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 225 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | private static final int CMD_OPEN_CHANNEL = 9; |
| 227 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 228 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 229 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 230 | private static final int CMD_NV_READ_ITEM = 13; |
| 231 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 232 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 233 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 234 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 235 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 236 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 237 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 238 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 239 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 240 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 241 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 242 | private static final int CMD_SEND_ENVELOPE = 25; |
| 243 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 244 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 245 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 246 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 247 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 248 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 249 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 250 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 251 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 252 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 253 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 255 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 256 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 257 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 258 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 259 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 260 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 261 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 262 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 263 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 264 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 265 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 266 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 267 | private static final int CMD_SWITCH_SLOTS = 50; |
| 268 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 269 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 270 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 271 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 272 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 273 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 274 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 275 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 276 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 277 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 278 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 279 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 280 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 281 | private static final int CMD_MODEM_REBOOT = 64; |
| 282 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 283 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 284 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 285 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 286 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 287 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 288 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 289 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 290 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 291 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 292 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 293 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 294 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 295 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 296 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 297 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 298 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 299 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 300 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 301 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 302 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 303 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 304 | private static final int CMD_GET_CALL_WAITING = 87; |
| 305 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 306 | private static final int CMD_SET_CALL_WAITING = 89; |
| 307 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 308 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 309 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 310 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 311 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 312 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 313 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 314 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 315 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 316 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 317 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SIM_POWER = 101; |
| 319 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 320 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 321 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 322 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 323 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 325 | // Parameters of select command. |
| 326 | private static final int SELECT_COMMAND = 0xA4; |
| 327 | private static final int SELECT_P1 = 0x04; |
| 328 | private static final int SELECT_P2 = 0; |
| 329 | private static final int SELECT_P3 = 0x10; |
| 330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | /** The singleton instance. */ |
| 332 | private static PhoneInterfaceManager sInstance; |
| 333 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 334 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 335 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 336 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 337 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 338 | private AppOpsManager mAppOps; |
| 339 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 340 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 341 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 342 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 344 | /** User Activity */ |
| 345 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 346 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 347 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 348 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 349 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 350 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 351 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 352 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 353 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 354 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 355 | // String to store multi SIM allowed |
| 356 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 357 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 358 | // The AID of ISD-R. |
| 359 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 360 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 361 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 362 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 363 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 364 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 365 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 366 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 367 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 368 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 369 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 370 | */ |
| 371 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 372 | "reset_network_erase_modem_config_enabled"; |
| 373 | |
| 374 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 375 | * A request object to use for transmitting data to an ICC. |
| 376 | */ |
| 377 | private static final class IccAPDUArgument { |
| 378 | public int channel, cla, command, p1, p2, p3; |
| 379 | public String data; |
| 380 | |
| 381 | public IccAPDUArgument(int channel, int cla, int command, |
| 382 | int p1, int p2, int p3, String data) { |
| 383 | this.channel = channel; |
| 384 | this.cla = cla; |
| 385 | this.command = command; |
| 386 | this.p1 = p1; |
| 387 | this.p2 = p2; |
| 388 | this.p3 = p3; |
| 389 | this.data = data; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 394 | * A request object to use for transmitting data to an ICC. |
| 395 | */ |
| 396 | private static final class ManualNetworkSelectionArgument { |
| 397 | public OperatorInfo operatorInfo; |
| 398 | public boolean persistSelection; |
| 399 | |
| 400 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 401 | this.operatorInfo = operatorInfo; |
| 402 | this.persistSelection = persistSelection; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 407 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 408 | * request after sending. The main thread will notify the request when it is complete. |
| 409 | */ |
| 410 | private static final class MainThreadRequest { |
| 411 | /** The argument to use for the request */ |
| 412 | public Object argument; |
| 413 | /** The result of the request that is run on the main thread */ |
| 414 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 415 | // The subscriber id that this request applies to. Defaults to |
| 416 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 417 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 419 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 420 | public Phone phone; |
| 421 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 422 | public WorkSource workSource; |
| 423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | public MainThreadRequest(Object argument) { |
| 425 | this.argument = argument; |
| 426 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 427 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 428 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 429 | this.argument = argument; |
| 430 | if (phone != null) { |
| 431 | this.phone = phone; |
| 432 | } |
| 433 | this.workSource = workSource; |
| 434 | } |
| 435 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 436 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 437 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 438 | if (subId != null) { |
| 439 | this.subId = subId; |
| 440 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 441 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 445 | private static final class IncomingThirdPartyCallArgs { |
| 446 | public final ComponentName component; |
| 447 | public final String callId; |
| 448 | public final String callerDisplayName; |
| 449 | |
| 450 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 451 | String callerDisplayName) { |
| 452 | this.component = component; |
| 453 | this.callId = callId; |
| 454 | this.callerDisplayName = callerDisplayName; |
| 455 | } |
| 456 | } |
| 457 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | /** |
| 459 | * A handler that processes messages on the main thread in the phone process. Since many |
| 460 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 461 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 462 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 463 | * on, which will be notified when the operation completes and will contain the result of the |
| 464 | * request. |
| 465 | * |
| 466 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 467 | * note that request.result must be set to something non-null for the calling thread to |
| 468 | * unblock. |
| 469 | */ |
| 470 | private final class MainThreadHandler extends Handler { |
| 471 | @Override |
| 472 | public void handleMessage(Message msg) { |
| 473 | MainThreadRequest request; |
| 474 | Message onCompleted; |
| 475 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 476 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 478 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | |
| 480 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 481 | case CMD_HANDLE_USSD_REQUEST: { |
| 482 | request = (MainThreadRequest) msg.obj; |
| 483 | final Phone phone = getPhoneFromRequest(request); |
| 484 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 485 | String ussdRequest = ussdObject.first; |
| 486 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 487 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | if (!isUssdApiAllowed(request.subId)) { |
| 489 | // Carrier does not support use of this API, return failure. |
| 490 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 491 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 492 | Bundle returnData = new Bundle(); |
| 493 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 494 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 495 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 496 | request.result = true; |
| 497 | notifyRequester(request); |
| 498 | return; |
| 499 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 500 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 501 | try { |
| 502 | request.result = phone != null |
| 503 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 504 | } catch (CallStateException cse) { |
| 505 | request.result = false; |
| 506 | } |
| 507 | // Wake up the requesting thread |
| 508 | notifyRequester(request); |
| 509 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 512 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 513 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 514 | final Phone phone = getPhoneFromRequest(request); |
| 515 | request.result = phone != null ? |
| 516 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 517 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 518 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 519 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 521 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 526 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 527 | if (uiccCard == null) { |
| 528 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 529 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 531 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 533 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 536 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 537 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 539 | break; |
| 540 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | ar = (AsyncResult) msg.obj; |
| 543 | request = (MainThreadRequest) ar.userObj; |
| 544 | if (ar.exception == null && ar.result != null) { |
| 545 | request.result = ar.result; |
| 546 | } else { |
| 547 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 548 | if (ar.result == null) { |
| 549 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 550 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 552 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | } else { |
| 554 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 555 | } |
| 556 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 558 | break; |
| 559 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 561 | request = (MainThreadRequest) msg.obj; |
| 562 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 563 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | if (uiccCard == null) { |
| 565 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 566 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 567 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | } else { |
| 569 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 570 | request); |
| 571 | uiccCard.iccTransmitApduBasicChannel( |
| 572 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 573 | iccArgument.p3, iccArgument.data, onCompleted); |
| 574 | } |
| 575 | break; |
| 576 | |
| 577 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 578 | ar = (AsyncResult) msg.obj; |
| 579 | request = (MainThreadRequest) ar.userObj; |
| 580 | if (ar.exception == null && ar.result != null) { |
| 581 | request.result = ar.result; |
| 582 | } else { |
| 583 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 584 | if (ar.result == null) { |
| 585 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 586 | } else if (ar.exception instanceof CommandException) { |
| 587 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 588 | ar.exception); |
| 589 | } else { |
| 590 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 591 | } |
| 592 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | break; |
| 595 | |
| 596 | case CMD_EXCHANGE_SIM_IO: |
| 597 | request = (MainThreadRequest) msg.obj; |
| 598 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 599 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 600 | if (uiccCard == null) { |
| 601 | loge("iccExchangeSimIO: No UICC"); |
| 602 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 603 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | } else { |
| 605 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 606 | request); |
| 607 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 608 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 609 | iccArgument.data, onCompleted); |
| 610 | } |
| 611 | break; |
| 612 | |
| 613 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 614 | ar = (AsyncResult) msg.obj; |
| 615 | request = (MainThreadRequest) ar.userObj; |
| 616 | if (ar.exception == null && ar.result != null) { |
| 617 | request.result = ar.result; |
| 618 | } else { |
| 619 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 620 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 624 | case CMD_SEND_ENVELOPE: |
| 625 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 626 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 627 | if (uiccCard == null) { |
| 628 | loge("sendEnvelopeWithStatus: No UICC"); |
| 629 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | } else { |
| 632 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 633 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 634 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 635 | break; |
| 636 | |
| 637 | case EVENT_SEND_ENVELOPE_DONE: |
| 638 | ar = (AsyncResult) msg.obj; |
| 639 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 640 | if (ar.exception == null && ar.result != null) { |
| 641 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 642 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 643 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 644 | if (ar.result == null) { |
| 645 | loge("sendEnvelopeWithStatus: Empty response"); |
| 646 | } else if (ar.exception instanceof CommandException) { |
| 647 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 648 | ar.exception); |
| 649 | } else { |
| 650 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 651 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 652 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 654 | break; |
| 655 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | case CMD_OPEN_CHANNEL: |
| 657 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 658 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 659 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | if (uiccCard == null) { |
| 661 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 662 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 663 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 664 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 665 | } else { |
| 666 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 667 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 668 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | break; |
| 671 | |
| 672 | case EVENT_OPEN_CHANNEL_DONE: |
| 673 | ar = (AsyncResult) msg.obj; |
| 674 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | int[] result = (int[]) ar.result; |
| 678 | int channelId = result[0]; |
| 679 | byte[] selectResponse = null; |
| 680 | if (result.length > 1) { |
| 681 | selectResponse = new byte[result.length - 1]; |
| 682 | for (int i = 1; i < result.length; ++i) { |
| 683 | selectResponse[i - 1] = (byte) result[i]; |
| 684 | } |
| 685 | } |
| 686 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 687 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | if (ar.result == null) { |
| 690 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | if (ar.exception != null) { |
| 693 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 694 | } |
| 695 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 696 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 697 | if (ar.exception instanceof CommandException) { |
| 698 | CommandException.Error error = |
| 699 | ((CommandException) (ar.exception)).getCommandError(); |
| 700 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 701 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 702 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 703 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 707 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 709 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case CMD_CLOSE_CHANNEL: |
| 714 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 715 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 716 | if (uiccCard == null) { |
| 717 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 718 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 720 | } else { |
| 721 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 722 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 723 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 728 | break; |
| 729 | |
| 730 | case CMD_NV_READ_ITEM: |
| 731 | request = (MainThreadRequest) msg.obj; |
| 732 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 733 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 734 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | ar = (AsyncResult) msg.obj; |
| 739 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | if (ar.exception == null && ar.result != null) { |
| 741 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | request.result = ""; |
| 744 | if (ar.result == null) { |
| 745 | loge("nvReadItem: Empty response"); |
| 746 | } else if (ar.exception instanceof CommandException) { |
| 747 | loge("nvReadItem: CommandException: " + |
| 748 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 751 | } |
| 752 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 753 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | break; |
| 755 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | case CMD_NV_WRITE_ITEM: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 759 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 760 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 761 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 762 | break; |
| 763 | |
| 764 | case EVENT_NV_WRITE_ITEM_DONE: |
| 765 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 766 | break; |
| 767 | |
| 768 | case CMD_NV_WRITE_CDMA_PRL: |
| 769 | request = (MainThreadRequest) msg.obj; |
| 770 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 771 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 775 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 776 | break; |
| 777 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 778 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 780 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 781 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | break; |
| 783 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 784 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 785 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 788 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 789 | request = (MainThreadRequest) msg.obj; |
| 790 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 791 | request); |
| 792 | Phone phone = getPhoneFromRequest(request); |
| 793 | if (phone != null) { |
| 794 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 795 | } else { |
| 796 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 797 | request.result = false; |
| 798 | notifyRequester(request); |
| 799 | } |
| 800 | break; |
| 801 | } |
| 802 | |
| 803 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 804 | ar = (AsyncResult) msg.obj; |
| 805 | request = (MainThreadRequest) ar.userObj; |
| 806 | if (ar.exception == null && ar.result != null) { |
| 807 | request.result = ar.result; |
| 808 | } else { |
| 809 | // request.result must be set to something non-null |
| 810 | // for the calling thread to unblock |
| 811 | if (request.result != null) { |
| 812 | request.result = ar.result; |
| 813 | } else { |
| 814 | request.result = false; |
| 815 | } |
| 816 | if (ar.result == null) { |
| 817 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 818 | } else if (ar.exception instanceof CommandException) { |
| 819 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 820 | + ar.exception); |
| 821 | } else { |
| 822 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 823 | } |
| 824 | } |
| 825 | notifyRequester(request); |
| 826 | break; |
| 827 | |
| 828 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 829 | request = (MainThreadRequest) msg.obj; |
| 830 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 831 | Phone phone = getPhoneFromRequest(request); |
| 832 | if (phone != null) { |
| 833 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 834 | request.workSource); |
| 835 | } else { |
| 836 | loge("enableNrDualConnectivity: No phone object"); |
| 837 | request.result = |
| 838 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 839 | notifyRequester(request); |
| 840 | } |
| 841 | break; |
| 842 | } |
| 843 | |
| 844 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 845 | ar = (AsyncResult) msg.obj; |
| 846 | request = (MainThreadRequest) ar.userObj; |
| 847 | if (ar.exception == null) { |
| 848 | request.result = |
| 849 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 850 | } else { |
| 851 | request.result = |
| 852 | TelephonyManager |
| 853 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 854 | if (ar.exception instanceof CommandException) { |
| 855 | CommandException.Error error = |
| 856 | ((CommandException) (ar.exception)).getCommandError(); |
| 857 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 858 | request.result = |
| 859 | TelephonyManager |
| 860 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 861 | } |
| 862 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 863 | + ar.exception); |
| 864 | } else { |
| 865 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 866 | } |
| 867 | } |
| 868 | notifyRequester(request); |
| 869 | break; |
| 870 | } |
| 871 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 872 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 873 | request = (MainThreadRequest) msg.obj; |
| 874 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 875 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 879 | ar = (AsyncResult) msg.obj; |
| 880 | request = (MainThreadRequest) ar.userObj; |
| 881 | if (ar.exception == null && ar.result != null) { |
| 882 | request.result = ar.result; // Integer |
| 883 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 884 | // request.result must be set to something non-null |
| 885 | // for the calling thread to unblock |
| 886 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | if (ar.result == null) { |
| 888 | loge("getPreferredNetworkType: Empty response"); |
| 889 | } else if (ar.exception instanceof CommandException) { |
| 890 | loge("getPreferredNetworkType: CommandException: " + |
| 891 | ar.exception); |
| 892 | } else { |
| 893 | loge("getPreferredNetworkType: Unknown exception"); |
| 894 | } |
| 895 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 896 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 900 | request = (MainThreadRequest) msg.obj; |
| 901 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 902 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 903 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 907 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 908 | break; |
| 909 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 910 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 911 | request = (MainThreadRequest)msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 913 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 914 | break; |
| 915 | |
| 916 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 917 | ar = (AsyncResult)msg.obj; |
| 918 | request = (MainThreadRequest)ar.userObj; |
| 919 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 920 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 921 | break; |
| 922 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 923 | case CMD_SET_VOICEMAIL_NUMBER: |
| 924 | request = (MainThreadRequest) msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 926 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 927 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 928 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 929 | break; |
| 930 | |
| 931 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 932 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 933 | break; |
| 934 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 935 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 936 | request = (MainThreadRequest) msg.obj; |
| 937 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 938 | request); |
| 939 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 940 | break; |
| 941 | |
| 942 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 943 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 944 | break; |
| 945 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 946 | case CMD_PERFORM_NETWORK_SCAN: |
| 947 | request = (MainThreadRequest) msg.obj; |
| 948 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 949 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 950 | break; |
| 951 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 952 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 953 | request = (MainThreadRequest) msg.obj; |
| 954 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 955 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 956 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 957 | request.argument; |
| 958 | int callForwardingReason = args.first; |
| 959 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 960 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 961 | } |
| 962 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 963 | ar = (AsyncResult) msg.obj; |
| 964 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 965 | TelephonyManager.CallForwardingInfoCallback callback = |
| 966 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 967 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 968 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 970 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 971 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 972 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 973 | // any service for voice call. |
| 974 | if ((callForwardInfo.serviceClass |
| 975 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 976 | callForwardingInfo = new CallForwardingInfo(true, |
| 977 | callForwardInfo.reason, |
| 978 | callForwardInfo.number, |
| 979 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | } |
| 983 | // Didn't find a call forward info for voice call. |
| 984 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 986 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 987 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 989 | } else { |
| 990 | if (ar.result == null) { |
| 991 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 992 | } |
| 993 | if (ar.exception != null) { |
| 994 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 995 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 996 | int errorCode = TelephonyManager |
| 997 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 998 | if (ar.exception instanceof CommandException) { |
| 999 | CommandException.Error error = |
| 1000 | ((CommandException) (ar.exception)).getCommandError(); |
| 1001 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1002 | errorCode = TelephonyManager |
| 1003 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1004 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1005 | errorCode = TelephonyManager |
| 1006 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1007 | } |
| 1008 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1009 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1010 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1011 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1013 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1014 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1015 | request = (MainThreadRequest) msg.obj; |
| 1016 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1017 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1018 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1019 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1020 | request.argument).first; |
| 1021 | request.phone.setCallForwardingOption( |
| 1022 | callForwardingInfoToSet.isEnabled() |
| 1023 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1024 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1025 | callForwardingInfoToSet.getReason(), |
| 1026 | callForwardingInfoToSet.getNumber(), |
| 1027 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1028 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1029 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1030 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | Consumer<Integer> callback = |
| 1035 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1036 | request.argument).second; |
| 1037 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1038 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1039 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1040 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | if (ar.exception instanceof CommandException) { |
| 1042 | CommandException.Error error = |
| 1043 | ((CommandException) (ar.exception)).getCommandError(); |
| 1044 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1045 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1046 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1048 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1049 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | callback.accept(errorCode); |
| 1053 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1054 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1055 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1056 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1060 | request = (MainThreadRequest) msg.obj; |
| 1061 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1062 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1063 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1065 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1070 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1071 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1072 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1073 | // Service Class is a bit mask per 3gpp 27.007. |
| 1074 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1075 | if (callForwardResults.length > 1 |
| 1076 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1078 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1080 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1081 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1083 | } |
| 1084 | } else { |
| 1085 | if (ar.result == null) { |
| 1086 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1087 | } |
| 1088 | if (ar.exception != null) { |
| 1089 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1090 | } |
| 1091 | if (ar.exception instanceof CommandException) { |
| 1092 | CommandException.Error error = |
| 1093 | ((CommandException) (ar.exception)).getCommandError(); |
| 1094 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1095 | callForwardingStatus = |
| 1096 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1097 | } |
| 1098 | } |
| 1099 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1101 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1103 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1105 | request = (MainThreadRequest) msg.obj; |
| 1106 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1108 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1111 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1113 | ar = (AsyncResult) msg.obj; |
| 1114 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1116 | Consumer<Integer> callback = |
| 1117 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1118 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1119 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | if (ar.exception instanceof CommandException) { |
| 1121 | CommandException.Error error = |
| 1122 | ((CommandException) (ar.exception)).getCommandError(); |
| 1123 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1124 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1125 | } else { |
| 1126 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1127 | } |
| 1128 | } else { |
| 1129 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1130 | } |
| 1131 | } else { |
| 1132 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1133 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1134 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1135 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1136 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1137 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1138 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1139 | ar = (AsyncResult) msg.obj; |
| 1140 | request = (MainThreadRequest) ar.userObj; |
| 1141 | CellNetworkScanResult cellScanResult; |
| 1142 | if (ar.exception == null && ar.result != null) { |
| 1143 | cellScanResult = new CellNetworkScanResult( |
| 1144 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1145 | (List<OperatorInfo>) ar.result); |
| 1146 | } else { |
| 1147 | if (ar.result == null) { |
| 1148 | loge("getCellNetworkScanResults: Empty response"); |
| 1149 | } |
| 1150 | if (ar.exception != null) { |
| 1151 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1152 | } |
| 1153 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1154 | if (ar.exception instanceof CommandException) { |
| 1155 | CommandException.Error error = |
| 1156 | ((CommandException) (ar.exception)).getCommandError(); |
| 1157 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1158 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1159 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1160 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1161 | } |
| 1162 | } |
| 1163 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1164 | } |
| 1165 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1166 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1167 | break; |
| 1168 | |
| 1169 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1170 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1171 | ManualNetworkSelectionArgument selArg = |
| 1172 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1173 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1174 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1175 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1176 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1177 | break; |
| 1178 | |
| 1179 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1180 | ar = (AsyncResult) msg.obj; |
| 1181 | request = (MainThreadRequest) ar.userObj; |
| 1182 | if (ar.exception == null) { |
| 1183 | request.result = true; |
| 1184 | } else { |
| 1185 | request.result = false; |
| 1186 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1187 | } |
| 1188 | notifyRequester(request); |
| 1189 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1192 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1193 | request = (MainThreadRequest) msg.obj; |
| 1194 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1195 | if (defaultPhone != null) { |
| 1196 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1197 | } else { |
| 1198 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1199 | Bundle bundle = new Bundle(); |
| 1200 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1201 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1202 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1203 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1204 | break; |
| 1205 | |
| 1206 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1207 | ar = (AsyncResult) msg.obj; |
| 1208 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1209 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1210 | |
| 1211 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1212 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1213 | // Update the last modem activity info and the result of the request. |
| 1214 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1215 | if (isModemActivityInfoValid(info)) { |
| 1216 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1217 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1218 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1219 | .getTransmitTimeMillis(); |
| 1220 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1221 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1222 | } |
| 1223 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1224 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1225 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1226 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1227 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1228 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1229 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1230 | info.getReceiveTimeMillis() |
| 1231 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1232 | } |
| 1233 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1234 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1235 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1236 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1237 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | if (ar.result == null) { |
| 1240 | loge("queryModemActivityInfo: Empty response"); |
| 1241 | } else if (ar.exception instanceof CommandException) { |
| 1242 | loge("queryModemActivityInfo: CommandException: " + |
| 1243 | ar.exception); |
| 1244 | } else { |
| 1245 | loge("queryModemActivityInfo: Unknown exception"); |
| 1246 | } |
| 1247 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1248 | Bundle bundle = new Bundle(); |
| 1249 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1250 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1251 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1252 | break; |
| 1253 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1254 | case CMD_SET_ALLOWED_CARRIERS: |
| 1255 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1256 | CarrierRestrictionRules argument = |
| 1257 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1258 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1259 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1260 | break; |
| 1261 | |
| 1262 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1263 | ar = (AsyncResult) msg.obj; |
| 1264 | request = (MainThreadRequest) ar.userObj; |
| 1265 | if (ar.exception == null && ar.result != null) { |
| 1266 | request.result = ar.result; |
| 1267 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1268 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1269 | if (ar.exception instanceof CommandException) { |
| 1270 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1271 | CommandException.Error error = |
| 1272 | ((CommandException) (ar.exception)).getCommandError(); |
| 1273 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1274 | request.result = |
| 1275 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1276 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1277 | } else { |
| 1278 | loge("setAllowedCarriers: Unknown exception"); |
| 1279 | } |
| 1280 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1281 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | break; |
| 1283 | |
| 1284 | case CMD_GET_ALLOWED_CARRIERS: |
| 1285 | request = (MainThreadRequest) msg.obj; |
| 1286 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1287 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1288 | break; |
| 1289 | |
| 1290 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1291 | ar = (AsyncResult) msg.obj; |
| 1292 | request = (MainThreadRequest) ar.userObj; |
| 1293 | if (ar.exception == null && ar.result != null) { |
| 1294 | request.result = ar.result; |
| 1295 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1296 | request.result = new IllegalStateException( |
| 1297 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1298 | if (ar.result == null) { |
| 1299 | loge("getAllowedCarriers: Empty response"); |
| 1300 | } else if (ar.exception instanceof CommandException) { |
| 1301 | loge("getAllowedCarriers: CommandException: " + |
| 1302 | ar.exception); |
| 1303 | } else { |
| 1304 | loge("getAllowedCarriers: Unknown exception"); |
| 1305 | } |
| 1306 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1307 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1310 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1311 | ar = (AsyncResult) msg.obj; |
| 1312 | request = (MainThreadRequest) ar.userObj; |
| 1313 | if (ar.exception == null && ar.result != null) { |
| 1314 | request.result = ar.result; |
| 1315 | } else { |
| 1316 | request.result = new IllegalArgumentException( |
| 1317 | "Failed to retrieve Forbidden Plmns"); |
| 1318 | if (ar.result == null) { |
| 1319 | loge("getForbiddenPlmns: Empty response"); |
| 1320 | } else { |
| 1321 | loge("getForbiddenPlmns: Unknown exception"); |
| 1322 | } |
| 1323 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1324 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1325 | break; |
| 1326 | |
| 1327 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1328 | request = (MainThreadRequest) msg.obj; |
| 1329 | uiccCard = getUiccCardFromRequest(request); |
| 1330 | if (uiccCard == null) { |
| 1331 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1332 | request.result = new IllegalArgumentException( |
| 1333 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1334 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | Integer appType = (Integer) request.argument; |
| 1338 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1339 | if (uiccApp == null) { |
| 1340 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1341 | + appType); |
| 1342 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1343 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1344 | break; |
| 1345 | } else { |
| 1346 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1347 | + " specified type -- " + appType); |
| 1348 | } |
| 1349 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1350 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1351 | onCompleted); |
| 1352 | break; |
| 1353 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1354 | case CMD_SWITCH_SLOTS: |
| 1355 | request = (MainThreadRequest) msg.obj; |
| 1356 | int[] physicalSlots = (int[]) request.argument; |
| 1357 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1358 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1359 | break; |
| 1360 | |
| 1361 | case EVENT_SWITCH_SLOTS_DONE: |
| 1362 | ar = (AsyncResult) msg.obj; |
| 1363 | request = (MainThreadRequest) ar.userObj; |
| 1364 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1365 | notifyRequester(request); |
| 1366 | break; |
| 1367 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1368 | request = (MainThreadRequest) msg.obj; |
| 1369 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1370 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1371 | break; |
| 1372 | |
| 1373 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1374 | ar = (AsyncResult) msg.obj; |
| 1375 | request = (MainThreadRequest) ar.userObj; |
| 1376 | if (ar.exception != null) { |
| 1377 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1378 | } else { |
| 1379 | int mode = ((int[]) ar.result)[0]; |
| 1380 | if (mode == 0) { |
| 1381 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1382 | } else { |
| 1383 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1384 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1385 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1386 | notifyRequester(request); |
| 1387 | break; |
| 1388 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1389 | request = (MainThreadRequest) msg.obj; |
| 1390 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1391 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1392 | break; |
| 1393 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | if (ar.exception != null) { |
| 1397 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1398 | } else { |
| 1399 | request.result = ((int[]) ar.result)[0]; |
| 1400 | } |
| 1401 | notifyRequester(request); |
| 1402 | break; |
| 1403 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1404 | request = (MainThreadRequest) msg.obj; |
| 1405 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1406 | int mode = (int) request.argument; |
| 1407 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1408 | break; |
| 1409 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
| 1412 | request.result = ar.exception == null; |
| 1413 | notifyRequester(request); |
| 1414 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1415 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1416 | request = (MainThreadRequest) msg.obj; |
| 1417 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1418 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1419 | break; |
| 1420 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1421 | ar = (AsyncResult) msg.obj; |
| 1422 | request = (MainThreadRequest) ar.userObj; |
| 1423 | if (ar.exception != null) { |
| 1424 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1425 | } else { |
| 1426 | request.result = ((int[]) ar.result)[0]; |
| 1427 | } |
| 1428 | notifyRequester(request); |
| 1429 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1430 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1431 | request = (MainThreadRequest) msg.obj; |
| 1432 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1433 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1434 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1435 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1436 | break; |
| 1437 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1438 | ar = (AsyncResult) msg.obj; |
| 1439 | request = (MainThreadRequest) ar.userObj; |
| 1440 | request.result = ar.exception == null; |
| 1441 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1442 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1443 | case CMD_GET_ALL_CELL_INFO: |
| 1444 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1445 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1446 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1447 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1448 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1451 | // If a timeout occurs, the response will be null |
| 1452 | request.result = (ar.exception == null && ar.result != null) |
| 1453 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1454 | synchronized (request) { |
| 1455 | request.notifyAll(); |
| 1456 | } |
| 1457 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1458 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1459 | request = (MainThreadRequest) msg.obj; |
| 1460 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1461 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1462 | break; |
| 1463 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
| 1466 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1467 | try { |
| 1468 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1469 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1470 | cb.onError( |
| 1471 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1472 | ar.exception.getClass().getName(), |
| 1473 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1474 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1475 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1476 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1477 | } else { |
| 1478 | // use the result as returned |
| 1479 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1480 | } |
| 1481 | } catch (RemoteException re) { |
| 1482 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1483 | } |
| 1484 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1485 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1486 | request = (MainThreadRequest) msg.obj; |
| 1487 | WorkSource ws = (WorkSource) request.argument; |
| 1488 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1489 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1491 | } |
| 1492 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1493 | ar = (AsyncResult) msg.obj; |
| 1494 | request = (MainThreadRequest) ar.userObj; |
| 1495 | if (ar.exception == null) { |
| 1496 | request.result = ar.result; |
| 1497 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1498 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1500 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | synchronized (request) { |
| 1504 | request.notifyAll(); |
| 1505 | } |
| 1506 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1507 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1508 | case CMD_MODEM_REBOOT: |
| 1509 | request = (MainThreadRequest) msg.obj; |
| 1510 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1511 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1512 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1513 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1514 | handleNullReturnEvent(msg, "rebootModem"); |
| 1515 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1516 | case CMD_REQUEST_ENABLE_MODEM: |
| 1517 | request = (MainThreadRequest) msg.obj; |
| 1518 | boolean enable = (boolean) request.argument; |
| 1519 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1520 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1521 | PhoneConfigurationManager.getInstance() |
| 1522 | .enablePhone(request.phone, enable, onCompleted); |
| 1523 | break; |
| 1524 | case EVENT_ENABLE_MODEM_DONE: |
| 1525 | ar = (AsyncResult) msg.obj; |
| 1526 | request = (MainThreadRequest) ar.userObj; |
| 1527 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1528 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1529 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1530 | if ((boolean) request.result) { |
| 1531 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1532 | updateModemStateMetrics(); |
| 1533 | } else { |
| 1534 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1535 | + ar.exception); |
| 1536 | } |
| 1537 | notifyRequester(request); |
| 1538 | break; |
| 1539 | case CMD_GET_MODEM_STATUS: |
| 1540 | request = (MainThreadRequest) msg.obj; |
| 1541 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1542 | PhoneConfigurationManager.getInstance() |
| 1543 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1544 | break; |
| 1545 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1546 | ar = (AsyncResult) msg.obj; |
| 1547 | request = (MainThreadRequest) ar.userObj; |
| 1548 | int id = request.phone.getPhoneId(); |
| 1549 | if (ar.exception == null && ar.result != null) { |
| 1550 | request.result = ar.result; |
| 1551 | //update the cache as modem status has changed |
| 1552 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1553 | (boolean) request.result); |
| 1554 | } else { |
| 1555 | // Return true if modem status cannot be retrieved. For most cases, |
| 1556 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1557 | // and disable modem are not supported. Modem is always on. |
| 1558 | // TODO: this should be fixed in R to support a third |
| 1559 | // status UNKNOWN b/131631629 |
| 1560 | request.result = true; |
| 1561 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1562 | + ar.exception); |
| 1563 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1564 | notifyRequester(request); |
| 1565 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1566 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1567 | request = (MainThreadRequest) msg.obj; |
| 1568 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1569 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1570 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1571 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1572 | break; |
| 1573 | } |
| 1574 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1575 | ar = (AsyncResult) msg.obj; |
| 1576 | request = (MainThreadRequest) ar.userObj; |
| 1577 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1578 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1579 | args.second.accept(ar.exception == null); |
| 1580 | notifyRequester(request); |
| 1581 | break; |
| 1582 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1583 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1584 | request = (MainThreadRequest) msg.obj; |
| 1585 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1586 | Phone phone = getPhoneFromRequest(request); |
| 1587 | if (phone != null) { |
| 1588 | phone.getSystemSelectionChannels(onCompleted); |
| 1589 | } else { |
| 1590 | loge("getSystemSelectionChannels: No phone object"); |
| 1591 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1592 | notifyRequester(request); |
| 1593 | } |
| 1594 | break; |
| 1595 | } |
| 1596 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1597 | ar = (AsyncResult) msg.obj; |
| 1598 | request = (MainThreadRequest) ar.userObj; |
| 1599 | if (ar.exception == null && ar.result != null) { |
| 1600 | request.result = ar.result; |
| 1601 | } else { |
| 1602 | request.result = new IllegalArgumentException( |
| 1603 | "Failed to retrieve system selection channels"); |
| 1604 | if (ar.result == null) { |
| 1605 | loge("getSystemSelectionChannels: Empty response"); |
| 1606 | } else { |
| 1607 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1608 | } |
| 1609 | } |
| 1610 | notifyRequester(request); |
| 1611 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1612 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1613 | ar = (AsyncResult) msg.obj; |
| 1614 | request = (MainThreadRequest) ar.userObj; |
| 1615 | if (ar.exception == null && ar.result != null) { |
| 1616 | request.result = ar.result; |
| 1617 | } else { |
| 1618 | request.result = -1; |
| 1619 | loge("Failed to set Forbidden Plmns"); |
| 1620 | if (ar.result == null) { |
| 1621 | loge("setForbidenPlmns: Empty response"); |
| 1622 | } else if (ar.exception != null) { |
| 1623 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1624 | request.result = -1; |
| 1625 | } else { |
| 1626 | loge("setForbiddenPlmns: Unknown exception"); |
| 1627 | } |
| 1628 | } |
| 1629 | notifyRequester(request); |
| 1630 | break; |
| 1631 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1632 | request = (MainThreadRequest) msg.obj; |
| 1633 | uiccCard = getUiccCardFromRequest(request); |
| 1634 | if (uiccCard == null) { |
| 1635 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1636 | request.result = -1; |
| 1637 | notifyRequester(request); |
| 1638 | break; |
| 1639 | } |
| 1640 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1641 | (Pair<Integer, List<String>>) request.argument; |
| 1642 | appType = setFplmnsArgs.first; |
| 1643 | List<String> fplmns = setFplmnsArgs.second; |
| 1644 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1645 | if (uiccApp == null) { |
| 1646 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1647 | request.result = -1; |
| 1648 | loge("Failed to get UICC App"); |
| 1649 | notifyRequester(request); |
| 1650 | } else { |
| 1651 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1652 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1653 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1654 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1655 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1656 | case CMD_ERASE_MODEM_CONFIG: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1659 | defaultPhone.eraseModemConfig(onCompleted); |
| 1660 | break; |
| 1661 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1662 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1663 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1664 | |
| 1665 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1666 | request = (MainThreadRequest) msg.obj; |
| 1667 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1668 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1669 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1670 | changed.first, changed.second, onCompleted); |
| 1671 | break; |
| 1672 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1673 | ar = (AsyncResult) msg.obj; |
| 1674 | request = (MainThreadRequest) ar.userObj; |
| 1675 | if (ar.exception == null) { |
| 1676 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1677 | } else { |
| 1678 | request.result = msg.arg1; |
| 1679 | } |
| 1680 | notifyRequester(request); |
| 1681 | break; |
| 1682 | |
| 1683 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1686 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1687 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1688 | enabled.first, enabled.second, onCompleted); |
| 1689 | break; |
| 1690 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | if (ar.exception == null) { |
| 1694 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1695 | } else { |
| 1696 | request.result = msg.arg1; |
| 1697 | } |
| 1698 | notifyRequester(request); |
| 1699 | break; |
| 1700 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1701 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1702 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1703 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1704 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1705 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1706 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1707 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1708 | |
| 1709 | case CMD_SET_DATA_THROTTLING: { |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1712 | DataThrottlingRequest dataThrottlingRequest = |
| 1713 | (DataThrottlingRequest) request.argument; |
| 1714 | Phone phone = getPhoneFromRequest(request); |
| 1715 | if (phone != null) { |
| 1716 | phone.setDataThrottling(onCompleted, |
| 1717 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1718 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1719 | } else { |
| 1720 | loge("setDataThrottling: No phone object"); |
| 1721 | request.result = |
| 1722 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1723 | notifyRequester(request); |
| 1724 | } |
| 1725 | |
| 1726 | break; |
| 1727 | } |
| 1728 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1729 | ar = (AsyncResult) msg.obj; |
| 1730 | request = (MainThreadRequest) ar.userObj; |
| 1731 | |
| 1732 | if (ar.exception == null) { |
| 1733 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1734 | } else if (ar.exception instanceof CommandException) { |
| 1735 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1736 | CommandException.Error error = |
| 1737 | ((CommandException) (ar.exception)).getCommandError(); |
| 1738 | |
| 1739 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1740 | request.result = TelephonyManager |
| 1741 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1742 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1743 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1744 | } else { |
| 1745 | request.result = |
| 1746 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1747 | } |
| 1748 | } else { |
| 1749 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1750 | } |
| 1751 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1752 | notifyRequester(request); |
| 1753 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1754 | |
| 1755 | case CMD_SET_SIM_POWER: { |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1758 | request = (MainThreadRequest) msg.obj; |
| 1759 | int stateToSet = |
| 1760 | ((Pair<Integer, IIntegerConsumer>) |
| 1761 | request.argument).first; |
| 1762 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1763 | break; |
| 1764 | } |
| 1765 | case EVENT_SET_SIM_POWER_DONE: { |
| 1766 | ar = (AsyncResult) msg.obj; |
| 1767 | request = (MainThreadRequest) ar.userObj; |
| 1768 | IIntegerConsumer callback = |
| 1769 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1770 | if (ar.exception != null) { |
| 1771 | loge("setSimPower exception: " + ar.exception); |
| 1772 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1773 | .RESULT_ERROR_UNKNOWN; |
| 1774 | if (ar.exception instanceof CommandException) { |
| 1775 | CommandException.Error error = |
| 1776 | ((CommandException) (ar.exception)).getCommandError(); |
| 1777 | if (error == CommandException.Error.SIM_ERR) { |
| 1778 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1779 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1780 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1781 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1782 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1783 | } else { |
| 1784 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1785 | } |
| 1786 | } |
| 1787 | try { |
| 1788 | callback.accept(errorCode); |
| 1789 | } catch (RemoteException e) { |
| 1790 | // Ignore if the remote process is no longer available to call back. |
| 1791 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1792 | } |
| 1793 | } else { |
| 1794 | try { |
| 1795 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1796 | } catch (RemoteException e) { |
| 1797 | // Ignore if the remote process is no longer available to call back. |
| 1798 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1799 | } |
| 1800 | } |
| 1801 | break; |
| 1802 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1803 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1804 | request = (MainThreadRequest) msg.obj; |
| 1805 | |
| 1806 | final Phone phone = getPhoneFromRequest(request); |
| 1807 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1808 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1809 | notifyRequester(request); |
| 1810 | break; |
| 1811 | } |
| 1812 | |
| 1813 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1814 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1815 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1816 | request); |
| 1817 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1818 | request.subId, pair.first /*callingUid*/, |
| 1819 | pair.second /*request*/, onCompleted); |
| 1820 | break; |
| 1821 | } |
| 1822 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1823 | ar = (AsyncResult) msg.obj; |
| 1824 | request = (MainThreadRequest) ar.userObj; |
| 1825 | // request.result will be the exception of ar if present, true otherwise. |
| 1826 | // Be cautious not to leave result null which will wait() forever |
| 1827 | request.result = ar.exception != null ? ar.exception : true; |
| 1828 | notifyRequester(request); |
| 1829 | break; |
| 1830 | } |
| 1831 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1832 | request = (MainThreadRequest) msg.obj; |
| 1833 | |
| 1834 | Phone phone = getPhoneFromRequest(request); |
| 1835 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1836 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1837 | notifyRequester(request); |
| 1838 | break; |
| 1839 | } |
| 1840 | |
| 1841 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1842 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1843 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1844 | request); |
| 1845 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1846 | request.subId, pair.first /*callingUid*/, |
| 1847 | pair.second /*request*/, onCompleted); |
| 1848 | break; |
| 1849 | } |
| 1850 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1851 | ar = (AsyncResult) msg.obj; |
| 1852 | request = (MainThreadRequest) ar.userObj; |
| 1853 | request.result = ar.exception != null ? ar.exception : true; |
| 1854 | notifyRequester(request); |
| 1855 | break; |
| 1856 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1857 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | default: |
| 1859 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1860 | break; |
| 1861 | } |
| 1862 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1863 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1864 | private void notifyRequester(MainThreadRequest request) { |
| 1865 | synchronized (request) { |
| 1866 | request.notifyAll(); |
| 1867 | } |
| 1868 | } |
| 1869 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1870 | private void handleNullReturnEvent(Message msg, String command) { |
| 1871 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1872 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1873 | if (ar.exception == null) { |
| 1874 | request.result = true; |
| 1875 | } else { |
| 1876 | request.result = false; |
| 1877 | if (ar.exception instanceof CommandException) { |
| 1878 | loge(command + ": CommandException: " + ar.exception); |
| 1879 | } else { |
| 1880 | loge(command + ": Unknown exception"); |
| 1881 | } |
| 1882 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1883 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1884 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * Posts the specified command to be executed on the main thread, |
| 1889 | * waits for the request to complete, and returns the result. |
| 1890 | * @see #sendRequestAsync |
| 1891 | */ |
| 1892 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1893 | return sendRequest( |
| 1894 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | /** |
| 1898 | * Posts the specified command to be executed on the main thread, |
| 1899 | * waits for the request to complete, and returns the result. |
| 1900 | * @see #sendRequestAsync |
| 1901 | */ |
| 1902 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1903 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1904 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Posts the specified command to be executed on the main thread, |
| 1909 | * waits for the request to complete, and returns the result. |
| 1910 | * @see #sendRequestAsync |
| 1911 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1912 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1913 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Posts the specified command to be executed on the main thread, |
| 1918 | * waits for the request to complete, and returns the result. |
| 1919 | * @see #sendRequestAsync |
| 1920 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1921 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1922 | return sendRequest(command, argument, subId, null, workSource); |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Posts the specified command to be executed on the main thread, |
| 1927 | * waits for the request to complete, and returns the result. |
| 1928 | * @see #sendRequestAsync |
| 1929 | */ |
| 1930 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1931 | return sendRequest( |
| 1932 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Posts the specified command to be executed on the main thread, |
| 1937 | * waits for the request to complete, and returns the result. |
| 1938 | * @see #sendRequestAsync |
| 1939 | */ |
| 1940 | private Object sendRequest( |
| 1941 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1943 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1944 | } |
| 1945 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1946 | MainThreadRequest request = null; |
| 1947 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1948 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1949 | } else if (phone != null) { |
| 1950 | request = new MainThreadRequest(argument, phone, workSource); |
| 1951 | } else { |
| 1952 | request = new MainThreadRequest(argument, subId, workSource); |
| 1953 | } |
| 1954 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1956 | msg.sendToTarget(); |
| 1957 | |
| 1958 | // Wait for the request to complete |
| 1959 | synchronized (request) { |
| 1960 | while (request.result == null) { |
| 1961 | try { |
| 1962 | request.wait(); |
| 1963 | } catch (InterruptedException e) { |
| 1964 | // Do nothing, go back and wait until the request is complete |
| 1965 | } |
| 1966 | } |
| 1967 | } |
| 1968 | return request.result; |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1973 | * Posts the specified command to be executed on the main thread, and |
| 1974 | * returns immediately. |
| 1975 | * @see #sendRequest |
| 1976 | */ |
| 1977 | private void sendRequestAsync(int command) { |
| 1978 | mMainThreadHandler.sendEmptyMessage(command); |
| 1979 | } |
| 1980 | |
| 1981 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1982 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1983 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1984 | */ |
| 1985 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1986 | sendRequestAsync(command, argument, null, null); |
| 1987 | } |
| 1988 | |
| 1989 | /** |
| 1990 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1991 | * @see {@link #sendRequest(int,Object)} |
| 1992 | */ |
| 1993 | private void sendRequestAsync( |
| 1994 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1995 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1996 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1997 | msg.sendToTarget(); |
| 1998 | } |
| 1999 | |
| 2000 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2002 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2003 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2004 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | synchronized (PhoneInterfaceManager.class) { |
| 2006 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2007 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2008 | } else { |
| 2009 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2010 | } |
| 2011 | return sInstance; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2016 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2018 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2019 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2020 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2022 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2023 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2024 | mTelephonySharedPreferences = |
| 2025 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2026 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2027 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2028 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2029 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | publish(); |
| 2031 | } |
| 2032 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2033 | private Phone getDefaultPhone() { |
| 2034 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2035 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2036 | } |
| 2037 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2038 | private void publish() { |
| 2039 | if (DBG) log("publish: " + this); |
| 2040 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2041 | TelephonyFrameworkInitializer |
| 2042 | .getTelephonyServiceManager() |
| 2043 | .getTelephonyServiceRegisterer() |
| 2044 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2047 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2048 | if (request.phone != null) { |
| 2049 | return request.phone; |
| 2050 | } else { |
| 2051 | return getPhoneFromSubId(request.subId); |
| 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | private Phone getPhoneFromSubId(int subId) { |
| 2056 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2057 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2060 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2061 | Phone phone = getPhoneFromRequest(request); |
| 2062 | return phone == null ? null : |
| 2063 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2064 | } |
| 2065 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2066 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2067 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2068 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2071 | private void sendEraseModemConfig(Phone phone) { |
| 2072 | if (phone != null) { |
| 2073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2074 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2078 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2079 | } finally { |
| 2080 | Binder.restoreCallingIdentity(identity); |
| 2081 | } |
| 2082 | } |
| 2083 | } |
| 2084 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2085 | private boolean isImsAvailableOnDevice() { |
| 2086 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2087 | if (pm == null) { |
| 2088 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2089 | // so do not throw error and allow. |
| 2090 | return true; |
| 2091 | } |
| 2092 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2093 | } |
| 2094 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2096 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2099 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2100 | if (DBG) log("dial: " + number); |
| 2101 | // No permission check needed here: This is just a wrapper around the |
| 2102 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2103 | // the UI before it does anything. |
| 2104 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2105 | final long identity = Binder.clearCallingIdentity(); |
| 2106 | try { |
| 2107 | String url = createTelUrl(number); |
| 2108 | if (url == null) { |
| 2109 | return; |
| 2110 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2113 | PhoneConstants.State state = mCM.getState(subId); |
| 2114 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2115 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2116 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2117 | mApp.startActivity(intent); |
| 2118 | } |
| 2119 | } finally { |
| 2120 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2125 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2126 | } |
| 2127 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2128 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | if (DBG) log("call: " + number); |
| 2130 | |
| 2131 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2132 | // need to do a permission check since we're calling startActivity() |
| 2133 | // from the context of the phone app. |
| 2134 | enforceCallPermission(); |
| 2135 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2136 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2137 | != AppOpsManager.MODE_ALLOWED) { |
| 2138 | return; |
| 2139 | } |
| 2140 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2141 | final long identity = Binder.clearCallingIdentity(); |
| 2142 | try { |
| 2143 | String url = createTelUrl(number); |
| 2144 | if (url == null) { |
| 2145 | return; |
| 2146 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2148 | boolean isValid = false; |
| 2149 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2150 | if (slist != null) { |
| 2151 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2152 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2153 | isValid = true; |
| 2154 | break; |
| 2155 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2156 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2157 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | if (!isValid) { |
| 2159 | return; |
| 2160 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2161 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2162 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2163 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2164 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2165 | mApp.startActivity(intent); |
| 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
| 2168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2171 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2172 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2173 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2174 | } |
| 2175 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2176 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2177 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2178 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2179 | } |
| 2180 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2181 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2183 | |
| 2184 | final long identity = Binder.clearCallingIdentity(); |
| 2185 | try { |
| 2186 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2187 | checkSimPin.start(); |
| 2188 | return checkSimPin.unlockSim(null, pin); |
| 2189 | } finally { |
| 2190 | Binder.restoreCallingIdentity(identity); |
| 2191 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2194 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2196 | |
| 2197 | final long identity = Binder.clearCallingIdentity(); |
| 2198 | try { |
| 2199 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2200 | checkSimPuk.start(); |
| 2201 | return checkSimPuk.unlockSim(puk, pin); |
| 2202 | } finally { |
| 2203 | Binder.restoreCallingIdentity(identity); |
| 2204 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2208 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 | * a synchronous one. |
| 2210 | */ |
| 2211 | private static class UnlockSim extends Thread { |
| 2212 | |
| 2213 | private final IccCard mSimCard; |
| 2214 | |
| 2215 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2216 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2217 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2218 | |
| 2219 | // For replies from SimCard interface |
| 2220 | private Handler mHandler; |
| 2221 | |
| 2222 | // For async handler to identify request type |
| 2223 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2224 | |
| 2225 | public UnlockSim(IccCard simCard) { |
| 2226 | mSimCard = simCard; |
| 2227 | } |
| 2228 | |
| 2229 | @Override |
| 2230 | public void run() { |
| 2231 | Looper.prepare(); |
| 2232 | synchronized (UnlockSim.this) { |
| 2233 | mHandler = new Handler() { |
| 2234 | @Override |
| 2235 | public void handleMessage(Message msg) { |
| 2236 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2237 | switch (msg.what) { |
| 2238 | case SUPPLY_PIN_COMPLETE: |
| 2239 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2240 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2241 | mRetryCount = msg.arg1; |
| 2242 | if (ar.exception != null) { |
| 2243 | if (ar.exception instanceof CommandException && |
| 2244 | ((CommandException)(ar.exception)).getCommandError() |
| 2245 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2246 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2247 | } //When UiccCardApp dispose,handle message and return exception |
| 2248 | else if (ar.exception instanceof CommandException && |
| 2249 | ((CommandException) (ar.exception)).getCommandError() |
| 2250 | == CommandException.Error.ABORTED) { |
| 2251 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2252 | } else { |
| 2253 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2254 | } |
| 2255 | } else { |
| 2256 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | mDone = true; |
| 2259 | UnlockSim.this.notifyAll(); |
| 2260 | } |
| 2261 | break; |
| 2262 | } |
| 2263 | } |
| 2264 | }; |
| 2265 | UnlockSim.this.notifyAll(); |
| 2266 | } |
| 2267 | Looper.loop(); |
| 2268 | } |
| 2269 | |
| 2270 | /* |
| 2271 | * Use PIN or PUK to unlock SIM card |
| 2272 | * |
| 2273 | * If PUK is null, unlock SIM card with PIN |
| 2274 | * |
| 2275 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2276 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2277 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | |
| 2279 | while (mHandler == null) { |
| 2280 | try { |
| 2281 | wait(); |
| 2282 | } catch (InterruptedException e) { |
| 2283 | Thread.currentThread().interrupt(); |
| 2284 | } |
| 2285 | } |
| 2286 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2287 | |
| 2288 | if (puk == null) { |
| 2289 | mSimCard.supplyPin(pin, callback); |
| 2290 | } else { |
| 2291 | mSimCard.supplyPuk(puk, pin, callback); |
| 2292 | } |
| 2293 | |
| 2294 | while (!mDone) { |
| 2295 | try { |
| 2296 | Log.d(LOG_TAG, "wait for done"); |
| 2297 | wait(); |
| 2298 | } catch (InterruptedException e) { |
| 2299 | // Restore the interrupted status |
| 2300 | Thread.currentThread().interrupt(); |
| 2301 | } |
| 2302 | } |
| 2303 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2304 | int[] resultArray = new int[2]; |
| 2305 | resultArray[0] = mResult; |
| 2306 | resultArray[1] = mRetryCount; |
| 2307 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2311 | /** |
| 2312 | * This method has been removed due to privacy and stability concerns. |
| 2313 | */ |
| 2314 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2315 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2316 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2317 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2320 | @Override |
| 2321 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2322 | mApp.getSystemService(AppOpsManager.class) |
| 2323 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2324 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2325 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2326 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2327 | // Callers targeting S have no business invoking this method. |
| 2328 | return; |
| 2329 | } |
| 2330 | |
| 2331 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2332 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2333 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2334 | .setCallingPackage(callingPackage) |
| 2335 | .setCallingFeatureId(null) |
| 2336 | .setCallingPid(Binder.getCallingPid()) |
| 2337 | .setCallingUid(Binder.getCallingUid()) |
| 2338 | .setMethod("updateServiceLocation") |
| 2339 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2340 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2341 | .build()); |
| 2342 | // Apps that lack location permission have no business calling this method; |
| 2343 | // however, because no permission was declared in the public API, denials must |
| 2344 | // all be "soft". |
| 2345 | switch (locationResult) { |
| 2346 | case DENIED_HARD: /* fall through */ |
| 2347 | case DENIED_SOFT: |
| 2348 | return; |
| 2349 | } |
| 2350 | |
| 2351 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2352 | final long identity = Binder.clearCallingIdentity(); |
| 2353 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2354 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2355 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2356 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2357 | } |
| 2358 | } finally { |
| 2359 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2360 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2361 | } |
| 2362 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2363 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2364 | @Override |
| 2365 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2366 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2369 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2370 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2371 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2372 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2373 | callingFeatureId); |
| 2374 | } |
| 2375 | |
| 2376 | @Deprecated |
| 2377 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2378 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2379 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2380 | } |
| 2381 | |
| 2382 | @Override |
| 2383 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2384 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2385 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2386 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2387 | return false; |
| 2388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2389 | |
| 2390 | final long identity = Binder.clearCallingIdentity(); |
| 2391 | try { |
| 2392 | return isRadioOnForSubscriber(subId); |
| 2393 | } finally { |
| 2394 | Binder.restoreCallingIdentity(identity); |
| 2395 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2399 | final long identity = Binder.clearCallingIdentity(); |
| 2400 | try { |
| 2401 | final Phone phone = getPhone(subId); |
| 2402 | if (phone != null) { |
| 2403 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2404 | } else { |
| 2405 | return false; |
| 2406 | } |
| 2407 | } finally { |
| 2408 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2409 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2413 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2414 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2415 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2416 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2418 | |
| 2419 | final long identity = Binder.clearCallingIdentity(); |
| 2420 | try { |
| 2421 | final Phone phone = getPhone(subId); |
| 2422 | if (phone != null) { |
| 2423 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2424 | } |
| 2425 | } finally { |
| 2426 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2427 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2431 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2434 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2435 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2436 | |
| 2437 | final long identity = Binder.clearCallingIdentity(); |
| 2438 | try { |
| 2439 | final Phone phone = getPhone(subId); |
| 2440 | if (phone == null) { |
| 2441 | return false; |
| 2442 | } |
| 2443 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2444 | toggleRadioOnOffForSubscriber(subId); |
| 2445 | } |
| 2446 | return true; |
| 2447 | } finally { |
| 2448 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2451 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2452 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2453 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2454 | /* |
| 2455 | * If any of the Radios are available, it will need to be |
| 2456 | * shutdown. So return true if any Radio is available. |
| 2457 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2458 | final long identity = Binder.clearCallingIdentity(); |
| 2459 | try { |
| 2460 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2461 | Phone phone = PhoneFactory.getPhone(i); |
| 2462 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2463 | } |
| 2464 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2465 | return false; |
| 2466 | } finally { |
| 2467 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2468 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2469 | } |
| 2470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2471 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2472 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | enforceModifyPermission(); |
| 2474 | |
| 2475 | final long identity = Binder.clearCallingIdentity(); |
| 2476 | try { |
| 2477 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2478 | logv("Shutting down Phone " + i); |
| 2479 | shutdownRadioUsingPhoneId(i); |
| 2480 | } |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2487 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2488 | if (phone != null && phone.isRadioAvailable()) { |
| 2489 | phone.shutdownRadio(); |
| 2490 | } |
| 2491 | } |
| 2492 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2494 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | |
| 2496 | final long identity = Binder.clearCallingIdentity(); |
| 2497 | try { |
| 2498 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2499 | if (defaultPhone != null) { |
| 2500 | defaultPhone.setRadioPower(turnOn); |
| 2501 | return true; |
| 2502 | } else { |
| 2503 | loge("There's no default phone."); |
| 2504 | return false; |
| 2505 | } |
| 2506 | } finally { |
| 2507 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2508 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2511 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2512 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | |
| 2514 | final long identity = Binder.clearCallingIdentity(); |
| 2515 | try { |
| 2516 | final Phone phone = getPhone(subId); |
| 2517 | if (phone != null) { |
| 2518 | phone.setRadioPower(turnOn); |
| 2519 | return true; |
| 2520 | } else { |
| 2521 | return false; |
| 2522 | } |
| 2523 | } finally { |
| 2524 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2528 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2529 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2530 | public boolean enableDataConnectivity() { |
| 2531 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | |
| 2533 | final long identity = Binder.clearCallingIdentity(); |
| 2534 | try { |
| 2535 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2536 | final Phone phone = getPhone(subId); |
| 2537 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2538 | phone.getDataEnabledSettings().setDataEnabled( |
| 2539 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2540 | return true; |
| 2541 | } else { |
| 2542 | return false; |
| 2543 | } |
| 2544 | } finally { |
| 2545 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2549 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2550 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | public boolean disableDataConnectivity() { |
| 2552 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2553 | |
| 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2557 | final Phone phone = getPhone(subId); |
| 2558 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2559 | phone.getDataEnabledSettings().setDataEnabled( |
| 2560 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2561 | return true; |
| 2562 | } else { |
| 2563 | return false; |
| 2564 | } |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2570 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2571 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2572 | final long identity = Binder.clearCallingIdentity(); |
| 2573 | try { |
| 2574 | final Phone phone = getPhone(subId); |
| 2575 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2576 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | } else { |
| 2578 | return false; |
| 2579 | } |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2586 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2589 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2590 | enforceCallPermission(); |
| 2591 | |
| 2592 | final long identity = Binder.clearCallingIdentity(); |
| 2593 | try { |
| 2594 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2595 | return; |
| 2596 | } |
| 2597 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2598 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2599 | } finally { |
| 2600 | Binder.restoreCallingIdentity(identity); |
| 2601 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2602 | }; |
| 2603 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2604 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | |
| 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2610 | return false; |
| 2611 | } |
| 2612 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2619 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2622 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | final long identity = Binder.clearCallingIdentity(); |
| 2624 | try { |
| 2625 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2626 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2627 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(identity); |
| 2630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2631 | } |
| 2632 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2633 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2634 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2635 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2636 | } |
| 2637 | |
| 2638 | @Override |
| 2639 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | final long identity = Binder.clearCallingIdentity(); |
| 2641 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2642 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2643 | if (phone != null) { |
| 2644 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2645 | } else { |
| 2646 | return PhoneConstantConversions.convertDataState( |
| 2647 | PhoneConstants.DataState.DISCONNECTED); |
| 2648 | } |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2654 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2655 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2656 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2657 | } |
| 2658 | |
| 2659 | @Override |
| 2660 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2663 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | if (phone != null) { |
| 2665 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2666 | } else { |
| 2667 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2668 | } |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2671 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2675 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2676 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2677 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2678 | |
| 2679 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2680 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2681 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2682 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2683 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2684 | .setCallingPid(Binder.getCallingPid()) |
| 2685 | .setCallingUid(Binder.getCallingUid()) |
| 2686 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2687 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2688 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2689 | .build()); |
| 2690 | switch (locationResult) { |
| 2691 | case DENIED_HARD: |
| 2692 | throw new SecurityException("Not allowed to access cell location"); |
| 2693 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2694 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2695 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2696 | } |
| 2697 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2698 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2699 | final long identity = Binder.clearCallingIdentity(); |
| 2700 | try { |
| 2701 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2702 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2703 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2704 | } finally { |
| 2705 | Binder.restoreCallingIdentity(identity); |
| 2706 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2709 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2710 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2711 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2712 | // registered cell info, so return a NULL country instead. |
| 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2715 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2716 | // Get default phone in this case. |
| 2717 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2718 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2719 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2721 | if (phone == null) return ""; |
| 2722 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2723 | if (sst == null) return ""; |
| 2724 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2725 | if (lt == null) return ""; |
| 2726 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2727 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2728 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
| 2731 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2734 | /** |
| 2735 | * This method was removed due to potential issues caused by performing partial |
| 2736 | * updates of service state, and lack of a credible use case. |
| 2737 | * |
| 2738 | * This has the ability to break the telephony implementation by disabling notification of |
| 2739 | * changes in device connectivity. DO NOT USE THIS! |
| 2740 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2741 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | public void enableLocationUpdates() { |
| 2743 | mApp.enforceCallingOrSelfPermission( |
| 2744 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2747 | /** |
| 2748 | * This method was removed due to potential issues caused by performing partial |
| 2749 | * updates of service state, and lack of a credible use case. |
| 2750 | * |
| 2751 | * This has the ability to break the telephony implementation by disabling notification of |
| 2752 | * changes in device connectivity. DO NOT USE THIS! |
| 2753 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | @Override |
| 2755 | public void disableLocationUpdates() { |
| 2756 | mApp.enforceCallingOrSelfPermission( |
| 2757 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | @Override |
| 2761 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2762 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2763 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2764 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2765 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2766 | throw new SecurityException( |
| 2767 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2768 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2769 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2770 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2772 | return null; |
| 2773 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2774 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2775 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2777 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2778 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2780 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2781 | for (CellInfo ci : info) { |
| 2782 | if (ci instanceof CellInfoGsm) { |
| 2783 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2784 | } else if (ci instanceof CellInfoWcdma) { |
| 2785 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2786 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2788 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2791 | private List<CellInfo> getCachedCellInfo() { |
| 2792 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2793 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2794 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2795 | if (info != null) cellInfos.addAll(info); |
| 2796 | } |
| 2797 | return cellInfos; |
| 2798 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2799 | |
| 2800 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2801 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2802 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2803 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2804 | |
| 2805 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2806 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2807 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2808 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2809 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2810 | .setCallingPid(Binder.getCallingPid()) |
| 2811 | .setCallingUid(Binder.getCallingUid()) |
| 2812 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2813 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2814 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2815 | .build()); |
| 2816 | switch (locationResult) { |
| 2817 | case DENIED_HARD: |
| 2818 | throw new SecurityException("Not allowed to access cell info"); |
| 2819 | case DENIED_SOFT: |
| 2820 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2823 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2824 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2825 | return getCachedCellInfo(); |
| 2826 | } |
| 2827 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2828 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2829 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | final long identity = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2833 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2834 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2835 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | if (info != null) cellInfos.addAll(info); |
| 2837 | } |
| 2838 | return cellInfos; |
| 2839 | } finally { |
| 2840 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2844 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2845 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2846 | String callingFeatureId) { |
| 2847 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2848 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2852 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2853 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2854 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2855 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2858 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2859 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2860 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2861 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2862 | |
| 2863 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2864 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2865 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2866 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2867 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2868 | .setCallingPid(Binder.getCallingPid()) |
| 2869 | .setCallingUid(Binder.getCallingUid()) |
| 2870 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2871 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2872 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2873 | .build()); |
| 2874 | switch (locationResult) { |
| 2875 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2876 | if (TelephonyPermissions |
| 2877 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2878 | // Safetynet logging for b/154934934 |
| 2879 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2880 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2881 | throw new SecurityException("Not allowed to access cell info"); |
| 2882 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2883 | if (TelephonyPermissions |
| 2884 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2885 | // Safetynet logging for b/154934934 |
| 2886 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2887 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2888 | try { |
| 2889 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2890 | } catch (RemoteException re) { |
| 2891 | // Drop without consequences |
| 2892 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2893 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2894 | } |
| 2895 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2896 | |
| 2897 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2898 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2899 | |
| 2900 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2901 | } |
| 2902 | |
| 2903 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2904 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2905 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2906 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | |
| 2908 | final long identity = Binder.clearCallingIdentity(); |
| 2909 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2910 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | } finally { |
| 2912 | Binder.restoreCallingIdentity(identity); |
| 2913 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2916 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2917 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2918 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2919 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2920 | return null; |
| 2921 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2922 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2923 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2924 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2925 | return null; |
| 2926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2927 | |
| 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | return phone.getImei(); |
| 2931 | } finally { |
| 2932 | Binder.restoreCallingIdentity(identity); |
| 2933 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2937 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2938 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2939 | String tac = null; |
| 2940 | if (phone != null) { |
| 2941 | String imei = phone.getImei(); |
| 2942 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2943 | } |
| 2944 | return tac; |
| 2945 | } |
| 2946 | |
| 2947 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2948 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2949 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2950 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2951 | return null; |
| 2952 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2953 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2954 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2955 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2956 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2957 | return null; |
| 2958 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2959 | |
| 2960 | final long identity = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | return phone.getMeid(); |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
| 2965 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2969 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2970 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2971 | String manufacturerCode = null; |
| 2972 | if (phone != null) { |
| 2973 | String meid = phone.getMeid(); |
| 2974 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2975 | } |
| 2976 | return manufacturerCode; |
| 2977 | } |
| 2978 | |
| 2979 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2980 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2981 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2982 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2983 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2984 | return null; |
| 2985 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2986 | int subId = phone.getSubId(); |
| 2987 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2988 | mApp, subId, callingPackage, callingFeatureId, |
| 2989 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2990 | return null; |
| 2991 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | |
| 2993 | final long identity = Binder.clearCallingIdentity(); |
| 2994 | try { |
| 2995 | return phone.getDeviceSvn(); |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3001 | @Override |
| 3002 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | final Phone phone = getPhone(subId); |
| 3006 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3007 | } finally { |
| 3008 | Binder.restoreCallingIdentity(identity); |
| 3009 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | @Override |
| 3013 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3014 | final long identity = Binder.clearCallingIdentity(); |
| 3015 | try { |
| 3016 | final Phone phone = getPhone(subId); |
| 3017 | return phone == null ? null : phone.getCarrierName(); |
| 3018 | } finally { |
| 3019 | Binder.restoreCallingIdentity(identity); |
| 3020 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3021 | } |
| 3022 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3023 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3024 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | final Phone phone = getPhone(subId); |
| 3028 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3029 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3036 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3037 | final long identity = Binder.clearCallingIdentity(); |
| 3038 | try { |
| 3039 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3040 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3041 | } finally { |
| 3042 | Binder.restoreCallingIdentity(identity); |
| 3043 | } |
| 3044 | } |
| 3045 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3046 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3047 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3048 | if (!isSubscriptionMccMnc) { |
| 3049 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3050 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3051 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3052 | if (phone == null) { |
| 3053 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3054 | } |
| 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
| 3060 | } |
| 3061 | } |
| 3062 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | // |
| 3064 | // Internal helper methods. |
| 3065 | // |
| 3066 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3067 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3069 | * |
| 3070 | * @throws SecurityException if the caller does not have the required permission |
| 3071 | */ |
| 3072 | private void enforceModifyPermission() { |
| 3073 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3074 | } |
| 3075 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3076 | /** |
| 3077 | * Make sure the caller is system. |
| 3078 | * |
| 3079 | * @throws SecurityException if the caller is not system. |
| 3080 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3081 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3082 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3083 | throw new SecurityException("Caller must be system"); |
| 3084 | } |
| 3085 | } |
| 3086 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3087 | private void enforceActiveEmergencySessionPermission() { |
| 3088 | mApp.enforceCallingOrSelfPermission( |
| 3089 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3090 | } |
| 3091 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3092 | /** |
| 3093 | * Make sure the caller has the CALL_PHONE permission. |
| 3094 | * |
| 3095 | * @throws SecurityException if the caller does not have the required permission |
| 3096 | */ |
| 3097 | private void enforceCallPermission() { |
| 3098 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3099 | } |
| 3100 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3101 | private void enforceSettingsPermission() { |
| 3102 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3105 | private String createTelUrl(String number) { |
| 3106 | if (TextUtils.isEmpty(number)) { |
| 3107 | return null; |
| 3108 | } |
| 3109 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3110 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3113 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3114 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3115 | } |
| 3116 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3117 | private static void logv(String msg) { |
| 3118 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3119 | } |
| 3120 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3121 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3122 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3123 | } |
| 3124 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3125 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3126 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3127 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3128 | } |
| 3129 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3130 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3131 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 | final long identity = Binder.clearCallingIdentity(); |
| 3133 | try { |
| 3134 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3135 | if (phone == null) { |
| 3136 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3137 | } else { |
| 3138 | return phone.getPhoneType(); |
| 3139 | } |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | /** |
| 3146 | * Returns the CDMA ERI icon index to display |
| 3147 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3148 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3149 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3150 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3151 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3152 | } |
| 3153 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3154 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3155 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3156 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3157 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3158 | mApp, subId, callingPackage, callingFeatureId, |
| 3159 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3160 | return -1; |
| 3161 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3162 | |
| 3163 | final long identity = Binder.clearCallingIdentity(); |
| 3164 | try { |
| 3165 | final Phone phone = getPhone(subId); |
| 3166 | if (phone != null) { |
| 3167 | return phone.getCdmaEriIconIndex(); |
| 3168 | } else { |
| 3169 | return -1; |
| 3170 | } |
| 3171 | } finally { |
| 3172 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3173 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | /** |
| 3177 | * Returns the CDMA ERI icon mode, |
| 3178 | * 0 - ON |
| 3179 | * 1 - FLASHING |
| 3180 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3181 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3182 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3183 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3184 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3187 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3188 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3191 | mApp, subId, callingPackage, callingFeatureId, |
| 3192 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3193 | return -1; |
| 3194 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | |
| 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | final Phone phone = getPhone(subId); |
| 3199 | if (phone != null) { |
| 3200 | return phone.getCdmaEriIconMode(); |
| 3201 | } else { |
| 3202 | return -1; |
| 3203 | } |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * Returns the CDMA ERI text, |
| 3211 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3212 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3213 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3214 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3215 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3218 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3219 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3220 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3221 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3222 | mApp, subId, callingPackage, callingFeatureId, |
| 3223 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3224 | return null; |
| 3225 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | |
| 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | final Phone phone = getPhone(subId); |
| 3230 | if (phone != null) { |
| 3231 | return phone.getCdmaEriText(); |
| 3232 | } else { |
| 3233 | return null; |
| 3234 | } |
| 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3241 | * Returns the CDMA MDN. |
| 3242 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3244 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3246 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3247 | |
| 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
| 3250 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3251 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | return phone.getLine1Number(); |
| 3253 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3254 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | return null; |
| 3256 | } |
| 3257 | } finally { |
| 3258 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3259 | } |
| 3260 | } |
| 3261 | |
| 3262 | /** |
| 3263 | * Returns the CDMA MIN. |
| 3264 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3265 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3266 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3268 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | |
| 3270 | final long identity = Binder.clearCallingIdentity(); |
| 3271 | try { |
| 3272 | final Phone phone = getPhone(subId); |
| 3273 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3274 | return phone.getCdmaMin(); |
| 3275 | } else { |
| 3276 | return null; |
| 3277 | } |
| 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3280 | } |
| 3281 | } |
| 3282 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3283 | @Override |
| 3284 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3285 | INumberVerificationCallback callback, String callingPackage) { |
| 3286 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3287 | != PERMISSION_GRANTED) { |
| 3288 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3289 | } |
| 3290 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3291 | |
| 3292 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3293 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3294 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3295 | + "calling package: " + callingPackage |
| 3296 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3297 | } |
| 3298 | |
| 3299 | if (range == null) { |
| 3300 | throw new NullPointerException("Range must be non-null"); |
| 3301 | } |
| 3302 | |
| 3303 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3304 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3305 | |
| 3306 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3307 | } |
| 3308 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3309 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3310 | * Returns true if CDMA provisioning needs to run. |
| 3311 | */ |
| 3312 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3313 | final long identity = Binder.clearCallingIdentity(); |
| 3314 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3315 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(identity); |
| 3318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3322 | * Sets the voice mail number of a given subId. |
| 3323 | */ |
| 3324 | @Override |
| 3325 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3326 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3327 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | |
| 3329 | final long identity = Binder.clearCallingIdentity(); |
| 3330 | try { |
| 3331 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3332 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3333 | return success; |
| 3334 | } finally { |
| 3335 | Binder.restoreCallingIdentity(identity); |
| 3336 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3337 | } |
| 3338 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3339 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3340 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3341 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3342 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3343 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3344 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3345 | throw new SecurityException("caller must be system dialer"); |
| 3346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | |
| 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3351 | if (phoneAccountHandle == null) { |
| 3352 | return null; |
| 3353 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3354 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3355 | } finally { |
| 3356 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3357 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3361 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3362 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3363 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3364 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3365 | mApp, subId, callingPackage, callingFeatureId, |
| 3366 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3367 | return null; |
| 3368 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3369 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3370 | final long identity = Binder.clearCallingIdentity(); |
| 3371 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3372 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(identity); |
| 3375 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3379 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3380 | VisualVoicemailSmsFilterSettings settings) { |
| 3381 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3382 | |
| 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3386 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | } finally { |
| 3388 | Binder.restoreCallingIdentity(identity); |
| 3389 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3393 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3395 | |
| 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3399 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3400 | } finally { |
| 3401 | Binder.restoreCallingIdentity(identity); |
| 3402 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3406 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3407 | String callingPackage, int subId) { |
| 3408 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3409 | |
| 3410 | final long identity = Binder.clearCallingIdentity(); |
| 3411 | try { |
| 3412 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3413 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(identity); |
| 3416 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3420 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3421 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3422 | |
| 3423 | final long identity = Binder.clearCallingIdentity(); |
| 3424 | try { |
| 3425 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3426 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
| 3429 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3433 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3434 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3435 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3436 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3437 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3438 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3439 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3440 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3441 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3442 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3443 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3444 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3445 | * Sets the voice activation state of a given subId. |
| 3446 | */ |
| 3447 | @Override |
| 3448 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3450 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3451 | |
| 3452 | final long identity = Binder.clearCallingIdentity(); |
| 3453 | try { |
| 3454 | final Phone phone = getPhone(subId); |
| 3455 | if (phone != null) { |
| 3456 | phone.setVoiceActivationState(activationState); |
| 3457 | } else { |
| 3458 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3459 | } |
| 3460 | } finally { |
| 3461 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3462 | } |
| 3463 | } |
| 3464 | |
| 3465 | /** |
| 3466 | * Sets the data activation state of a given subId. |
| 3467 | */ |
| 3468 | @Override |
| 3469 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3471 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | |
| 3473 | final long identity = Binder.clearCallingIdentity(); |
| 3474 | try { |
| 3475 | final Phone phone = getPhone(subId); |
| 3476 | if (phone != null) { |
| 3477 | phone.setDataActivationState(activationState); |
| 3478 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3479 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3480 | } |
| 3481 | } finally { |
| 3482 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | /** |
| 3487 | * Returns the voice activation state of a given subId. |
| 3488 | */ |
| 3489 | @Override |
| 3490 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3491 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3493 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3494 | final long identity = Binder.clearCallingIdentity(); |
| 3495 | try { |
| 3496 | if (phone != null) { |
| 3497 | return phone.getVoiceActivationState(); |
| 3498 | } else { |
| 3499 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3500 | } |
| 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | /** |
| 3507 | * Returns the data activation state of a given subId. |
| 3508 | */ |
| 3509 | @Override |
| 3510 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3512 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3513 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3514 | final long identity = Binder.clearCallingIdentity(); |
| 3515 | try { |
| 3516 | if (phone != null) { |
| 3517 | return phone.getDataActivationState(); |
| 3518 | } else { |
| 3519 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3520 | } |
| 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3527 | * Returns the unread count of voicemails for a subId |
| 3528 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3529 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3530 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3531 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3533 | mApp, subId, callingPackage, callingFeatureId, |
| 3534 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3535 | return 0; |
| 3536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
| 3539 | final Phone phone = getPhone(subId); |
| 3540 | if (phone != null) { |
| 3541 | return phone.getVoiceMessageCount(); |
| 3542 | } else { |
| 3543 | return 0; |
| 3544 | } |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3547 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3551 | * returns true, if the device is in a state where both voice and data |
| 3552 | * are supported simultaneously. This can change based on location or network condition. |
| 3553 | */ |
| 3554 | @Override |
| 3555 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3556 | final long identity = Binder.clearCallingIdentity(); |
| 3557 | try { |
| 3558 | final Phone phone = getPhone(subId); |
| 3559 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3560 | } finally { |
| 3561 | Binder.restoreCallingIdentity(identity); |
| 3562 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3563 | } |
| 3564 | |
| 3565 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3566 | * Send the dialer code if called from the current default dialer or the caller has |
| 3567 | * carrier privilege. |
| 3568 | * @param inputCode The dialer code to send |
| 3569 | */ |
| 3570 | @Override |
| 3571 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3572 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3573 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3574 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3575 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3576 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3577 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3578 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3579 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3580 | |
| 3581 | final long identity = Binder.clearCallingIdentity(); |
| 3582 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3583 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
| 3586 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3589 | @Override |
| 3590 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3591 | TelephonyPermissions |
| 3592 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3593 | mApp, subId, "getNetworkSelectionMode"); |
| 3594 | final long identity = Binder.clearCallingIdentity(); |
| 3595 | try { |
| 3596 | if (!isActiveSubscription(subId)) { |
| 3597 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3598 | } |
| 3599 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3602 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3606 | public boolean isInEmergencySmsMode() { |
| 3607 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3608 | final long identity = Binder.clearCallingIdentity(); |
| 3609 | try { |
| 3610 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3611 | if (phone.isInEmergencySmsMode()) { |
| 3612 | return true; |
| 3613 | } |
| 3614 | } |
| 3615 | } finally { |
| 3616 | Binder.restoreCallingIdentity(identity); |
| 3617 | } |
| 3618 | return false; |
| 3619 | } |
| 3620 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3621 | /** |
| 3622 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3623 | * @param subId The subscription to use to check the configuration. |
| 3624 | * @param c The callback that will be used to send the result. |
| 3625 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3626 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3627 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3628 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3629 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3630 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3631 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3632 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3633 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3634 | "IMS not available on device."); |
| 3635 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3636 | final long token = Binder.clearCallingIdentity(); |
| 3637 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3638 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3639 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3640 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3641 | } catch (ImsException e) { |
| 3642 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(token); |
| 3645 | } |
| 3646 | } |
| 3647 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3648 | /** |
| 3649 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3650 | * @param subId The subscription to use to check the configuration. |
| 3651 | * @param c The callback that will be used to send the result. |
| 3652 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3653 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3654 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3655 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3656 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3657 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3658 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3659 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3660 | final long token = Binder.clearCallingIdentity(); |
| 3661 | try { |
| 3662 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3663 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3664 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3665 | } catch (ImsException e) { |
| 3666 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3667 | + "is inactive, ignoring unregister."); |
| 3668 | // If the subscription is no longer active, just return, since the callback |
| 3669 | // will already have been removed internally. |
| 3670 | } finally { |
| 3671 | Binder.restoreCallingIdentity(token); |
| 3672 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3673 | } |
| 3674 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3675 | /** |
| 3676 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3677 | */ |
| 3678 | @Override |
| 3679 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3680 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3681 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3683 | "IMS not available on device."); |
| 3684 | } |
| 3685 | final long token = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | Phone phone = getPhone(subId); |
| 3688 | if (phone == null) { |
| 3689 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3690 | + subId + "'"); |
| 3691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3692 | } |
| 3693 | phone.getImsRegistrationState(regState -> { |
| 3694 | try { |
| 3695 | consumer.accept((regState == null) |
| 3696 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3697 | } catch (RemoteException e) { |
| 3698 | // Ignore if the remote process is no longer available to call back. |
| 3699 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3700 | } |
| 3701 | }); |
| 3702 | } finally { |
| 3703 | Binder.restoreCallingIdentity(token); |
| 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | /** |
| 3708 | * Get the transport type for the IMS service registration state. |
| 3709 | */ |
| 3710 | @Override |
| 3711 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3712 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3713 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3714 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3715 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3716 | "IMS not available on device."); |
| 3717 | } |
| 3718 | final long token = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | Phone phone = getPhone(subId); |
| 3721 | if (phone == null) { |
| 3722 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3723 | + subId + "'"); |
| 3724 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3725 | } |
| 3726 | phone.getImsRegistrationTech(regTech -> { |
| 3727 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3728 | int regTechConverted = (regTech == null) |
| 3729 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3730 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3731 | regTechConverted); |
| 3732 | try { |
| 3733 | consumer.accept(regTechConverted); |
| 3734 | } catch (RemoteException e) { |
| 3735 | // Ignore if the remote process is no longer available to call back. |
| 3736 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3737 | } |
| 3738 | }); |
| 3739 | } finally { |
| 3740 | Binder.restoreCallingIdentity(token); |
| 3741 | } |
| 3742 | } |
| 3743 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3744 | /** |
| 3745 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3746 | * @param subId The subscription to use to check the configuration. |
| 3747 | * @param c The callback that will be used to send the result. |
| 3748 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3749 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3750 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3751 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3752 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3753 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3754 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3756 | "IMS not available on device."); |
| 3757 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3758 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3759 | final long token = Binder.clearCallingIdentity(); |
| 3760 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3761 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3763 | } catch (ImsException e) { |
| 3764 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3765 | } finally { |
| 3766 | Binder.restoreCallingIdentity(token); |
| 3767 | } |
| 3768 | } |
| 3769 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3770 | /** |
| 3771 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3772 | * @param subId The subscription to use to check the configuration. |
| 3773 | * @param c The callback that will be used to send the result. |
| 3774 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3775 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3776 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3777 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3778 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3779 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3780 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3781 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3782 | |
| 3783 | final long token = Binder.clearCallingIdentity(); |
| 3784 | try { |
| 3785 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3786 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3787 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3788 | } catch (ImsException e) { |
| 3789 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3790 | + "is inactive, ignoring unregister."); |
| 3791 | // If the subscription is no longer active, just return, since the callback |
| 3792 | // will already have been removed internally. |
| 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(token); |
| 3795 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3799 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3800 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3801 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3802 | final long token = Binder.clearCallingIdentity(); |
| 3803 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3804 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3805 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3806 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3807 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3808 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3809 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3810 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3811 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(token); |
| 3814 | } |
| 3815 | } |
| 3816 | |
| 3817 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3818 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3819 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3820 | final long token = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | Phone phone = getPhone(subId); |
| 3823 | if (phone == null) return false; |
| 3824 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3825 | } catch (com.android.ims.ImsException e) { |
| 3826 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3827 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(token); |
| 3830 | } |
| 3831 | } |
| 3832 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3833 | /** |
| 3834 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3835 | * subscription. |
| 3836 | * @param subId The subscription to use to check the configuration. |
| 3837 | * @param callback The callback that will be used to send the result. |
| 3838 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3839 | * @param transportType The transport type of the MmTelFeature capability. |
| 3840 | */ |
| 3841 | @Override |
| 3842 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3843 | int transportType) { |
| 3844 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3845 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3846 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3847 | "IMS not available on device."); |
| 3848 | } |
| 3849 | final long token = Binder.clearCallingIdentity(); |
| 3850 | try { |
| 3851 | int slotId = getSlotIndex(subId); |
| 3852 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3853 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3854 | + subId + "'"); |
| 3855 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3856 | } |
| 3857 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3858 | transportType, aBoolean -> { |
| 3859 | try { |
| 3860 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3861 | } catch (RemoteException e) { |
| 3862 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3863 | + "running. Ignore"); |
| 3864 | } |
| 3865 | }); |
| 3866 | } finally { |
| 3867 | Binder.restoreCallingIdentity(token); |
| 3868 | } |
| 3869 | } |
| 3870 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3871 | /** |
| 3872 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3873 | * @param subId The subscription to use to check the configuration. |
| 3874 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3875 | @Override |
| 3876 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3877 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3878 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3879 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3881 | final long token = Binder.clearCallingIdentity(); |
| 3882 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3883 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3885 | } catch (ImsException e) { |
| 3886 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3887 | } finally { |
| 3888 | Binder.restoreCallingIdentity(token); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3893 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3895 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3899 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3901 | } catch (ImsException e) { |
| 3902 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
| 3905 | } |
| 3906 | } |
| 3907 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3908 | /** |
| 3909 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3910 | * @param subId The subscription to use to check the configuration. |
| 3911 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3912 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3913 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3914 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3915 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
| 3918 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3919 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3920 | } catch (ImsException e) { |
| 3921 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3922 | } finally { |
| 3923 | Binder.restoreCallingIdentity(identity); |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3928 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3929 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3930 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3931 | final long identity = Binder.clearCallingIdentity(); |
| 3932 | try { |
| 3933 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3934 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3935 | } catch (ImsException e) { |
| 3936 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3937 | } finally { |
| 3938 | Binder.restoreCallingIdentity(identity); |
| 3939 | } |
| 3940 | } |
| 3941 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3942 | /** |
| 3943 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3944 | * @param subId The subscription to use to check the configuration. |
| 3945 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3946 | @Override |
| 3947 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3948 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3949 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
| 3952 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3953 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3954 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3955 | } catch (ImsException e) { |
| 3956 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3963 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3964 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3965 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | final long identity = Binder.clearCallingIdentity(); |
| 3967 | try { |
| 3968 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3969 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3970 | } catch (ImsException e) { |
| 3971 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(identity); |
| 3974 | } |
| 3975 | } |
| 3976 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3977 | /** |
| 3978 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3979 | * @param subId The subscription to use to check the configuration. |
| 3980 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3981 | @Override |
| 3982 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3983 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3984 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | final long identity = Binder.clearCallingIdentity(); |
| 3986 | try { |
| 3987 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3988 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3990 | } catch (ImsException e) { |
| 3991 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | } finally { |
| 3993 | Binder.restoreCallingIdentity(identity); |
| 3994 | } |
| 3995 | } |
| 3996 | |
| 3997 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3998 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4000 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | final long identity = Binder.clearCallingIdentity(); |
| 4002 | try { |
| 4003 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4004 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4006 | } catch (ImsException e) { |
| 4007 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4008 | } finally { |
| 4009 | Binder.restoreCallingIdentity(identity); |
| 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | @Override |
| 4014 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4016 | "setVoWiFiNonPersistent"); |
| 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
| 4019 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4020 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4021 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4022 | } catch (ImsException e) { |
| 4023 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
| 4026 | } |
| 4027 | } |
| 4028 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4029 | /** |
| 4030 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4031 | * @param subId The subscription to use to check the configuration. |
| 4032 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4033 | @Override |
| 4034 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4035 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4036 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | final long identity = Binder.clearCallingIdentity(); |
| 4038 | try { |
| 4039 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4040 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4042 | } catch (ImsException e) { |
| 4043 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4044 | } finally { |
| 4045 | Binder.restoreCallingIdentity(identity); |
| 4046 | } |
| 4047 | } |
| 4048 | |
| 4049 | @Override |
| 4050 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4052 | "setVoWiFiModeSetting"); |
| 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4056 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4057 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4058 | } catch (ImsException e) { |
| 4059 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | } finally { |
| 4061 | Binder.restoreCallingIdentity(identity); |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | @Override |
| 4066 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4067 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
| 4070 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4071 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4072 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4073 | } catch (ImsException e) { |
| 4074 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | } finally { |
| 4076 | Binder.restoreCallingIdentity(identity); |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | @Override |
| 4081 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4083 | "setVoWiFiRoamingModeSetting"); |
| 4084 | final long identity = Binder.clearCallingIdentity(); |
| 4085 | try { |
| 4086 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4087 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4088 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4089 | } catch (ImsException e) { |
| 4090 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
| 4094 | } |
| 4095 | |
| 4096 | @Override |
| 4097 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4099 | "setRttCapabilityEnabled"); |
| 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4103 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4104 | } catch (ImsException e) { |
| 4105 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(identity); |
| 4108 | } |
| 4109 | } |
| 4110 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4111 | /** |
| 4112 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4113 | * @param subId The subscription to use to check the configuration. |
| 4114 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | @Override |
| 4116 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4117 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4118 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4119 | final long identity = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4122 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4123 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4124 | } catch (ImsException e) { |
| 4125 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | } finally { |
| 4127 | Binder.restoreCallingIdentity(identity); |
| 4128 | } |
| 4129 | } |
| 4130 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4131 | @Override |
| 4132 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4133 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4134 | final long identity = Binder.clearCallingIdentity(); |
| 4135 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4136 | if (!isImsAvailableOnDevice()) { |
| 4137 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4138 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4139 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4140 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4142 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4143 | } catch (ImsException e) { |
| 4144 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4145 | } finally { |
| 4146 | Binder.restoreCallingIdentity(identity); |
| 4147 | } |
| 4148 | } |
| 4149 | |
| 4150 | @Override |
| 4151 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4152 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4153 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4154 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4155 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4156 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4157 | try { |
| 4158 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4159 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4160 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4161 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4162 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4163 | + "is inactive, ignoring unregister."); |
| 4164 | // If the subscription is no longer active, just return, since the callback will already |
| 4165 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4166 | } finally { |
| 4167 | Binder.restoreCallingIdentity(identity); |
| 4168 | } |
| 4169 | } |
| 4170 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4171 | |
| 4172 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4174 | message); |
| 4175 | } |
| 4176 | |
| 4177 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4178 | boolean isMmtelCapability) { |
| 4179 | Phone phone = getPhone(subId); |
| 4180 | if (phone == null) { |
| 4181 | loge("phone instance null for subid " + subId); |
| 4182 | return false; |
| 4183 | } |
| 4184 | if (isMmtelCapability) { |
| 4185 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4186 | return false; |
| 4187 | } |
| 4188 | } else { |
| 4189 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4190 | return false; |
| 4191 | } |
| 4192 | } |
| 4193 | return true; |
| 4194 | } |
| 4195 | |
| 4196 | @Override |
| 4197 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4198 | boolean isProvisioned) { |
| 4199 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4200 | |
| 4201 | final long identity = Binder.clearCallingIdentity(); |
| 4202 | try { |
| 4203 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4204 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4205 | return; |
| 4206 | } |
| 4207 | |
| 4208 | // this capability requires provisioning, route to the correct API. |
| 4209 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4210 | switch (capability) { |
| 4211 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4212 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4213 | ims.setEabProvisioned(isProvisioned); |
| 4214 | break; |
| 4215 | default: { |
| 4216 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4217 | + "rcs capability '" + capability + "', which does not require " |
| 4218 | + "provisioning."); |
| 4219 | } |
| 4220 | } |
| 4221 | } finally { |
| 4222 | Binder.restoreCallingIdentity(identity); |
| 4223 | } |
| 4224 | |
| 4225 | } |
| 4226 | |
| 4227 | |
| 4228 | @Override |
| 4229 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4230 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4231 | final long identity = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4234 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4235 | return true; |
| 4236 | } |
| 4237 | |
| 4238 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4239 | switch (capability) { |
| 4240 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4241 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4242 | return ims.isEabProvisionedOnDevice(); |
| 4243 | |
| 4244 | default: { |
| 4245 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4246 | + "capability '" + capability + "', which does not require " |
| 4247 | + "provisioning."); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | } finally { |
| 4252 | Binder.restoreCallingIdentity(identity); |
| 4253 | } |
| 4254 | } |
| 4255 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4256 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4257 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4258 | boolean isProvisioned) { |
| 4259 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4260 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4261 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4262 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4263 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4264 | final long identity = Binder.clearCallingIdentity(); |
| 4265 | try { |
| 4266 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4267 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4268 | return; |
| 4269 | } |
| 4270 | |
| 4271 | // this capability requires provisioning, route to the correct API. |
| 4272 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4273 | switch (capability) { |
| 4274 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4275 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4276 | ims.setVolteProvisioned(isProvisioned); |
| 4277 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4278 | ims.setWfcProvisioned(isProvisioned); |
| 4279 | } |
| 4280 | break; |
| 4281 | } |
| 4282 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4283 | // There is currently no difference in VT provisioning type. |
| 4284 | ims.setVtProvisioned(isProvisioned); |
| 4285 | break; |
| 4286 | } |
| 4287 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4288 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4289 | // change the capability of the feature instead if needed. |
| 4290 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4291 | == isProvisioned) { |
| 4292 | // No change in provisioning. |
| 4293 | return; |
| 4294 | } |
| 4295 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4296 | try { |
| 4297 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4298 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4299 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4300 | + ", Exception" + e.getMessage()); |
| 4301 | } |
| 4302 | break; |
| 4303 | } |
| 4304 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4305 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4306 | + "MmTel capability '" + capability + "', which does not require " |
| 4307 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | } finally { |
| 4312 | Binder.restoreCallingIdentity(identity); |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | @Override |
| 4317 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4318 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4319 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4320 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4321 | } |
| 4322 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4323 | final long identity = Binder.clearCallingIdentity(); |
| 4324 | try { |
| 4325 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4326 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4327 | return true; |
| 4328 | } |
| 4329 | |
| 4330 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4331 | switch (capability) { |
| 4332 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4333 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4334 | return ims.isVolteProvisionedOnDevice(); |
| 4335 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4336 | return ims.isWfcProvisionedOnDevice(); |
| 4337 | } |
| 4338 | // This should never happen, since we are checking tech above to make sure it |
| 4339 | // is either LTE or IWLAN. |
| 4340 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4341 | + "capability."); |
| 4342 | } |
| 4343 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4344 | // There is currently no difference in VT provisioning type. |
| 4345 | return ims.isVtProvisionedOnDevice(); |
| 4346 | } |
| 4347 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4348 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4349 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4350 | } |
| 4351 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4352 | throw new IllegalArgumentException( |
| 4353 | "Tried to get provisioning for MmTel capability '" + capability |
| 4354 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4355 | } |
| 4356 | } |
| 4357 | |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(identity); |
| 4360 | } |
| 4361 | } |
| 4362 | |
| 4363 | @Override |
| 4364 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4365 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4366 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4367 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4368 | } |
| 4369 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4370 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4371 | return (provisionedBits & capability) > 0; |
| 4372 | } |
| 4373 | |
| 4374 | @Override |
| 4375 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4376 | boolean isProvisioned) { |
| 4377 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4378 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4379 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4380 | } |
| 4381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4382 | "setProvisioningStatusForCapability"); |
| 4383 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4384 | // If the current provisioning status for capability already matches isProvisioned, |
| 4385 | // do nothing. |
| 4386 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4387 | return; |
| 4388 | } |
| 4389 | if (isProvisioned) { |
| 4390 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4391 | } else { |
| 4392 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4393 | } |
| 4394 | } |
| 4395 | |
| 4396 | /** |
| 4397 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4398 | * technology. The bitfield should mirror the bitfield defined by |
| 4399 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4400 | */ |
| 4401 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4402 | String key = getMmTelProvisioningKey(subId, tech); |
| 4403 | // Default is no capabilities are provisioned. |
| 4404 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4409 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4410 | * technology specified. |
| 4411 | * |
| 4412 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4413 | */ |
| 4414 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4415 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4416 | String key = getMmTelProvisioningKey(subId, tech); |
| 4417 | editor.putInt(key, newField); |
| 4418 | editor.commit(); |
| 4419 | } |
| 4420 | |
| 4421 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4422 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4423 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4428 | * carrier associated with the subscription id. |
| 4429 | */ |
| 4430 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4431 | int capability) { |
| 4432 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4433 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4434 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4435 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4436 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4437 | false); |
| 4438 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4439 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4440 | |
| 4441 | // First check to make sure that the capability requires provisioning. |
| 4442 | switch (capability) { |
| 4443 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4444 | // intentional fallthrough |
| 4445 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4446 | if (requireVoiceVtProvisioning) { |
| 4447 | // Voice and Video requires provisioning |
| 4448 | return true; |
| 4449 | } |
| 4450 | break; |
| 4451 | } |
| 4452 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4453 | if (requireUtProvisioning) { |
| 4454 | // UT requires provisioning |
| 4455 | return true; |
| 4456 | } |
| 4457 | break; |
| 4458 | } |
| 4459 | } |
| 4460 | return false; |
| 4461 | } |
| 4462 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4463 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4464 | int capability) { |
| 4465 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4466 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4467 | |
| 4468 | boolean requireRcsProvisioning = c.getBoolean( |
| 4469 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4470 | |
| 4471 | // First check to make sure that the capability requires provisioning. |
| 4472 | switch (capability) { |
| 4473 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4474 | // intentional fallthrough |
| 4475 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4476 | if (requireRcsProvisioning) { |
| 4477 | // OPTION or PRESENCE requires provisioning |
| 4478 | return true; |
| 4479 | } |
| 4480 | break; |
| 4481 | } |
| 4482 | } |
| 4483 | return false; |
| 4484 | } |
| 4485 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4486 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4487 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4488 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4489 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4490 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4491 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4492 | final long identity = Binder.clearCallingIdentity(); |
| 4493 | try { |
| 4494 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4495 | int slotId = getSlotIndex(subId); |
| 4496 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4497 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4498 | + subId + "' for key:" + key); |
| 4499 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4500 | } |
| 4501 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4502 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4503 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4504 | + subId + "' for key:" + key); |
| 4505 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | @Override |
| 4512 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4513 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4514 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4515 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4516 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4517 | final long identity = Binder.clearCallingIdentity(); |
| 4518 | try { |
| 4519 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4520 | int slotId = getSlotIndex(subId); |
| 4521 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4522 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4523 | + subId + "' for key:" + key); |
| 4524 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4525 | } |
| 4526 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4527 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4528 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4529 | + subId + "' for key:" + key); |
| 4530 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4531 | } finally { |
| 4532 | Binder.restoreCallingIdentity(identity); |
| 4533 | } |
| 4534 | } |
| 4535 | |
| 4536 | @Override |
| 4537 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4538 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4539 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4540 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4541 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4542 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4543 | final long identity = Binder.clearCallingIdentity(); |
| 4544 | try { |
| 4545 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4546 | int slotId = getSlotIndex(subId); |
| 4547 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4548 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4549 | + subId + "' for key:" + key); |
| 4550 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4551 | } |
| 4552 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4553 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4554 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4555 | + "' for key:" + key); |
| 4556 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4557 | } finally { |
| 4558 | Binder.restoreCallingIdentity(identity); |
| 4559 | } |
| 4560 | } |
| 4561 | |
| 4562 | @Override |
| 4563 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4564 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4565 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4566 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4568 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4569 | final long identity = Binder.clearCallingIdentity(); |
| 4570 | try { |
| 4571 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4572 | int slotId = getSlotIndex(subId); |
| 4573 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4574 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4575 | + subId + "' for key:" + key); |
| 4576 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4577 | } |
| 4578 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4579 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4580 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4581 | + "' for key:" + key); |
| 4582 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4583 | } finally { |
| 4584 | Binder.restoreCallingIdentity(identity); |
| 4585 | } |
| 4586 | } |
| 4587 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4588 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4589 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4590 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4591 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4592 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4593 | } |
| 4594 | return slotId; |
| 4595 | } |
| 4596 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4597 | private int getSlotIndex(int subId) { |
| 4598 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4599 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4600 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4601 | } |
| 4602 | return slotId; |
| 4603 | } |
| 4604 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4605 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4606 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4607 | */ |
| 4608 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4609 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4610 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4611 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4612 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4613 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4614 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4615 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4616 | mApp, subId, callingPackage, callingFeatureId, |
| 4617 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4618 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4619 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | final long identity = Binder.clearCallingIdentity(); |
| 4622 | try { |
| 4623 | final Phone phone = getPhone(subId); |
| 4624 | if (phone != null) { |
| 4625 | return phone.getServiceState().getDataNetworkType(); |
| 4626 | } else { |
| 4627 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4628 | } |
| 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4631 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | /** |
| 4635 | * Returns the data network type |
| 4636 | */ |
| 4637 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4638 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4639 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4640 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | /** |
| 4644 | * Returns the data network type for a subId |
| 4645 | */ |
| 4646 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4647 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4648 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4650 | mApp, subId, callingPackage, callingFeatureId, |
| 4651 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4652 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4653 | } |
| 4654 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4655 | final long identity = Binder.clearCallingIdentity(); |
| 4656 | try { |
| 4657 | final Phone phone = getPhone(subId); |
| 4658 | if (phone != null) { |
| 4659 | return phone.getServiceState().getDataNetworkType(); |
| 4660 | } else { |
| 4661 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4662 | } |
| 4663 | } finally { |
| 4664 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4665 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4669 | * Returns the Voice network type for a subId |
| 4670 | */ |
| 4671 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4672 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4673 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4674 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4675 | mApp, subId, callingPackage, callingFeatureId, |
| 4676 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4677 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4678 | } |
| 4679 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4680 | final long identity = Binder.clearCallingIdentity(); |
| 4681 | try { |
| 4682 | final Phone phone = getPhone(subId); |
| 4683 | if (phone != null) { |
| 4684 | return phone.getServiceState().getVoiceNetworkType(); |
| 4685 | } else { |
| 4686 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4687 | } |
| 4688 | } finally { |
| 4689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | /** |
| 4694 | * @return true if a ICC card is present |
| 4695 | */ |
| 4696 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4697 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4698 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4699 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4703 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4704 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4705 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4706 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4707 | final long identity = Binder.clearCallingIdentity(); |
| 4708 | try { |
| 4709 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4710 | if (phone != null) { |
| 4711 | return phone.getIccCard().hasIccCard(); |
| 4712 | } else { |
| 4713 | return false; |
| 4714 | } |
| 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | /** |
| 4721 | * Return if the current radio is LTE on CDMA. This |
| 4722 | * is a tri-state return value as for a period of time |
| 4723 | * the mode may be unknown. |
| 4724 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4725 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4726 | * @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] | 4727 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4728 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4729 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4730 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4731 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4732 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4735 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4736 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4737 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4738 | try { |
| 4739 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4740 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4741 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4742 | } |
| 4743 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | final long identity = Binder.clearCallingIdentity(); |
| 4745 | try { |
| 4746 | final Phone phone = getPhone(subId); |
| 4747 | if (phone == null) { |
| 4748 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4749 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4750 | return TelephonyProperties.lte_on_cdma_device() |
| 4751 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | } |
| 4753 | } finally { |
| 4754 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4755 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4756 | } |
| 4757 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4758 | /** |
| 4759 | * {@hide} |
| 4760 | * Returns Default subId, 0 in the case of single standby. |
| 4761 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4762 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4763 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4766 | private int getSlotForDefaultSubscription() { |
| 4767 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4768 | } |
| 4769 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4770 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4771 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4772 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4773 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4774 | private boolean isActiveSubscription(int subId) { |
| 4775 | return mSubscriptionController.isActiveSubId(subId); |
| 4776 | } |
| 4777 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4778 | /** |
| 4779 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4780 | */ |
| 4781 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4782 | final long identity = Binder.clearCallingIdentity(); |
| 4783 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4784 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4786 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4787 | } finally { |
| 4788 | Binder.restoreCallingIdentity(identity); |
| 4789 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4790 | } |
| 4791 | |
| 4792 | /** |
| 4793 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4794 | */ |
| 4795 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | final long identity = Binder.clearCallingIdentity(); |
| 4797 | try { |
| 4798 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4799 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4800 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4804 | } |
| 4805 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4806 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4807 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4808 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4809 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4810 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4811 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4812 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4813 | if (phoneId == -1) { |
| 4814 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4815 | + " does not correspond to an active phone"); |
| 4816 | } |
| 4817 | return PhoneFactory.getPhone(phoneId); |
| 4818 | } |
| 4819 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4820 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4821 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4822 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4823 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4824 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4825 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4826 | if (DBG) { |
| 4827 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4828 | } |
| 4829 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4830 | p2); |
| 4831 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4832 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4833 | |
| 4834 | @Override |
| 4835 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4836 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4837 | enforceModifyPermission(); |
| 4838 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4839 | if (DBG) { |
| 4840 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4841 | } |
| 4842 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4843 | callingPackage, aid, p2); |
| 4844 | } |
| 4845 | |
| 4846 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4847 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 | final long identity = Binder.clearCallingIdentity(); |
| 4849 | try { |
| 4850 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4851 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4852 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4853 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4854 | if (bestComponent == null |
| 4855 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4856 | loge("The calling package is not allowed to access ISD-R."); |
| 4857 | throw new SecurityException( |
| 4858 | "The calling package is not allowed to access ISD-R."); |
| 4859 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4860 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4861 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4862 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4863 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4864 | null /* workSource */); |
| 4865 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | return response; |
| 4867 | } finally { |
| 4868 | Binder.restoreCallingIdentity(identity); |
| 4869 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4873 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4875 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4876 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4877 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4878 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4879 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4880 | @Override |
| 4881 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4882 | enforceModifyPermission(); |
| 4883 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4884 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4885 | channel); |
| 4886 | } |
| 4887 | |
| 4888 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | if (channel < 0) { |
| 4892 | return false; |
| 4893 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4894 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4895 | null /* workSource */); |
| 4896 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | return success; |
| 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4900 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
| 4903 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4904 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4905 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4907 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4908 | if (DBG) { |
| 4909 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4910 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4911 | + p3 + " data=" + data); |
| 4912 | } |
| 4913 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4914 | command, p1, p2, p3, data); |
| 4915 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4916 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4917 | @Override |
| 4918 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4919 | int command, int p1, int p2, int p3, String data) { |
| 4920 | enforceModifyPermission(); |
| 4921 | if (DBG) { |
| 4922 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4923 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4924 | + p3 + " data=" + data); |
| 4925 | } |
| 4926 | return iccTransmitApduLogicalChannelWithPermission( |
| 4927 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4928 | data); |
| 4929 | } |
| 4930 | |
| 4931 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4932 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4935 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | return ""; |
| 4937 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4938 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4940 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4941 | null /* workSource */); |
| 4942 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | // Append the returned status code to the end of the response payload. |
| 4945 | String s = Integer.toHexString( |
| 4946 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4947 | if (response.payload != null) { |
| 4948 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4949 | } |
| 4950 | return s; |
| 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4953 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4954 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4955 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4956 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4957 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4958 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4960 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4961 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4962 | if (DBG) { |
| 4963 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4964 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4965 | } |
| 4966 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4967 | cla, command, p1, p2, p3, data); |
| 4968 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4969 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4970 | @Override |
| 4971 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4972 | int command, int p1, int p2, int p3, String data) { |
| 4973 | enforceModifyPermission(); |
| 4974 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4975 | if (DBG) { |
| 4976 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4977 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4978 | + " data=" + data); |
| 4979 | } |
| 4980 | |
| 4981 | return iccTransmitApduBasicChannelWithPermission( |
| 4982 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4983 | p2, p3, data); |
| 4984 | } |
| 4985 | |
| 4986 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4987 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4988 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
| 4991 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4992 | && TextUtils.equals(ISDR_AID, data)) { |
| 4993 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4994 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4995 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | if (bestComponent == null |
| 4997 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4998 | loge("The calling package is not allowed to select ISD-R."); |
| 4999 | throw new SecurityException( |
| 5000 | "The calling package is not allowed to select ISD-R."); |
| 5001 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5002 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5005 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5006 | null /* workSource */); |
| 5007 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | // Append the returned status code to the end of the response payload. |
| 5010 | String s = Integer.toHexString( |
| 5011 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5012 | if (response.payload != null) { |
| 5013 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5014 | } |
| 5015 | return s; |
| 5016 | } finally { |
| 5017 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5018 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5022 | 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] | 5023 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5024 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5025 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5027 | final long identity = Binder.clearCallingIdentity(); |
| 5028 | try { |
| 5029 | if (DBG) { |
| 5030 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5031 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5032 | } |
| 5033 | |
| 5034 | IccIoResult response = |
| 5035 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5036 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5037 | subId); |
| 5038 | |
| 5039 | if (DBG) { |
| 5040 | log("Exchange SIM_IO [R]" + response); |
| 5041 | } |
| 5042 | |
| 5043 | byte[] result = null; |
| 5044 | int length = 2; |
| 5045 | if (response.payload != null) { |
| 5046 | length = 2 + response.payload.length; |
| 5047 | result = new byte[length]; |
| 5048 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5049 | } else { |
| 5050 | result = new byte[length]; |
| 5051 | } |
| 5052 | |
| 5053 | result[length - 1] = (byte) response.sw2; |
| 5054 | result[length - 2] = (byte) response.sw1; |
| 5055 | return result; |
| 5056 | } finally { |
| 5057 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5058 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5059 | } |
| 5060 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5061 | /** |
| 5062 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5063 | * on a particular subscription |
| 5064 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5065 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5066 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5068 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5069 | return null; |
| 5070 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5071 | |
| 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
| 5074 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5075 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5076 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5077 | return null; |
| 5078 | } |
| 5079 | Object response = sendRequest( |
| 5080 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5081 | if (response instanceof String[]) { |
| 5082 | return (String[]) response; |
| 5083 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5084 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5086 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5089 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5092 | /** |
| 5093 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5094 | * subscription. |
| 5095 | * |
| 5096 | * @param subId the id of the subscription. |
| 5097 | * @param appType the uicc app type, must be USIM or SIM. |
| 5098 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5099 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5100 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5101 | * @return number of fplmns that is successfully written to the SIM. |
| 5102 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5103 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5104 | String callingFeatureId) { |
| 5105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5106 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5107 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5108 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5109 | } |
| 5110 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5111 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5112 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5113 | } |
| 5114 | if (fplmns == null) { |
| 5115 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5116 | } |
| 5117 | for (String fplmn : fplmns) { |
| 5118 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5119 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5120 | } |
| 5121 | } |
| 5122 | final long identity = Binder.clearCallingIdentity(); |
| 5123 | try { |
| 5124 | Object response = sendRequest( |
| 5125 | CMD_SET_FORBIDDEN_PLMNS, |
| 5126 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5127 | subId); |
| 5128 | return (int) response; |
| 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
| 5131 | } |
| 5132 | } |
| 5133 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5134 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5135 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5137 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5139 | final long identity = Binder.clearCallingIdentity(); |
| 5140 | try { |
| 5141 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5142 | if (response.payload == null) { |
| 5143 | return ""; |
| 5144 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5145 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | // Append the returned status code to the end of the response payload. |
| 5147 | String s = Integer.toHexString( |
| 5148 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5149 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5150 | return s; |
| 5151 | } finally { |
| 5152 | Binder.restoreCallingIdentity(identity); |
| 5153 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5154 | } |
| 5155 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5156 | /** |
| 5157 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5158 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5159 | * |
| 5160 | * @param itemID the ID of the item to read |
| 5161 | * @return the NV item as a String, or null on error. |
| 5162 | */ |
| 5163 | @Override |
| 5164 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5165 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5167 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | |
| 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
| 5171 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5172 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5174 | return value; |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
| 5177 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | /** |
| 5181 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5182 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5183 | * |
| 5184 | * @param itemID the ID of the item to read |
| 5185 | * @param itemValue the value to write, as a String |
| 5186 | * @return true on success; false on any failure |
| 5187 | */ |
| 5188 | @Override |
| 5189 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5190 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5192 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | |
| 5194 | final long identity = Binder.clearCallingIdentity(); |
| 5195 | try { |
| 5196 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5197 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5198 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5199 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5200 | return success; |
| 5201 | } finally { |
| 5202 | Binder.restoreCallingIdentity(identity); |
| 5203 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5204 | } |
| 5205 | |
| 5206 | /** |
| 5207 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5208 | * Used for device configuration by some CDMA operators. |
| 5209 | * |
| 5210 | * @param preferredRoamingList byte array containing the new PRL |
| 5211 | * @return true on success; false on any failure |
| 5212 | */ |
| 5213 | @Override |
| 5214 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5215 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5216 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | |
| 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
| 5220 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5221 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5222 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5223 | return success; |
| 5224 | } finally { |
| 5225 | Binder.restoreCallingIdentity(identity); |
| 5226 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5230 | * 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] | 5231 | * Used for device configuration by some CDMA operators. |
| 5232 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5233 | * @param slotIndex - device slot. |
| 5234 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5235 | * @return true on success; false on any failure |
| 5236 | */ |
| 5237 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5238 | public boolean resetModemConfig(int slotIndex) { |
| 5239 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5240 | if (phone != null) { |
| 5241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5242 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5243 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5244 | final long identity = Binder.clearCallingIdentity(); |
| 5245 | try { |
| 5246 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5247 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5248 | return success; |
| 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5253 | return false; |
| 5254 | } |
| 5255 | |
| 5256 | /** |
| 5257 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5258 | * |
| 5259 | * @param slotIndex - device slot. |
| 5260 | * |
| 5261 | * @return true on success; false on any failure |
| 5262 | */ |
| 5263 | @Override |
| 5264 | public boolean rebootModem(int slotIndex) { |
| 5265 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5266 | if (phone != null) { |
| 5267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5268 | mApp, phone.getSubId(), "rebootModem"); |
| 5269 | |
| 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
| 5272 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5273 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5274 | return success; |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
| 5278 | } |
| 5279 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5280 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5281 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5282 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5283 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5284 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5286 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5287 | return new String[0]; |
| 5288 | } |
| 5289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | final long identity = Binder.clearCallingIdentity(); |
| 5291 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5292 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5298 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5299 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5300 | * {@link #disableIms(int)}. |
| 5301 | * @param slotIndex device slot. |
| 5302 | */ |
| 5303 | public void resetIms(int slotIndex) { |
| 5304 | enforceModifyPermission(); |
| 5305 | |
| 5306 | final long identity = Binder.clearCallingIdentity(); |
| 5307 | try { |
| 5308 | if (mImsResolver == null) { |
| 5309 | // may happen if the does not support IMS. |
| 5310 | return; |
| 5311 | } |
| 5312 | mImsResolver.disableIms(slotIndex); |
| 5313 | mImsResolver.enableIms(slotIndex); |
| 5314 | } finally { |
| 5315 | Binder.restoreCallingIdentity(identity); |
| 5316 | } |
| 5317 | } |
| 5318 | |
| 5319 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5320 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5321 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5322 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5323 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5324 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5328 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5329 | // may happen if the device does not support IMS. |
| 5330 | return; |
| 5331 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5332 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5339 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5340 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5341 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5342 | public void disableIms(int slotId) { |
| 5343 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5344 | |
| 5345 | final long identity = Binder.clearCallingIdentity(); |
| 5346 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5347 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5348 | // may happen if the device does not support IMS. |
| 5349 | return; |
| 5350 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5351 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | } finally { |
| 5353 | Binder.restoreCallingIdentity(identity); |
| 5354 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5358 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5359 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5360 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5361 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5362 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5363 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | |
| 5365 | final long identity = Binder.clearCallingIdentity(); |
| 5366 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5367 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5368 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5369 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5370 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5371 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | } finally { |
| 5373 | Binder.restoreCallingIdentity(identity); |
| 5374 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5375 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5376 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5377 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5378 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5379 | @Override |
| 5380 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5381 | enforceModifyPermission(); |
| 5382 | |
| 5383 | final long identity = Binder.clearCallingIdentity(); |
| 5384 | try { |
| 5385 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5386 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5387 | } finally { |
| 5388 | Binder.restoreCallingIdentity(identity); |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5393 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5394 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5395 | */ |
| 5396 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5397 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | |
| 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5401 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5402 | // may happen if the device does not support IMS. |
| 5403 | return null; |
| 5404 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5405 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | } finally { |
| 5407 | Binder.restoreCallingIdentity(identity); |
| 5408 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5409 | } |
| 5410 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5411 | /** |
| 5412 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5413 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5414 | */ |
| 5415 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5416 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | |
| 5418 | final long identity = Binder.clearCallingIdentity(); |
| 5419 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5420 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5421 | // may happen if the device does not support IMS. |
| 5422 | return null; |
| 5423 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5424 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5428 | } |
| 5429 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5430 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5431 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5432 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5433 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5434 | * @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] | 5435 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5436 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5437 | * @param packageName The name of the package that the current configuration will be replaced |
| 5438 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5439 | * @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] | 5440 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5441 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5442 | int[] featureTypes, String packageName) { |
| 5443 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5444 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5446 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5447 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5451 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5452 | // may happen if the device does not support IMS. |
| 5453 | return false; |
| 5454 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5455 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5456 | for (int featureType : featureTypes) { |
| 5457 | featureConfig.put(featureType, packageName); |
| 5458 | } |
| 5459 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5460 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
| 5463 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5467 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5468 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5469 | * |
| 5470 | * This should only be used for testing. |
| 5471 | * |
| 5472 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5473 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5474 | */ |
| 5475 | @Override |
| 5476 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5477 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5478 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5479 | "clearCarrierImsServiceOverride"); |
| 5480 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5481 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5482 | "clearCarrierImsServiceOverride"); |
| 5483 | |
| 5484 | final long identity = Binder.clearCallingIdentity(); |
| 5485 | try { |
| 5486 | if (mImsResolver == null) { |
| 5487 | // may happen if the device does not support IMS. |
| 5488 | return false; |
| 5489 | } |
| 5490 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5491 | } finally { |
| 5492 | Binder.restoreCallingIdentity(identity); |
| 5493 | } |
| 5494 | } |
| 5495 | |
| 5496 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5497 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5498 | * |
| 5499 | * @param slotId The slot that the ImsService is associated with. |
| 5500 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5501 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5502 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5503 | * @return the package name of the ImsService configuration. |
| 5504 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5505 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5506 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5507 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5508 | TelephonyPermissions |
| 5509 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5510 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5511 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5513 | final long identity = Binder.clearCallingIdentity(); |
| 5514 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5515 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5516 | // may happen if the device does not support IMS. |
| 5517 | return ""; |
| 5518 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5519 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5521 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
| 5524 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5527 | /** |
| 5528 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5529 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5530 | * @param callback A callback with an integer containing the |
| 5531 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5532 | */ |
| 5533 | @Override |
| 5534 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5535 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5536 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5537 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5538 | "IMS not available on device."); |
| 5539 | } |
| 5540 | final long token = Binder.clearCallingIdentity(); |
| 5541 | try { |
| 5542 | int slotId = getSlotIndex(subId); |
| 5543 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5544 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5545 | + subId + "'"); |
| 5546 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5547 | } |
| 5548 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5549 | try { |
| 5550 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5551 | } catch (RemoteException e) { |
| 5552 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5553 | + "Ignore"); |
| 5554 | } |
| 5555 | }); |
| 5556 | } finally { |
| 5557 | Binder.restoreCallingIdentity(token); |
| 5558 | } |
| 5559 | } |
| 5560 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5561 | /** |
| 5562 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5563 | */ |
| 5564 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5565 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | |
| 5567 | final long identity = Binder.clearCallingIdentity(); |
| 5568 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5569 | // NOTE: Before S, this method only set the default phone. |
| 5570 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5571 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5572 | phone.setImsRegistrationState(registered); |
| 5573 | } |
| 5574 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | } finally { |
| 5576 | Binder.restoreCallingIdentity(identity); |
| 5577 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5581 | * Set the network selection mode to automatic. |
| 5582 | * |
| 5583 | */ |
| 5584 | @Override |
| 5585 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5587 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | |
| 5589 | final long identity = Binder.clearCallingIdentity(); |
| 5590 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5591 | if (!isActiveSubscription(subId)) { |
| 5592 | return; |
| 5593 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5594 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5595 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5601 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5602 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5603 | * |
| 5604 | * @param subId the id of the subscription. |
| 5605 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5606 | * the operator to attach to. |
| 5607 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5608 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5609 | * normal network selection next time. |
| 5610 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5611 | */ |
| 5612 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5613 | public boolean setNetworkSelectionModeManual( |
| 5614 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5616 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5617 | |
| 5618 | if (!isActiveSubscription(subId)) { |
| 5619 | return false; |
| 5620 | } |
| 5621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | final long identity = Binder.clearCallingIdentity(); |
| 5623 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5624 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5626 | if (DBG) { |
| 5627 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5628 | + " operator: " + operatorInfo); |
| 5629 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5631 | } finally { |
| 5632 | Binder.restoreCallingIdentity(identity); |
| 5633 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5634 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5635 | /** |
| 5636 | * Get the manual network selection |
| 5637 | * |
| 5638 | * @param subId the id of the subscription. |
| 5639 | * |
| 5640 | * @return the previously saved user selected PLMN |
| 5641 | */ |
| 5642 | @Override |
| 5643 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5644 | TelephonyPermissions |
| 5645 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5646 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5647 | |
| 5648 | final long identity = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | if (!isActiveSubscription(subId)) { |
| 5651 | return ""; |
| 5652 | } |
| 5653 | |
| 5654 | final Phone phone = getPhone(subId); |
| 5655 | if (phone == null) { |
| 5656 | return ""; |
| 5657 | } |
| 5658 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5659 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5660 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5661 | } finally { |
| 5662 | Binder.restoreCallingIdentity(identity); |
| 5663 | } |
| 5664 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5665 | |
| 5666 | /** |
| 5667 | * Scans for available networks. |
| 5668 | */ |
| 5669 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5670 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5671 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5673 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5674 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5675 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5676 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5677 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5678 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5679 | .setCallingPid(Binder.getCallingPid()) |
| 5680 | .setCallingUid(Binder.getCallingUid()) |
| 5681 | .setMethod("getCellNetworkScanResults") |
| 5682 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5683 | .build()); |
| 5684 | switch (locationResult) { |
| 5685 | case DENIED_HARD: |
| 5686 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5687 | case DENIED_SOFT: |
| 5688 | return null; |
| 5689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5691 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | try { |
| 5693 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5694 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5695 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | } finally { |
| 5697 | Binder.restoreCallingIdentity(identity); |
| 5698 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5699 | } |
| 5700 | |
| 5701 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5702 | * Get the call forwarding info, given the call forwarding reason. |
| 5703 | */ |
| 5704 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5705 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5706 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5707 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5708 | long identity = Binder.clearCallingIdentity(); |
| 5709 | try { |
| 5710 | if (DBG) { |
| 5711 | log("getCallForwarding: subId " + subId |
| 5712 | + " callForwardingReason" + callForwardingReason); |
| 5713 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5714 | |
| 5715 | Phone phone = getPhone(subId); |
| 5716 | if (phone == null) { |
| 5717 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5718 | callback.onError( |
| 5719 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5720 | } catch (RemoteException e) { |
| 5721 | // ignore |
| 5722 | } |
| 5723 | return; |
| 5724 | } |
| 5725 | |
| 5726 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5727 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5728 | @Override |
| 5729 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5730 | try { |
| 5731 | callback.onCallForwardingInfoAvailable(info); |
| 5732 | } catch (RemoteException e) { |
| 5733 | // ignore |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | @Override |
| 5738 | public void onError(int error) { |
| 5739 | try { |
| 5740 | callback.onError(error); |
| 5741 | } catch (RemoteException e) { |
| 5742 | // ignore |
| 5743 | } |
| 5744 | } |
| 5745 | }); |
| 5746 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5747 | } finally { |
| 5748 | Binder.restoreCallingIdentity(identity); |
| 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | /** |
| 5753 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5754 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5755 | */ |
| 5756 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5757 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5758 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5759 | enforceModifyPermission(); |
| 5760 | long identity = Binder.clearCallingIdentity(); |
| 5761 | try { |
| 5762 | if (DBG) { |
| 5763 | log("setCallForwarding: subId " + subId |
| 5764 | + " callForwardingInfo" + callForwardingInfo); |
| 5765 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5766 | |
| 5767 | Phone phone = getPhone(subId); |
| 5768 | if (phone == null) { |
| 5769 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5770 | callback.accept( |
| 5771 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5772 | } catch (RemoteException e) { |
| 5773 | // ignore |
| 5774 | } |
| 5775 | return; |
| 5776 | } |
| 5777 | |
| 5778 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5779 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5780 | |
| 5781 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5782 | } finally { |
| 5783 | Binder.restoreCallingIdentity(identity); |
| 5784 | } |
| 5785 | } |
| 5786 | |
| 5787 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5788 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5789 | */ |
| 5790 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5791 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5792 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5793 | long identity = Binder.clearCallingIdentity(); |
| 5794 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5795 | |
| 5796 | Phone phone = getPhone(subId); |
| 5797 | if (phone == null) { |
| 5798 | try { |
| 5799 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5800 | } catch (RemoteException e) { |
| 5801 | // ignore |
| 5802 | } |
| 5803 | return; |
| 5804 | } |
| 5805 | |
| 5806 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5807 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5808 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5809 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5810 | } finally { |
| 5811 | Binder.restoreCallingIdentity(identity); |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5816 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5817 | */ |
| 5818 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5819 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5820 | enforceModifyPermission(); |
| 5821 | long identity = Binder.clearCallingIdentity(); |
| 5822 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5823 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5824 | |
| 5825 | Phone phone = getPhone(subId); |
| 5826 | if (phone == null) { |
| 5827 | try { |
| 5828 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5829 | } catch (RemoteException e) { |
| 5830 | // ignore |
| 5831 | } |
| 5832 | return; |
| 5833 | } |
| 5834 | |
| 5835 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5836 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5837 | |
| 5838 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5839 | } finally { |
| 5840 | Binder.restoreCallingIdentity(identity); |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5845 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5846 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5847 | * @param subId id of the subscription |
| 5848 | * @param request contains the radio access networks with bands/channels to scan |
| 5849 | * @param messenger callback messenger for scan results or errors |
| 5850 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5851 | * @return the id of the requested scan which can be used to stop the scan. |
| 5852 | */ |
| 5853 | @Override |
| 5854 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5855 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5856 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5857 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5858 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5859 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5860 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5861 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5862 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5863 | .setCallingPid(Binder.getCallingPid()) |
| 5864 | .setCallingUid(Binder.getCallingUid()) |
| 5865 | .setMethod("requestNetworkScan") |
| 5866 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5867 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5868 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5869 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5870 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5871 | if (e != null) { |
| 5872 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5873 | throw e; |
| 5874 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5875 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5876 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5877 | } |
| 5878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5880 | int callingUid = Binder.getCallingUid(); |
| 5881 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
| 5884 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5885 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5886 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5887 | } finally { |
| 5888 | Binder.restoreCallingIdentity(identity); |
| 5889 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5890 | } |
| 5891 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5892 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5893 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5894 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5895 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5896 | boolean hasNetworkScanPermission = |
| 5897 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5898 | == PERMISSION_GRANTED; |
| 5899 | |
| 5900 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5901 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5902 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5906 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5907 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5908 | return new SecurityException("Specific channels must not be" |
| 5909 | + " scanned without location access."); |
| 5910 | } |
| 5911 | } |
| 5912 | } |
| 5913 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5914 | return null; |
| 5915 | } |
| 5916 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5917 | /** |
| 5918 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5919 | * |
| 5920 | * @param subId id of the subscription |
| 5921 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5922 | */ |
| 5923 | @Override |
| 5924 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5926 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5928 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5931 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5932 | } finally { |
| 5933 | Binder.restoreCallingIdentity(identity); |
| 5934 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5938 | * Get the calculated preferred network type. |
| 5939 | * Used for debugging incorrect network type. |
| 5940 | * |
| 5941 | * @return the preferred network type, defined in RILConstants.java. |
| 5942 | */ |
| 5943 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5944 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5945 | final Phone defaultPhone = getDefaultPhone(); |
| 5946 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5947 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5948 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5949 | } |
| 5950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | final long identity = Binder.clearCallingIdentity(); |
| 5952 | try { |
| 5953 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5954 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5958 | } |
| 5959 | |
| 5960 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5961 | * Get the preferred network type. |
| 5962 | * Used for device configuration by some CDMA operators. |
| 5963 | * |
| 5964 | * @return the preferred network type, defined in RILConstants.java. |
| 5965 | */ |
| 5966 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5967 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5968 | TelephonyPermissions |
| 5969 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5970 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | |
| 5972 | final long identity = Binder.clearCallingIdentity(); |
| 5973 | try { |
| 5974 | if (DBG) log("getPreferredNetworkType"); |
| 5975 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5976 | int networkType = (result != null ? result[0] : -1); |
| 5977 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5978 | return networkType; |
| 5979 | } finally { |
| 5980 | Binder.restoreCallingIdentity(identity); |
| 5981 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | /** |
| 5985 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5986 | * |
| 5987 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5988 | * @return true on success; false on any failure. |
| 5989 | */ |
| 5990 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5991 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5992 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5993 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | |
| 5995 | final long identity = Binder.clearCallingIdentity(); |
| 5996 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5997 | Boolean success = (Boolean) sendRequest( |
| 5998 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5999 | |
| 6000 | if (success) { |
| 6001 | Settings.Global.putInt(mApp.getContentResolver(), |
| 6002 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 6003 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6004 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 6005 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | } finally { |
| 6007 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 6008 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6009 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6010 | |
| 6011 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6012 | * Get the allowed network types that store in the telephony provider. |
| 6013 | * |
| 6014 | * @param subId the id of the subscription. |
| 6015 | * @return allowedNetworkTypes the allowed network types. |
| 6016 | */ |
| 6017 | @Override |
| 6018 | public long getAllowedNetworkTypes(int subId) { |
| 6019 | TelephonyPermissions |
| 6020 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6021 | mApp, subId, "getAllowedNetworkTypes"); |
| 6022 | |
| 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
| 6025 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6026 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6027 | } finally { |
| 6028 | Binder.restoreCallingIdentity(identity); |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /** |
| 6033 | * Set the allowed network types. |
| 6034 | * |
| 6035 | * @param subId the id of the subscription. |
| 6036 | * @param allowedNetworkTypes the allowed network types. |
| 6037 | * @return true on success; false on any failure. |
| 6038 | */ |
| 6039 | @Override |
| 6040 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6041 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6042 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6043 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6044 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6045 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6046 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6047 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6048 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6049 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6050 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6051 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6052 | } |
| 6053 | |
| 6054 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6055 | * Get the allowed network types for certain reason. |
| 6056 | * |
| 6057 | * @param subId the id of the subscription. |
| 6058 | * @param reason the reason the allowed network type change is taking place |
| 6059 | * @return the allowed network types. |
| 6060 | */ |
| 6061 | @Override |
| 6062 | public long getAllowedNetworkTypesForReason(int subId, |
| 6063 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6064 | TelephonyPermissions |
| 6065 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6066 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6067 | final long identity = Binder.clearCallingIdentity(); |
| 6068 | try { |
| 6069 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6070 | } finally { |
| 6071 | Binder.restoreCallingIdentity(identity); |
| 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6076 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6077 | * @param subId subscription id of the sim card |
| 6078 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6079 | * This can be passed following states |
| 6080 | * <ol> |
| 6081 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6082 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6083 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6084 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6085 | * </ol> |
| 6086 | * @return operation result. |
| 6087 | */ |
| 6088 | @Override |
| 6089 | public int setNrDualConnectivityState(int subId, |
| 6090 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6091 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6092 | mApp, subId, "enableNRDualConnectivity"); |
| 6093 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6094 | final long identity = Binder.clearCallingIdentity(); |
| 6095 | try { |
| 6096 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6097 | nrDualConnectivityState, subId, |
| 6098 | workSource); |
| 6099 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6100 | return result; |
| 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
| 6107 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6108 | * @return true if dual connectivity is enabled else false |
| 6109 | */ |
| 6110 | @Override |
| 6111 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6112 | TelephonyPermissions |
| 6113 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6114 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6115 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6116 | final long identity = Binder.clearCallingIdentity(); |
| 6117 | try { |
| 6118 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6119 | null, subId, workSource); |
| 6120 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6121 | return isEnabled; |
| 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6128 | * get carrier bandwidth per primary and secondary carrier |
| 6129 | * @param subId subscription id of the sim card |
| 6130 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6131 | */ |
| 6132 | @Override |
| 6133 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6134 | TelephonyPermissions |
| 6135 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6136 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6137 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6138 | final long identity = Binder.clearCallingIdentity(); |
| 6139 | try { |
| 6140 | CarrierBandwidth carrierBandwidth = |
| 6141 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6142 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6143 | return carrierBandwidth; |
| 6144 | } finally { |
| 6145 | Binder.restoreCallingIdentity(identity); |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6150 | * Get the effective allowed network types on the device. |
| 6151 | * This API will return an intersection of allowed network types for all reasons, |
| 6152 | * including the configuration done through setAllowedNetworkTypes |
| 6153 | * |
| 6154 | * @param subId the id of the subscription. |
| 6155 | * @return the allowed network types |
| 6156 | */ |
| 6157 | @Override |
| 6158 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6159 | TelephonyPermissions |
| 6160 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6161 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6162 | final long identity = Binder.clearCallingIdentity(); |
| 6163 | try { |
| 6164 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | /** |
| 6171 | * Set the allowed network types of the device and |
| 6172 | * provide the reason triggering the allowed network change. |
| 6173 | * |
| 6174 | * @param subId the id of the subscription. |
| 6175 | * @param reason the reason the allowed network type change is taking place |
| 6176 | * @param allowedNetworkTypes the allowed network types. |
| 6177 | * @return true on success; false on any failure. |
| 6178 | */ |
| 6179 | @Override |
| 6180 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6181 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6183 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6184 | final long identity = Binder.clearCallingIdentity(); |
| 6185 | try { |
| 6186 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6187 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6188 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6189 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6190 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6191 | } finally { |
| 6192 | Binder.restoreCallingIdentity(identity); |
| 6193 | } |
| 6194 | } |
| 6195 | |
| 6196 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6197 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6198 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6199 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6200 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6201 | * @hide |
| 6202 | */ |
| 6203 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6204 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6205 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6207 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6209 | if (phone != null) { |
| 6210 | return phone.hasMatchedTetherApnSetting(); |
| 6211 | } else { |
| 6212 | return false; |
| 6213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | } finally { |
| 6215 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6216 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6220 | * Enable or disable always reporting signal strength changes from radio. |
| 6221 | * |
| 6222 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6223 | */ |
| 6224 | @Override |
| 6225 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6226 | enforceModifyPermission(); |
| 6227 | enforceSystemCaller(); |
| 6228 | |
| 6229 | final long identity = Binder.clearCallingIdentity(); |
| 6230 | final Phone phone = getPhone(subId); |
| 6231 | try { |
| 6232 | if (phone != null) { |
| 6233 | if (DBG) { |
| 6234 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6235 | + " isEnable=" + isEnable); |
| 6236 | } |
| 6237 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6238 | } else { |
| 6239 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6240 | + subId); |
| 6241 | } |
| 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
| 6244 | } |
| 6245 | } |
| 6246 | |
| 6247 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6248 | * Get the user enabled state of Mobile Data. |
| 6249 | * |
| 6250 | * TODO: remove and use isUserDataEnabled. |
| 6251 | * This can't be removed now because some vendor codes |
| 6252 | * calls through ITelephony directly while they should |
| 6253 | * use TelephonyManager. |
| 6254 | * |
| 6255 | * @return true on enabled |
| 6256 | */ |
| 6257 | @Override |
| 6258 | public boolean getDataEnabled(int subId) { |
| 6259 | return isUserDataEnabled(subId); |
| 6260 | } |
| 6261 | |
| 6262 | /** |
| 6263 | * Get whether mobile data is enabled per user setting. |
| 6264 | * |
| 6265 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6266 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6267 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6268 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6269 | * |
| 6270 | * @return {@code true} if data is enabled else {@code false} |
| 6271 | */ |
| 6272 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6273 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6274 | try { |
| 6275 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6276 | null); |
| 6277 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6278 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6279 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6280 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | |
| 6282 | final long identity = Binder.clearCallingIdentity(); |
| 6283 | try { |
| 6284 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6285 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6286 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6287 | if (phone != null) { |
| 6288 | boolean retVal = phone.isUserDataEnabled(); |
| 6289 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6290 | return retVal; |
| 6291 | } else { |
| 6292 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6293 | return false; |
| 6294 | } |
| 6295 | } finally { |
| 6296 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6301 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6302 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6303 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6304 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6305 | * @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] | 6306 | */ |
| 6307 | @Override |
| 6308 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6309 | try { |
| 6310 | try { |
| 6311 | mApp.enforceCallingOrSelfPermission( |
| 6312 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6313 | null); |
| 6314 | } catch (Exception e) { |
| 6315 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6316 | "isDataEnabled"); |
| 6317 | } |
| 6318 | } catch (Exception e) { |
| 6319 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6320 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | |
| 6322 | final long identity = Binder.clearCallingIdentity(); |
| 6323 | try { |
| 6324 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6325 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6326 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6327 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6328 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6330 | return retVal; |
| 6331 | } else { |
| 6332 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6333 | return false; |
| 6334 | } |
| 6335 | } finally { |
| 6336 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6337 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6338 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6339 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6340 | /** |
| 6341 | * Check if data is enabled for a specific reason |
| 6342 | * @param subId Subscription index |
| 6343 | * @param reason the reason the data enable change is taking place |
| 6344 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6345 | */ |
| 6346 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6347 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6348 | @TelephonyManager.DataEnabledReason int reason) { |
| 6349 | try { |
| 6350 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6351 | null); |
| 6352 | } catch (Exception e) { |
| 6353 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6354 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | |
| 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
| 6360 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6361 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6362 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6363 | + " reason=" + reason); |
| 6364 | } |
| 6365 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6366 | if (phone != null) { |
| 6367 | boolean retVal; |
| 6368 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6369 | retVal = phone.isUserDataEnabled(); |
| 6370 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6371 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6372 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6373 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6374 | return retVal; |
| 6375 | } else { |
| 6376 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6377 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6378 | + subId + " retVal=false"); |
| 6379 | } |
| 6380 | return false; |
| 6381 | } |
| 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
| 6385 | } |
| 6386 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6387 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6388 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6389 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6390 | // Skip the check if it's one of these special uids |
| 6391 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6392 | } |
| 6393 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6394 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6395 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6396 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6397 | || subController == null) return privilegeFromSim; |
| 6398 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6399 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6400 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6401 | |
| 6402 | final long identity = Binder.clearCallingIdentity(); |
| 6403 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6404 | int subId = phone.getSubId(); |
| 6405 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6406 | // A test override is in place for the privileges for this subId, so don't try to |
| 6407 | // read the subscription privileges. |
| 6408 | return privilegeFromSim; |
| 6409 | } |
| 6410 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6411 | SubscriptionManager subManager = (SubscriptionManager) |
| 6412 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6413 | for (String pkg : packages) { |
| 6414 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6415 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6416 | } |
| 6417 | } |
| 6418 | return privilegeFromSim; |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6425 | String pkgName) { |
| 6426 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6427 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6428 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6429 | || subController == null) return privilegeFromSim; |
| 6430 | |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6433 | int subId = phone.getSubId(); |
| 6434 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6435 | // A test override is in place for the privileges for this subId, so don't try to |
| 6436 | // read the subscription privileges. |
| 6437 | return privilegeFromSim; |
| 6438 | } |
| 6439 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6440 | SubscriptionManager subManager = (SubscriptionManager) |
| 6441 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6442 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6443 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6444 | } finally { |
| 6445 | Binder.restoreCallingIdentity(identity); |
| 6446 | } |
| 6447 | } |
| 6448 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6449 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6450 | public int getCarrierPrivilegeStatus(int subId) { |
| 6451 | final Phone phone = getPhone(subId); |
| 6452 | if (phone == null) { |
| 6453 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6454 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6455 | } |
| 6456 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6457 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6458 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6459 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6460 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6461 | |
| 6462 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6463 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6464 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6465 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6466 | |
| 6467 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6468 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6469 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6470 | final Phone phone = getPhone(subId); |
| 6471 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6472 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6473 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6474 | } |
| 6475 | UiccProfile profile = |
| 6476 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6477 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6478 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6479 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6480 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6481 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6482 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6483 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6484 | } |
| 6485 | |
| 6486 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6487 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6488 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6489 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6493 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6494 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6495 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6496 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6497 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6498 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6499 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6500 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | @Override |
| 6504 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6505 | if (TextUtils.isEmpty(pkgName)) |
| 6506 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6507 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6508 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6509 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6510 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6511 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6512 | continue; |
| 6513 | } |
| 6514 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6515 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6516 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6517 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6518 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6519 | break; |
| 6520 | } |
| 6521 | } |
| 6522 | |
| 6523 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6524 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6525 | |
| 6526 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6527 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6528 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6529 | loge("phoneId " + phoneId + " is not valid."); |
| 6530 | return null; |
| 6531 | } |
| 6532 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6533 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6534 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6535 | return null ; |
| 6536 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6537 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6538 | } |
| 6539 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6540 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6541 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6542 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6543 | List<String> privilegedPackages = new ArrayList<>(); |
| 6544 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6545 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6546 | // has UICC in that slot. |
| 6547 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6548 | if (card.hasCarrierPrivilegeRules()) { |
| 6549 | if (packages == null) { |
| 6550 | // Only check packages in user 0 for now |
| 6551 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6552 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6553 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6554 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6555 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6556 | } |
| 6557 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6558 | PackageInfo pkgInfo = packages.get(p); |
| 6559 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6560 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6561 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6562 | privilegedPackages.add(pkgInfo.packageName); |
| 6563 | } |
| 6564 | } |
| 6565 | } |
| 6566 | } |
| 6567 | return privilegedPackages; |
| 6568 | } |
| 6569 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6570 | @Override |
| 6571 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6572 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6573 | |
| 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6576 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6577 | try { |
| 6578 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6579 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6580 | } |
| 6581 | } finally { |
| 6582 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6583 | } |
| 6584 | return privilegedPackages; |
| 6585 | } |
| 6586 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6587 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6588 | final Phone phone = getPhone(subId); |
| 6589 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6590 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6591 | return null; |
| 6592 | } |
| 6593 | String iccId = card.getIccId(); |
| 6594 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6595 | return null; |
| 6596 | } |
| 6597 | return iccId; |
| 6598 | } |
| 6599 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6600 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6601 | public void setCallComposerStatus(int subId, int status) { |
| 6602 | enforceModifyPermission(); |
| 6603 | |
| 6604 | final long identity = Binder.clearCallingIdentity(); |
| 6605 | try { |
| 6606 | Phone phone = getPhone(subId); |
| 6607 | if (phone != null) { |
| 6608 | Phone defaultPhone = phone.getImsPhone(); |
| 6609 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6610 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6611 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6612 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6613 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6614 | } |
| 6615 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6616 | } catch (ImsException e) { |
| 6617 | throw new ServiceSpecificException(e.getCode()); |
| 6618 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6619 | Binder.restoreCallingIdentity(identity); |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | @Override |
| 6624 | public int getCallComposerStatus(int subId) { |
| 6625 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6626 | |
| 6627 | final long identity = Binder.clearCallingIdentity(); |
| 6628 | try { |
| 6629 | Phone phone = getPhone(subId); |
| 6630 | if (phone != null) { |
| 6631 | Phone defaultPhone = phone.getImsPhone(); |
| 6632 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6633 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6634 | return imsPhone.getCallComposerStatus(); |
| 6635 | } |
| 6636 | } |
| 6637 | } finally { |
| 6638 | Binder.restoreCallingIdentity(identity); |
| 6639 | } |
| 6640 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6641 | } |
| 6642 | |
| 6643 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6644 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6645 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6646 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6647 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6649 | final long identity = Binder.clearCallingIdentity(); |
| 6650 | try { |
| 6651 | final String iccId = getIccId(subId); |
| 6652 | final Phone phone = getPhone(subId); |
| 6653 | if (phone == null) { |
| 6654 | return false; |
| 6655 | } |
| 6656 | final String subscriberId = phone.getSubscriberId(); |
| 6657 | |
| 6658 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6659 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6660 | + subscriberId + " to " + number); |
| 6661 | } |
| 6662 | |
| 6663 | if (TextUtils.isEmpty(iccId)) { |
| 6664 | return false; |
| 6665 | } |
| 6666 | |
| 6667 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6668 | |
| 6669 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6670 | if (alphaTag == null) { |
| 6671 | editor.remove(alphaTagPrefKey); |
| 6672 | } else { |
| 6673 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6674 | } |
| 6675 | |
| 6676 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6677 | // track all merged IMSIs based on line number |
| 6678 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6679 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6680 | if (number == null) { |
| 6681 | editor.remove(numberPrefKey); |
| 6682 | editor.remove(subscriberPrefKey); |
| 6683 | } else { |
| 6684 | editor.putString(numberPrefKey, number); |
| 6685 | editor.putString(subscriberPrefKey, subscriberId); |
| 6686 | } |
| 6687 | |
| 6688 | editor.commit(); |
| 6689 | return true; |
| 6690 | } finally { |
| 6691 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6692 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
| 6695 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6696 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6697 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6698 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6700 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6701 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6702 | return null; |
| 6703 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | final long identity = Binder.clearCallingIdentity(); |
| 6706 | try { |
| 6707 | String iccId = getIccId(subId); |
| 6708 | if (iccId != null) { |
| 6709 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6710 | if (DBG_MERGE) { |
| 6711 | log("getLine1NumberForDisplay returning " |
| 6712 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6713 | } |
| 6714 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6715 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6717 | return null; |
| 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6720 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6724 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6725 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6726 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6727 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6728 | return null; |
| 6729 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6730 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | final long identity = Binder.clearCallingIdentity(); |
| 6732 | try { |
| 6733 | String iccId = getIccId(subId); |
| 6734 | if (iccId != null) { |
| 6735 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6736 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6737 | } |
| 6738 | return null; |
| 6739 | } finally { |
| 6740 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6741 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6742 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6743 | |
| 6744 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6745 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6746 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6747 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6748 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6750 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6751 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6752 | return null; |
| 6753 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6754 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6755 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6756 | // the process, where TelephonyManager was instantiated. |
| 6757 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6758 | final long identity = Binder.clearCallingIdentity(); |
| 6759 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6760 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6762 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6763 | |
| 6764 | // Figure out what subscribers are currently active |
| 6765 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6766 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6767 | // Only consider subs which match the current subId |
| 6768 | // This logic can be simplified. See b/131189269 for progress. |
| 6769 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6770 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6771 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | |
| 6773 | // First pass, find a number override for an active subscriber |
| 6774 | String mergeNumber = null; |
| 6775 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6776 | for (String key : prefs.keySet()) { |
| 6777 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6778 | final String subscriberId = (String) prefs.get(key); |
| 6779 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6780 | final String iccId = key.substring( |
| 6781 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6782 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6783 | mergeNumber = (String) prefs.get(numberKey); |
| 6784 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6785 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | + " for active subscriber " + subscriberId); |
| 6787 | } |
| 6788 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6789 | break; |
| 6790 | } |
| 6791 | } |
| 6792 | } |
| 6793 | } |
| 6794 | |
| 6795 | // Shortcut when no active merged subscribers |
| 6796 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6797 | return null; |
| 6798 | } |
| 6799 | |
| 6800 | // Second pass, find all subscribers under that line override |
| 6801 | final ArraySet<String> result = new ArraySet<>(); |
| 6802 | for (String key : prefs.keySet()) { |
| 6803 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6804 | final String number = (String) prefs.get(key); |
| 6805 | if (mergeNumber.equals(number)) { |
| 6806 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6807 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6808 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6809 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6810 | result.add(subscriberId); |
| 6811 | } |
| 6812 | } |
| 6813 | } |
| 6814 | } |
| 6815 | |
| 6816 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6817 | Arrays.sort(resultArray); |
| 6818 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6819 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6820 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6821 | } |
| 6822 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6823 | } finally { |
| 6824 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6825 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6826 | } |
| 6827 | |
| 6828 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6829 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6830 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6831 | |
| 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
| 6834 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6835 | TelephonyManager.class); |
| 6836 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6837 | if (subscriberId == null) { |
| 6838 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6839 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6840 | + subId); |
| 6841 | } |
| 6842 | return null; |
| 6843 | } |
| 6844 | |
| 6845 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6846 | .getSubscriptionInfo(subId); |
| 6847 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6848 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6849 | if (groupUuid == null) { |
| 6850 | return new String[]{subscriberId}; |
| 6851 | } |
| 6852 | |
| 6853 | // Get all subscriberIds from the group. |
| 6854 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6855 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6856 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6857 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6858 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6859 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6860 | if (subscriberId != null) { |
| 6861 | mergedSubscriberIds.add(subscriberId); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6866 | } finally { |
| 6867 | Binder.restoreCallingIdentity(identity); |
| 6868 | |
| 6869 | } |
| 6870 | } |
| 6871 | |
| 6872 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6873 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6874 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6875 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6876 | |
| 6877 | final long identity = Binder.clearCallingIdentity(); |
| 6878 | try { |
| 6879 | final Phone phone = getPhone(subId); |
| 6880 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6881 | } finally { |
| 6882 | Binder.restoreCallingIdentity(identity); |
| 6883 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6884 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6885 | |
| 6886 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6887 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6888 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6889 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6890 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6891 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6892 | |
| 6893 | final long identity = Binder.clearCallingIdentity(); |
| 6894 | try { |
| 6895 | final Phone phone = getPhone(subId); |
| 6896 | if (phone == null) { |
| 6897 | return false; |
| 6898 | } |
| 6899 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6900 | cdmaNonRoamingList); |
| 6901 | } finally { |
| 6902 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6903 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6907 | @Deprecated |
| 6908 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6909 | enforceModifyPermission(); |
| 6910 | |
| 6911 | int returnValue = 0; |
| 6912 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6913 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6914 | if(result.exception == null) { |
| 6915 | if (result.result != null) { |
| 6916 | byte[] responseData = (byte[])(result.result); |
| 6917 | if(responseData.length > oemResp.length) { |
| 6918 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6919 | responseData.length + "bytes. Buffer Size is " + |
| 6920 | oemResp.length + "bytes."); |
| 6921 | } |
| 6922 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6923 | returnValue = responseData.length; |
| 6924 | } |
| 6925 | } else { |
| 6926 | CommandException ex = (CommandException) result.exception; |
| 6927 | returnValue = ex.getCommandError().ordinal(); |
| 6928 | if(returnValue > 0) returnValue *= -1; |
| 6929 | } |
| 6930 | } catch (RuntimeException e) { |
| 6931 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6932 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6933 | if(returnValue > 0) returnValue *= -1; |
| 6934 | } |
| 6935 | |
| 6936 | return returnValue; |
| 6937 | } |
| 6938 | |
| 6939 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6940 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6941 | try { |
| 6942 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6943 | } catch (RuntimeException e) { |
| 6944 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6945 | } |
| 6946 | } |
| 6947 | |
| 6948 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6949 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6950 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6951 | try { |
| 6952 | TelephonyPermissions |
| 6953 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6954 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6955 | } catch (SecurityException e) { |
| 6956 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6957 | throw e; |
| 6958 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6959 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6960 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6961 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6962 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6963 | final long identity = Binder.clearCallingIdentity(); |
| 6964 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6965 | TelephonyPermissions |
| 6966 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6967 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6968 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6969 | } finally { |
| 6970 | Binder.restoreCallingIdentity(identity); |
| 6971 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6972 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6973 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6974 | |
| 6975 | @Override |
| 6976 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6977 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6978 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6979 | |
| 6980 | final long identity = Binder.clearCallingIdentity(); |
| 6981 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6982 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6983 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6984 | } finally { |
| 6985 | Binder.restoreCallingIdentity(identity); |
| 6986 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6990 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6991 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6992 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6993 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6994 | return false; |
| 6995 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6996 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6997 | final long identity = Binder.clearCallingIdentity(); |
| 6998 | try { |
| 6999 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7000 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7001 | // In the long run, we may instead need to check if there exists a connection service |
| 7002 | // which can support video calling. |
| 7003 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7004 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | return imsManager.isVtEnabledByPlatform() |
| 7006 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7007 | && imsManager.isVtEnabledByUser(); |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7011 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7012 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7013 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7014 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7015 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7017 | mApp, subId, callingPackage, callingFeatureId, |
| 7018 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | return false; |
| 7020 | } |
| 7021 | |
| 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
| 7024 | CarrierConfigManager configManager = |
| 7025 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7026 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7027 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7028 | } finally { |
| 7029 | Binder.restoreCallingIdentity(identity); |
| 7030 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7034 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7036 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | return false; |
| 7038 | } |
| 7039 | |
| 7040 | final long identity = Binder.clearCallingIdentity(); |
| 7041 | try { |
| 7042 | CarrierConfigManager configManager = |
| 7043 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7044 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
| 7048 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7049 | } |
| 7050 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7051 | @Override |
| 7052 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7053 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7054 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7055 | } |
| 7056 | |
| 7057 | @Override |
| 7058 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | final long identity = Binder.clearCallingIdentity(); |
| 7060 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7061 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
| 7064 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7065 | } |
| 7066 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7067 | /** |
| 7068 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7069 | * support for the feature and device firmware support. |
| 7070 | * |
| 7071 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7072 | */ |
| 7073 | @Override |
| 7074 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7076 | final Phone phone = getPhone(subscriptionId); |
| 7077 | if (phone == null) { |
| 7078 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7079 | return false; |
| 7080 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7082 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7083 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7084 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7085 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7086 | return isCarrierSupported && isDeviceSupported; |
| 7087 | } finally { |
| 7088 | Binder.restoreCallingIdentity(identity); |
| 7089 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7090 | } |
| 7091 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7092 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7093 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7094 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7095 | * 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] | 7096 | */ |
| 7097 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7100 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7101 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7102 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7103 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7104 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7105 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | } finally { |
| 7107 | Binder.restoreCallingIdentity(identity); |
| 7108 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7109 | } |
| 7110 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7111 | @Deprecated |
| 7112 | @Override |
| 7113 | public String getDeviceId(String callingPackage) { |
| 7114 | return getDeviceIdWithFeature(callingPackage, null); |
| 7115 | } |
| 7116 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7117 | /** |
| 7118 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7119 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7120 | * |
| 7121 | * <p>Requires Permission: |
| 7122 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7123 | */ |
| 7124 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7125 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7126 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7127 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7128 | return null; |
| 7129 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7130 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7131 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7132 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7133 | return null; |
| 7134 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7135 | |
| 7136 | final long identity = Binder.clearCallingIdentity(); |
| 7137 | try { |
| 7138 | return phone.getDeviceId(); |
| 7139 | } finally { |
| 7140 | Binder.restoreCallingIdentity(identity); |
| 7141 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7142 | } |
| 7143 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7144 | /** |
| 7145 | * {@hide} |
| 7146 | * Returns the IMS Registration Status on a particular subid |
| 7147 | * |
| 7148 | * @param subId |
| 7149 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7150 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7151 | Phone phone = getPhone(subId); |
| 7152 | if (phone != null) { |
| 7153 | return phone.isImsRegistered(); |
| 7154 | } else { |
| 7155 | return false; |
| 7156 | } |
| 7157 | } |
| 7158 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7159 | @Override |
| 7160 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7161 | final long identity = Binder.clearCallingIdentity(); |
| 7162 | try { |
| 7163 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7164 | } finally { |
| 7165 | Binder.restoreCallingIdentity(identity); |
| 7166 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7167 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7168 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7169 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7170 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7171 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7172 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7173 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7174 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7175 | } |
| 7176 | final long identity = Binder.clearCallingIdentity(); |
| 7177 | try { |
| 7178 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7179 | } finally { |
| 7180 | Binder.restoreCallingIdentity(identity); |
| 7181 | } |
| 7182 | } |
| 7183 | |
| 7184 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7185 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7186 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7187 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7188 | final long identity = Binder.clearCallingIdentity(); |
| 7189 | try { |
| 7190 | Phone phone = getPhone(subscriptionId); |
| 7191 | if (phone == null) { |
| 7192 | return null; |
| 7193 | } |
| 7194 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7195 | } finally { |
| 7196 | Binder.restoreCallingIdentity(identity); |
| 7197 | } |
| 7198 | } |
| 7199 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7200 | /** |
| 7201 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7202 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7203 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7204 | final long identity = Binder.clearCallingIdentity(); |
| 7205 | try { |
| 7206 | Phone phone = getPhone(subId); |
| 7207 | if (phone != null) { |
| 7208 | return phone.isWifiCallingEnabled(); |
| 7209 | } else { |
| 7210 | return false; |
| 7211 | } |
| 7212 | } finally { |
| 7213 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7214 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7215 | } |
| 7216 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7217 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7218 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7219 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7220 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7221 | final long identity = Binder.clearCallingIdentity(); |
| 7222 | try { |
| 7223 | Phone phone = getPhone(subId); |
| 7224 | if (phone != null) { |
| 7225 | return phone.isVideoEnabled(); |
| 7226 | } else { |
| 7227 | return false; |
| 7228 | } |
| 7229 | } finally { |
| 7230 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | /** |
| 7235 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7236 | * defined in {@link ImsRegistrationImplBase}. |
| 7237 | */ |
| 7238 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | final long identity = Binder.clearCallingIdentity(); |
| 7240 | try { |
| 7241 | Phone phone = getPhone(subId); |
| 7242 | if (phone != null) { |
| 7243 | return phone.getImsRegistrationTech(); |
| 7244 | } else { |
| 7245 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7246 | } |
| 7247 | } finally { |
| 7248 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7249 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7250 | } |
| 7251 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7252 | @Override |
| 7253 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7254 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7255 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7256 | return; |
| 7257 | } |
| 7258 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7259 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7260 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7261 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7262 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7263 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7264 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7265 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7266 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7267 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7268 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7269 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7270 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7271 | // There has been issues when Sms raw table somehow stores orphan |
| 7272 | // fragments. They lead to garbled message when new fragments come |
| 7273 | // in and combined with those stale ones. In case this happens again, |
| 7274 | // user can reset all network settings which will clean up this table. |
| 7275 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7276 | // Clean up IMS settings as well here. |
| 7277 | int slotId = getSlotIndex(subId); |
| 7278 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7279 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7280 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7281 | |
| 7282 | // Erase modem config if erase modem on network setting is enabled. |
| 7283 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7284 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7285 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7286 | sendEraseModemConfig(getDefaultPhone()); |
| 7287 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7288 | } finally { |
| 7289 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7290 | } |
| 7291 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7292 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7293 | private void cleanUpSmsRawTable(Context context) { |
| 7294 | ContentResolver resolver = context.getContentResolver(); |
| 7295 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7296 | resolver.delete(uri, null, null); |
| 7297 | } |
| 7298 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7299 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7300 | public String getSimLocaleForSubscriber(int subId) { |
| 7301 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7302 | final Phone phone = getPhone(subId); |
| 7303 | if (phone == null) { |
| 7304 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7305 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7306 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7307 | final long identity = Binder.clearCallingIdentity(); |
| 7308 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7309 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7310 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7311 | if (info == null) { |
| 7312 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7313 | return null; |
| 7314 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7315 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7316 | // preferences (EF-PL and EF-LI)... |
| 7317 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7318 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7319 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7320 | if (localeFromDefaultSim != null) { |
| 7321 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7322 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7323 | + localeFromDefaultSim); |
| 7324 | return localeFromDefaultSim.toLanguageTag(); |
| 7325 | } else { |
| 7326 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | } |
| 7328 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7329 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7330 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7331 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7332 | // the SIM and carrier preferences does not include a country we add the country |
| 7333 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7334 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7336 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | return mccLocale.toLanguageTag(); |
| 7338 | } |
| 7339 | |
| 7340 | if (DBG) log("No locale found - returning null"); |
| 7341 | return null; |
| 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7345 | } |
| 7346 | |
| 7347 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7348 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7349 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7350 | } |
| 7351 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7352 | /** |
| 7353 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7354 | */ |
| 7355 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7356 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7357 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7358 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7359 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7360 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7361 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7362 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7363 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7364 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7365 | * representing the state of the modem. |
| 7366 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7367 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7368 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7369 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7370 | */ |
| 7371 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7372 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7373 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7374 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | |
| 7376 | final long identity = Binder.clearCallingIdentity(); |
| 7377 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7378 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | } finally { |
| 7380 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7381 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7382 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7383 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7384 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7385 | // less than total activity duration. |
| 7386 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7387 | if (info == null) { |
| 7388 | return false; |
| 7389 | } |
| 7390 | int activityDurationMs = |
| 7391 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7392 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7393 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7394 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7395 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7396 | } |
| 7397 | return (info.isValid() |
| 7398 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7399 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7400 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7401 | && (totalTxTimeMs <= activityDurationMs)); |
| 7402 | } |
| 7403 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7404 | /** |
| 7405 | * {@hide} |
| 7406 | * Returns the service state information on specified subscription. |
| 7407 | */ |
| 7408 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7409 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7410 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7412 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7413 | return null; |
| 7414 | } |
| 7415 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7416 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7417 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7418 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7419 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7420 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7421 | .setCallingPid(Binder.getCallingPid()) |
| 7422 | .setCallingUid(Binder.getCallingUid()) |
| 7423 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7424 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7425 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7426 | .build()); |
| 7427 | |
| 7428 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7429 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7430 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7431 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7432 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7433 | .setCallingPid(Binder.getCallingPid()) |
| 7434 | .setCallingUid(Binder.getCallingUid()) |
| 7435 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7436 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7437 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7438 | .build()); |
| 7439 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7440 | boolean hasFinePermission = |
| 7441 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7442 | boolean hasCoarsePermission = |
| 7443 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | final long identity = Binder.clearCallingIdentity(); |
| 7446 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7447 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7448 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7449 | Rlog.d(LOG_TAG, |
| 7450 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7451 | return null; |
| 7452 | } |
| 7453 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7454 | final Phone phone = getPhone(subId); |
| 7455 | if (phone == null) { |
| 7456 | return null; |
| 7457 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7458 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7459 | ServiceState ss = phone.getServiceState(); |
| 7460 | |
| 7461 | // Scrub out the location info in ServiceState depending on what level of access |
| 7462 | // the caller has. |
| 7463 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7464 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7465 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7466 | } finally { |
| 7467 | Binder.restoreCallingIdentity(identity); |
| 7468 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7469 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7470 | |
| 7471 | /** |
| 7472 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7473 | * |
| 7474 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7475 | * voicemail ringtone. |
| 7476 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7477 | * PhoneAccount. |
| 7478 | */ |
| 7479 | @Override |
| 7480 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | final long identity = Binder.clearCallingIdentity(); |
| 7482 | try { |
| 7483 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7484 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7485 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7487 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7489 | } finally { |
| 7490 | Binder.restoreCallingIdentity(identity); |
| 7491 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7492 | } |
| 7493 | |
| 7494 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7495 | * Sets the per-account voicemail ringtone. |
| 7496 | * |
| 7497 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7498 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7499 | * |
| 7500 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7501 | * voicemail ringtone. |
| 7502 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7503 | * PhoneAccount. |
| 7504 | */ |
| 7505 | @Override |
| 7506 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7507 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7508 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7509 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7510 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7511 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7512 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7513 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7514 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7515 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | |
| 7517 | final long identity = Binder.clearCallingIdentity(); |
| 7518 | try { |
| 7519 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7520 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7521 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | } |
| 7523 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7524 | } finally { |
| 7525 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7526 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7527 | } |
| 7528 | |
| 7529 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7530 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7531 | * |
| 7532 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7533 | * voicemail vibration setting. |
| 7534 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7535 | */ |
| 7536 | @Override |
| 7537 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
| 7540 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7541 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7542 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7549 | } |
| 7550 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7551 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7552 | * Sets the per-account voicemail vibration. |
| 7553 | * |
| 7554 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7555 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7556 | * |
| 7557 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7558 | * voicemail vibration setting. |
| 7559 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7560 | * specific PhoneAccount. |
| 7561 | */ |
| 7562 | @Override |
| 7563 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7564 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7565 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7566 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7567 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7568 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7569 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7570 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7571 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7572 | } |
| 7573 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7574 | final long identity = Binder.clearCallingIdentity(); |
| 7575 | try { |
| 7576 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7577 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7578 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | } |
| 7580 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7581 | } finally { |
| 7582 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7583 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7584 | } |
| 7585 | |
| 7586 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7587 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7588 | * |
| 7589 | * @throws SecurityException if the caller does not have the required permission |
| 7590 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7591 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7592 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7593 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7597 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7598 | * permission. |
| 7599 | * |
| 7600 | * @throws SecurityException if the caller does not have the required permission |
| 7601 | */ |
| 7602 | private void enforceSendSmsPermission() { |
| 7603 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7604 | } |
| 7605 | |
| 7606 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7607 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7608 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7609 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7610 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7611 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7612 | final long identity = Binder.clearCallingIdentity(); |
| 7613 | try { |
| 7614 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7615 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7616 | if (componentName == null) { |
| 7617 | throw new SecurityException( |
| 7618 | "Caller not current active visual voicemail package[null]"); |
| 7619 | } |
| 7620 | String vvmPackage = componentName.getPackageName(); |
| 7621 | if (!callingPackage.equals(vvmPackage)) { |
| 7622 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7623 | + vvmPackage + "]"); |
| 7624 | } |
| 7625 | } finally { |
| 7626 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7627 | } |
| 7628 | } |
| 7629 | |
| 7630 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7631 | * Return the application ID for the app type. |
| 7632 | * |
| 7633 | * @param subId the subscription ID that this request applies to. |
| 7634 | * @param appType the uicc app type. |
| 7635 | * @return Application ID for specificied app type, or null if no uicc. |
| 7636 | */ |
| 7637 | @Override |
| 7638 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7639 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7640 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7641 | |
| 7642 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7643 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | if (phone == null) { |
| 7645 | return null; |
| 7646 | } |
| 7647 | String aid = null; |
| 7648 | try { |
| 7649 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7650 | .getApplicationByType(appType).getAid(); |
| 7651 | } catch (Exception e) { |
| 7652 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7653 | } |
| 7654 | return aid; |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7657 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7658 | } |
| 7659 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7660 | /** |
| 7661 | * Return the Electronic Serial Number. |
| 7662 | * |
| 7663 | * @param subId the subscription ID that this request applies to. |
| 7664 | * @return ESN or null if error. |
| 7665 | */ |
| 7666 | @Override |
| 7667 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7668 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7669 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | |
| 7671 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7672 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7673 | if (phone == null) { |
| 7674 | return null; |
| 7675 | } |
| 7676 | String esn = null; |
| 7677 | try { |
| 7678 | esn = phone.getEsn(); |
| 7679 | } catch (Exception e) { |
| 7680 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7681 | } |
| 7682 | return esn; |
| 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7685 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7686 | } |
| 7687 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7688 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7689 | * Return the Preferred Roaming List Version. |
| 7690 | * |
| 7691 | * @param subId the subscription ID that this request applies to. |
| 7692 | * @return PRLVersion or null if error. |
| 7693 | */ |
| 7694 | @Override |
| 7695 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7696 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7697 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7698 | |
| 7699 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7700 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | if (phone == null) { |
| 7702 | return null; |
| 7703 | } |
| 7704 | String cdmaPrlVersion = null; |
| 7705 | try { |
| 7706 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7707 | } catch (Exception e) { |
| 7708 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7709 | } |
| 7710 | return cdmaPrlVersion; |
| 7711 | } finally { |
| 7712 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7713 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7717 | * Get snapshot of Telephony histograms |
| 7718 | * @return List of Telephony histograms |
| 7719 | * @hide |
| 7720 | */ |
| 7721 | @Override |
| 7722 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7724 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7725 | |
| 7726 | final long identity = Binder.clearCallingIdentity(); |
| 7727 | try { |
| 7728 | return RIL.getTelephonyRILTimingHistograms(); |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
| 7731 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7732 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7733 | |
| 7734 | /** |
| 7735 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7736 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7737 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7738 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7739 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7740 | * @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] | 7741 | */ |
| 7742 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7743 | @TelephonyManager.SetCarrierRestrictionResult |
| 7744 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7745 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7746 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7747 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7748 | if (carrierRestrictionRules == null) { |
| 7749 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7750 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | final long identity = Binder.clearCallingIdentity(); |
| 7753 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7754 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7755 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
| 7758 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7759 | } |
| 7760 | |
| 7761 | /** |
| 7762 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7763 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7764 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7765 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7766 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7767 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7768 | */ |
| 7769 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7770 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7771 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7772 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | |
| 7774 | final long identity = Binder.clearCallingIdentity(); |
| 7775 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7776 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7777 | if (response instanceof CarrierRestrictionRules) { |
| 7778 | return (CarrierRestrictionRules) response; |
| 7779 | } |
| 7780 | // Response is an Exception of some kind, |
| 7781 | // which is signalled to the user as a NULL retval |
| 7782 | return null; |
| 7783 | } catch (Exception e) { |
| 7784 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7785 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
| 7788 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7791 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7792 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7793 | * @param subId the subscription ID that this action applies to. |
| 7794 | * @param enabled control enable or disable radio. |
| 7795 | * {@hide} |
| 7796 | */ |
| 7797 | @Override |
| 7798 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7799 | enforceModifyPermission(); |
| 7800 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | |
| 7802 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7803 | if (phone == null) { |
| 7804 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7805 | return; |
| 7806 | } |
| 7807 | try { |
| 7808 | phone.carrierActionSetRadioEnabled(enabled); |
| 7809 | } catch (Exception e) { |
| 7810 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7811 | } finally { |
| 7812 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7813 | } |
| 7814 | } |
| 7815 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7816 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7817 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7818 | * network status based on which carrier apps could apply actions accordingly, |
| 7819 | * enable/disable default url handler for example. |
| 7820 | * |
| 7821 | * @param subId the subscription ID that this action applies to. |
| 7822 | * @param report control start/stop reporting the default network status. |
| 7823 | * {@hide} |
| 7824 | */ |
| 7825 | @Override |
| 7826 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7827 | enforceModifyPermission(); |
| 7828 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7829 | |
| 7830 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7831 | if (phone == null) { |
| 7832 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7833 | return; |
| 7834 | } |
| 7835 | try { |
| 7836 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7837 | } catch (Exception e) { |
| 7838 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7845 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7846 | * @param subId the subscription ID that this action applies to. |
| 7847 | * {@hide} |
| 7848 | */ |
| 7849 | @Override |
| 7850 | public void carrierActionResetAll(int subId) { |
| 7851 | enforceModifyPermission(); |
| 7852 | final Phone phone = getPhone(subId); |
| 7853 | if (phone == null) { |
| 7854 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7855 | return; |
| 7856 | } |
| 7857 | try { |
| 7858 | phone.carrierActionResetAll(); |
| 7859 | } catch (Exception e) { |
| 7860 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7861 | } |
| 7862 | } |
| 7863 | |
| 7864 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7865 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7866 | * bug report is being generated. |
| 7867 | */ |
| 7868 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7869 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7870 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7871 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7872 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7873 | + Binder.getCallingPid() |
| 7874 | + ", uid=" + Binder.getCallingUid() |
| 7875 | + "without permission " |
| 7876 | + android.Manifest.permission.DUMP); |
| 7877 | return; |
| 7878 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7879 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7880 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7881 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7882 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7883 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7884 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7885 | @NonNull String[] args) { |
| 7886 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7887 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7888 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7889 | } |
| 7890 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7891 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7892 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7893 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7894 | * @param reason the reason the data enable change is taking place |
| 7895 | * @param enabled True if enabling the data, otherwise disabling. |
| 7896 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7897 | */ |
| 7898 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7899 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7900 | boolean enabled) { |
| 7901 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7902 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7903 | try { |
| 7904 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7905 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7906 | } catch (SecurityException se) { |
| 7907 | enforceModifyPermission(); |
| 7908 | } |
| 7909 | } else { |
| 7910 | enforceModifyPermission(); |
| 7911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7912 | |
| 7913 | final long identity = Binder.clearCallingIdentity(); |
| 7914 | try { |
| 7915 | Phone phone = getPhone(subId); |
| 7916 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7917 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7918 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7919 | } else { |
| 7920 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7922 | } |
| 7923 | } finally { |
| 7924 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7925 | } |
| 7926 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7927 | |
| 7928 | /** |
| 7929 | * Get Client request stats |
| 7930 | * @return List of Client Request Stats |
| 7931 | * @hide |
| 7932 | */ |
| 7933 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7934 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7935 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7936 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7937 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7938 | return null; |
| 7939 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7940 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7941 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | final long identity = Binder.clearCallingIdentity(); |
| 7943 | try { |
| 7944 | if (phone != null) { |
| 7945 | return phone.getClientRequestStats(); |
| 7946 | } |
| 7947 | |
| 7948 | return null; |
| 7949 | } finally { |
| 7950 | Binder.restoreCallingIdentity(identity); |
| 7951 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7952 | } |
| 7953 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7954 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7955 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7956 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7957 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7958 | |
| 7959 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7960 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7961 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7962 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7963 | * @param state State of SIM (power down, power up, pass through) |
| 7964 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7965 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7966 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7967 | * |
| 7968 | **/ |
| 7969 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7970 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7971 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7972 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7973 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7974 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7975 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7976 | final long identity = Binder.clearCallingIdentity(); |
| 7977 | try { |
| 7978 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7979 | phone.setSimPowerState(state, null, workSource); |
| 7980 | } |
| 7981 | } finally { |
| 7982 | Binder.restoreCallingIdentity(identity); |
| 7983 | } |
| 7984 | } |
| 7985 | |
| 7986 | /** |
| 7987 | * Set SIM card power state. |
| 7988 | * |
| 7989 | * @param slotIndex SIM slot id. |
| 7990 | * @param state State of SIM (power down, power up, pass through) |
| 7991 | * @param callback callback to trigger after success or failure |
| 7992 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7993 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7994 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7995 | * |
| 7996 | **/ |
| 7997 | @Override |
| 7998 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7999 | IIntegerConsumer callback) { |
| 8000 | enforceModifyPermission(); |
| 8001 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8002 | |
| 8003 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8004 | |
| 8005 | final long identity = Binder.clearCallingIdentity(); |
| 8006 | try { |
| 8007 | if (phone != null) { |
| 8008 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8009 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8010 | } |
| 8011 | } finally { |
| 8012 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8013 | } |
| 8014 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8015 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8016 | private boolean isUssdApiAllowed(int subId) { |
| 8017 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8018 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8019 | if (configManager == null) { |
| 8020 | return false; |
| 8021 | } |
| 8022 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8023 | if (pb == null) { |
| 8024 | return false; |
| 8025 | } |
| 8026 | return pb.getBoolean( |
| 8027 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8028 | } |
| 8029 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8030 | /** |
| 8031 | * Check if phone is in emergency callback mode |
| 8032 | * @return true if phone is in emergency callback mode |
| 8033 | * @param subId sub id |
| 8034 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8035 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8036 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8037 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8038 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8039 | |
| 8040 | final long identity = Binder.clearCallingIdentity(); |
| 8041 | try { |
| 8042 | if (phone != null) { |
| 8043 | return phone.isInEcm(); |
| 8044 | } else { |
| 8045 | return false; |
| 8046 | } |
| 8047 | } finally { |
| 8048 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8049 | } |
| 8050 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8051 | |
| 8052 | /** |
| 8053 | * Get the current signal strength information for the given subscription. |
| 8054 | * Because this information is not updated when the device is in a low power state |
| 8055 | * it should not be relied-upon to be current. |
| 8056 | * @param subId Subscription index |
| 8057 | * @return the most recent cached signal strength info from the modem |
| 8058 | */ |
| 8059 | @Override |
| 8060 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8061 | final long identity = Binder.clearCallingIdentity(); |
| 8062 | try { |
| 8063 | Phone p = getPhone(subId); |
| 8064 | if (p == null) { |
| 8065 | return null; |
| 8066 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | return p.getSignalStrength(); |
| 8069 | } finally { |
| 8070 | Binder.restoreCallingIdentity(identity); |
| 8071 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8072 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8073 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8074 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8075 | * Get the current modem radio state for the given slot. |
| 8076 | * @param slotIndex slot index. |
| 8077 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8078 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8079 | * @return the current radio power state from the modem |
| 8080 | */ |
| 8081 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8082 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8083 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8084 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8085 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8086 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8087 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8088 | } |
| 8089 | |
| 8090 | final long identity = Binder.clearCallingIdentity(); |
| 8091 | try { |
| 8092 | return phone.getRadioPowerState(); |
| 8093 | } finally { |
| 8094 | Binder.restoreCallingIdentity(identity); |
| 8095 | } |
| 8096 | } |
| 8097 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8098 | } |
| 8099 | |
| 8100 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8101 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8102 | * |
| 8103 | * <p>Requires one of the following permissions: |
| 8104 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8105 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8106 | * privileges. |
| 8107 | * |
| 8108 | * @param subId subscription id |
| 8109 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8110 | * {@code false}. |
| 8111 | */ |
| 8112 | @Override |
| 8113 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8114 | try { |
| 8115 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8116 | null); |
| 8117 | } catch (Exception e) { |
| 8118 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8119 | mApp, subId, "isDataRoamingEnabled"); |
| 8120 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8121 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8122 | boolean isEnabled = false; |
| 8123 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8124 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8125 | Phone phone = getPhone(subId); |
| 8126 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8127 | } finally { |
| 8128 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8129 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8130 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8131 | } |
| 8132 | |
| 8133 | |
| 8134 | /** |
| 8135 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8136 | * |
| 8137 | * <p> Requires permission: |
| 8138 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8139 | * privileges. |
| 8140 | * |
| 8141 | * @param subId subscription id |
| 8142 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8143 | */ |
| 8144 | @Override |
| 8145 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8147 | mApp, subId, "setDataRoamingEnabled"); |
| 8148 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8149 | final long identity = Binder.clearCallingIdentity(); |
| 8150 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8151 | Phone phone = getPhone(subId); |
| 8152 | if (phone != null) { |
| 8153 | phone.setDataRoamingEnabled(isEnabled); |
| 8154 | } |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8157 | } |
| 8158 | } |
| 8159 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8160 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8161 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8162 | TelephonyPermissions |
| 8163 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8164 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8165 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8166 | boolean isAllowed = true; |
| 8167 | final long identity = Binder.clearCallingIdentity(); |
| 8168 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8169 | Phone phone = getPhone(subId); |
| 8170 | if (phone != null) { |
| 8171 | isAllowed = phone.isCspPlmnEnabled(); |
| 8172 | } |
| 8173 | } finally { |
| 8174 | Binder.restoreCallingIdentity(identity); |
| 8175 | } |
| 8176 | return isAllowed; |
| 8177 | } |
| 8178 | |
| 8179 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8180 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8181 | // Verify that tha callingPackage belongs to the calling UID |
| 8182 | mApp.getSystemService(AppOpsManager.class) |
| 8183 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8184 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8185 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8186 | try { |
| 8187 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8188 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8189 | } catch (SecurityException e) { |
| 8190 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8191 | // has carrier privileges on an active UICC |
| 8192 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8193 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8194 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8195 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8196 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8197 | |
| 8198 | final long identity = Binder.clearCallingIdentity(); |
| 8199 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8200 | UiccController uiccController = UiccController.getInstance(); |
| 8201 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8202 | if (hasReadPermission) { |
| 8203 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8204 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8205 | |
| 8206 | // Remove private info if the caller doesn't have access |
| 8207 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8208 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8209 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8210 | // is available |
| 8211 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8212 | if (card == null || card.getUiccProfile() == null) { |
| 8213 | // assume no access if the card or profile is unavailable |
| 8214 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8215 | continue; |
| 8216 | } |
| 8217 | UiccProfile profile = card.getUiccProfile(); |
| 8218 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8219 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8220 | filteredInfos.add(cardInfo); |
| 8221 | } else { |
| 8222 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8223 | } |
| 8224 | } |
| 8225 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
| 8229 | } |
| 8230 | |
| 8231 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8232 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8233 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8235 | final long identity = Binder.clearCallingIdentity(); |
| 8236 | try { |
| 8237 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8238 | if (slots == null) { |
| 8239 | Rlog.i(LOG_TAG, "slots is null."); |
| 8240 | return null; |
| 8241 | } |
| 8242 | |
| 8243 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8244 | for (int i = 0; i < slots.length; i++) { |
| 8245 | UiccSlot slot = slots[i]; |
| 8246 | if (slot == null) { |
| 8247 | continue; |
| 8248 | } |
| 8249 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8250 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | UiccCard card = slot.getUiccCard(); |
| 8252 | if (card != null) { |
| 8253 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8254 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8255 | cardId = slot.getEid(); |
| 8256 | if (TextUtils.isEmpty(cardId)) { |
| 8257 | cardId = slot.getIccId(); |
| 8258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8259 | } |
| 8260 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8261 | if (cardId != null) { |
| 8262 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8263 | // if cardId is an EID, it's all digits so this is fine |
| 8264 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8265 | } |
| 8266 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | int cardState = 0; |
| 8268 | switch (slot.getCardState()) { |
| 8269 | case CARDSTATE_ABSENT: |
| 8270 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8271 | break; |
| 8272 | case CARDSTATE_PRESENT: |
| 8273 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8274 | break; |
| 8275 | case CARDSTATE_ERROR: |
| 8276 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8277 | break; |
| 8278 | case CARDSTATE_RESTRICTED: |
| 8279 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8280 | break; |
| 8281 | default: |
| 8282 | break; |
| 8283 | |
| 8284 | } |
| 8285 | |
| 8286 | infos[i] = new UiccSlotInfo( |
| 8287 | slot.isActive(), |
| 8288 | slot.isEuicc(), |
| 8289 | cardId, |
| 8290 | cardState, |
| 8291 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8292 | slot.isExtendedApduSupported(), |
| 8293 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8294 | } |
| 8295 | return infos; |
| 8296 | } finally { |
| 8297 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8298 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8299 | } |
| 8300 | |
| 8301 | @Override |
| 8302 | public boolean switchSlots(int[] physicalSlots) { |
| 8303 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8304 | |
| 8305 | final long identity = Binder.clearCallingIdentity(); |
| 8306 | try { |
| 8307 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
| 8310 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8311 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8312 | |
| 8313 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8314 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8315 | final long identity = Binder.clearCallingIdentity(); |
| 8316 | try { |
| 8317 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8318 | } finally { |
| 8319 | Binder.restoreCallingIdentity(identity); |
| 8320 | } |
| 8321 | } |
| 8322 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8323 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8324 | * A test API to reload the UICC profile. |
| 8325 | * |
| 8326 | * <p>Requires that the calling app has permission |
| 8327 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8328 | * @hide |
| 8329 | */ |
| 8330 | @Override |
| 8331 | public void refreshUiccProfile(int subId) { |
| 8332 | enforceModifyPermission(); |
| 8333 | |
| 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
| 8336 | Phone phone = getPhone(subId); |
| 8337 | if (phone == null) { |
| 8338 | return; |
| 8339 | } |
| 8340 | UiccCard uiccCard = phone.getUiccCard(); |
| 8341 | if (uiccCard == null) { |
| 8342 | return; |
| 8343 | } |
| 8344 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8345 | if (uiccProfile == null) { |
| 8346 | return; |
| 8347 | } |
| 8348 | uiccProfile.refresh(); |
| 8349 | } finally { |
| 8350 | Binder.restoreCallingIdentity(identity); |
| 8351 | } |
| 8352 | } |
| 8353 | |
| 8354 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8355 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8356 | */ |
| 8357 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8358 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8359 | } |
| 8360 | |
| 8361 | /** |
| 8362 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8363 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8364 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8365 | */ |
| 8366 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8367 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8368 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8369 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8370 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8371 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8372 | return isDataRoamingEnabled; |
| 8373 | } |
| 8374 | |
| 8375 | /** |
| 8376 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8377 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8378 | */ |
| 8379 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8380 | List<Integer> list = TelephonyProperties.default_network(); |
| 8381 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8382 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8383 | return list.get(phoneId); |
| 8384 | } |
| 8385 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8386 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8387 | |
| 8388 | @Override |
| 8389 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8390 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8391 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | |
| 8393 | final long identity = Binder.clearCallingIdentity(); |
| 8394 | try { |
| 8395 | final Phone phone = getPhone(subId); |
| 8396 | if (phone == null) { |
| 8397 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8398 | return; |
| 8399 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8400 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8401 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8402 | if (carrierPrivilegeRules == null) { |
| 8403 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8404 | } else { |
| 8405 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8406 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | } finally { |
| 8408 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8409 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | @Override |
| 8413 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8414 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8415 | |
| 8416 | final long identity = Binder.clearCallingIdentity(); |
| 8417 | try { |
| 8418 | final Phone phone = getPhone(subId); |
| 8419 | if (phone == null) { |
| 8420 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8421 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8422 | } |
| 8423 | return phone.getCarrierIdListVersion(); |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8426 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8427 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8428 | |
| 8429 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8430 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8431 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8432 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8433 | mApp, subId, callingPackage, callingFeatureId, |
| 8434 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8435 | return -1; |
| 8436 | } |
| 8437 | |
| 8438 | final long identity = Binder.clearCallingIdentity(); |
| 8439 | try { |
| 8440 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8441 | } finally { |
| 8442 | Binder.restoreCallingIdentity(identity); |
| 8443 | } |
| 8444 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8445 | |
| 8446 | @Override |
| 8447 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8448 | TelephonyPermissions |
| 8449 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8450 | mApp, subId, "getCdmaRoamingMode"); |
| 8451 | |
| 8452 | final long identity = Binder.clearCallingIdentity(); |
| 8453 | try { |
| 8454 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | @Override |
| 8461 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8463 | mApp, subId, "setCdmaRoamingMode"); |
| 8464 | |
| 8465 | final long identity = Binder.clearCallingIdentity(); |
| 8466 | try { |
| 8467 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8468 | } finally { |
| 8469 | Binder.restoreCallingIdentity(identity); |
| 8470 | } |
| 8471 | } |
| 8472 | |
| 8473 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8474 | public int getCdmaSubscriptionMode(int subId) { |
| 8475 | TelephonyPermissions |
| 8476 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8477 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8478 | |
| 8479 | final long identity = Binder.clearCallingIdentity(); |
| 8480 | try { |
| 8481 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8482 | } finally { |
| 8483 | Binder.restoreCallingIdentity(identity); |
| 8484 | } |
| 8485 | } |
| 8486 | |
| 8487 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8488 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8490 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8491 | |
| 8492 | final long identity = Binder.clearCallingIdentity(); |
| 8493 | try { |
| 8494 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8495 | } finally { |
| 8496 | Binder.restoreCallingIdentity(identity); |
| 8497 | } |
| 8498 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8499 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8500 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8501 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8502 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8503 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8504 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8505 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8506 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8507 | } |
| 8508 | final long identity = Binder.clearCallingIdentity(); |
| 8509 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8510 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8511 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8512 | if (phone.getEmergencyNumberTracker() != null |
| 8513 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8514 | emergencyNumberListInternal.put( |
| 8515 | phone.getSubId(), |
| 8516 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8517 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8518 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8519 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8520 | } finally { |
| 8521 | Binder.restoreCallingIdentity(identity); |
| 8522 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8523 | } |
| 8524 | |
| 8525 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8526 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8527 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8528 | if (!exactMatch) { |
| 8529 | TelephonyPermissions |
| 8530 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8531 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8532 | } |
| 8533 | final long identity = Binder.clearCallingIdentity(); |
| 8534 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8535 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8536 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8537 | && phone.getEmergencyNumberTracker() |
| 8538 | .isEmergencyNumber(number, exactMatch)) { |
| 8539 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8540 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8541 | } |
| 8542 | return false; |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
| 8545 | } |
| 8546 | } |
| 8547 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8548 | /** |
| 8549 | * Update emergency number list for test mode. |
| 8550 | */ |
| 8551 | @Override |
| 8552 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8553 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8554 | "updateEmergencyNumberListTestMode"); |
| 8555 | |
| 8556 | final long identity = Binder.clearCallingIdentity(); |
| 8557 | try { |
| 8558 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8559 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8560 | if (tracker != null) { |
| 8561 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8562 | } |
| 8563 | } |
| 8564 | } finally { |
| 8565 | Binder.restoreCallingIdentity(identity); |
| 8566 | } |
| 8567 | } |
| 8568 | |
| 8569 | /** |
| 8570 | * Get the full emergency number list for test mode. |
| 8571 | */ |
| 8572 | @Override |
| 8573 | public List<String> getEmergencyNumberListTestMode() { |
| 8574 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8575 | "getEmergencyNumberListTestMode"); |
| 8576 | |
| 8577 | final long identity = Binder.clearCallingIdentity(); |
| 8578 | try { |
| 8579 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8580 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8581 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8582 | if (tracker != null) { |
| 8583 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8584 | emergencyNumbers.add(num.getNumber()); |
| 8585 | } |
| 8586 | } |
| 8587 | } |
| 8588 | return new ArrayList<>(emergencyNumbers); |
| 8589 | } finally { |
| 8590 | Binder.restoreCallingIdentity(identity); |
| 8591 | } |
| 8592 | } |
| 8593 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8594 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8595 | public int getEmergencyNumberDbVersion(int subId) { |
| 8596 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8597 | |
| 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | final Phone phone = getPhone(subId); |
| 8601 | if (phone == null) { |
| 8602 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8603 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8604 | } |
| 8605 | return phone.getEmergencyNumberDbVersion(); |
| 8606 | } finally { |
| 8607 | Binder.restoreCallingIdentity(identity); |
| 8608 | } |
| 8609 | } |
| 8610 | |
| 8611 | @Override |
| 8612 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8613 | enforceModifyPermission(); |
| 8614 | |
| 8615 | final long identity = Binder.clearCallingIdentity(); |
| 8616 | try { |
| 8617 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8618 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8619 | if (tracker != null) { |
| 8620 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8621 | } |
| 8622 | } |
| 8623 | } finally { |
| 8624 | Binder.restoreCallingIdentity(identity); |
| 8625 | } |
| 8626 | } |
| 8627 | |
| 8628 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8629 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8630 | enforceActiveEmergencySessionPermission(); |
| 8631 | |
| 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
| 8634 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8635 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8636 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8637 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8638 | } |
| 8639 | } |
| 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
| 8642 | } |
| 8643 | } |
| 8644 | |
| 8645 | @Override |
| 8646 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8647 | enforceActiveEmergencySessionPermission(); |
| 8648 | |
| 8649 | final long identity = Binder.clearCallingIdentity(); |
| 8650 | try { |
| 8651 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8652 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8653 | if (tracker != null) { |
| 8654 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8655 | } |
| 8656 | } |
| 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
| 8659 | } |
| 8660 | } |
| 8661 | |
| 8662 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8663 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8664 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8665 | Phone phone = getPhone(subId); |
| 8666 | if (phone == null) { |
| 8667 | return null; |
| 8668 | } |
| 8669 | final long identity = Binder.clearCallingIdentity(); |
| 8670 | try { |
| 8671 | UiccProfile profile = UiccController.getInstance() |
| 8672 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8673 | if (profile != null) { |
| 8674 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8675 | } |
| 8676 | } finally { |
| 8677 | Binder.restoreCallingIdentity(identity); |
| 8678 | } |
| 8679 | return null; |
| 8680 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8681 | |
| 8682 | /** |
| 8683 | * Enable or disable a modem stack. |
| 8684 | */ |
| 8685 | @Override |
| 8686 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8687 | enforceModifyPermission(); |
| 8688 | |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | try { |
| 8691 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8692 | if (phone == null) { |
| 8693 | return false; |
| 8694 | } else { |
| 8695 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8696 | } |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
| 8700 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8701 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8702 | /** |
| 8703 | * Whether a modem stack is enabled or not. |
| 8704 | */ |
| 8705 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8706 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8707 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8708 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8709 | if (phone == null) return false; |
| 8710 | |
| 8711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8712 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8713 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8714 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8715 | } |
| 8716 | |
| 8717 | final long identity = Binder.clearCallingIdentity(); |
| 8718 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8719 | try { |
| 8720 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8721 | } catch (NoSuchElementException ex) { |
| 8722 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8723 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8724 | } finally { |
| 8725 | Binder.restoreCallingIdentity(identity); |
| 8726 | } |
| 8727 | } |
| 8728 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8729 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8730 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8731 | enforceModifyPermission(); |
| 8732 | |
| 8733 | final long identity = Binder.clearCallingIdentity(); |
| 8734 | try { |
| 8735 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8736 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8737 | .commit(); |
| 8738 | } finally { |
| 8739 | Binder.restoreCallingIdentity(identity); |
| 8740 | } |
| 8741 | } |
| 8742 | |
| 8743 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8744 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8745 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8746 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8747 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8748 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8749 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8750 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8751 | |
| 8752 | final long identity = Binder.clearCallingIdentity(); |
| 8753 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8754 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8755 | } finally { |
| 8756 | Binder.restoreCallingIdentity(identity); |
| 8757 | } |
| 8758 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8759 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8760 | @TelephonyManager.IsMultiSimSupportedResult |
| 8761 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8762 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8763 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8764 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8765 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8766 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8767 | } |
| 8768 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8769 | // supported by the modem, indicate that it is restricted. |
| 8770 | PhoneCapability staticCapability = |
| 8771 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8772 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8773 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8774 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8775 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8776 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8777 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8778 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8779 | } |
| 8780 | // Check if support of multiple SIMs is restricted by carrier |
| 8781 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8782 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8783 | } |
| 8784 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8785 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8786 | } |
| 8787 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8788 | /** |
| 8789 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8790 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8791 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8792 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8793 | * @param numOfSims number of active sims we want to switch to |
| 8794 | */ |
| 8795 | @Override |
| 8796 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8797 | if (numOfSims == 1) { |
| 8798 | enforceModifyPermission(); |
| 8799 | } else { |
| 8800 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8801 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8802 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8803 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8804 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8805 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8806 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8807 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8808 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8809 | return; |
| 8810 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8811 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8812 | } finally { |
| 8813 | Binder.restoreCallingIdentity(identity); |
| 8814 | } |
| 8815 | } |
| 8816 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8817 | @Override |
| 8818 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8819 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8820 | Phone phone = getPhone(subId); |
| 8821 | if (phone == null) { |
| 8822 | return false; |
| 8823 | } |
| 8824 | final long identity = Binder.clearCallingIdentity(); |
| 8825 | try { |
| 8826 | UiccCard uiccCard = phone.getUiccCard(); |
| 8827 | if (uiccCard == null) { |
| 8828 | return false; |
| 8829 | } |
| 8830 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8831 | if (uiccProfile == null) { |
| 8832 | return false; |
| 8833 | } |
| 8834 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8835 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8836 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8837 | } |
| 8838 | return false; |
| 8839 | } finally { |
| 8840 | Binder.restoreCallingIdentity(identity); |
| 8841 | } |
| 8842 | } |
| 8843 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8844 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8845 | * Get whether making changes to modem configurations will trigger reboot. |
| 8846 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8847 | */ |
| 8848 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8849 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8850 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8851 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8852 | mApp, subId, callingPackage, callingFeatureId, |
| 8853 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8854 | return false; |
| 8855 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8856 | final long identity = Binder.clearCallingIdentity(); |
| 8857 | try { |
| 8858 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8859 | } finally { |
| 8860 | Binder.restoreCallingIdentity(identity); |
| 8861 | } |
| 8862 | } |
| 8863 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8864 | private void updateModemStateMetrics() { |
| 8865 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8866 | // TODO: check the state for each modem if the api is ready. |
| 8867 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8868 | } |
| 8869 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8870 | @Override |
| 8871 | public int[] getSlotsMapping() { |
| 8872 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8873 | |
| 8874 | final long identity = Binder.clearCallingIdentity(); |
| 8875 | try { |
| 8876 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8877 | // All logical slots should have a mapping to a physical slot. |
| 8878 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8879 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8880 | for (int i = 0; i < slotInfos.length; i++) { |
| 8881 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8882 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8883 | } |
| 8884 | } |
| 8885 | return logicalSlotsMapping; |
| 8886 | } finally { |
| 8887 | Binder.restoreCallingIdentity(identity); |
| 8888 | } |
| 8889 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8890 | |
| 8891 | /** |
| 8892 | * Get the IRadio HAL Version |
| 8893 | */ |
| 8894 | @Override |
| 8895 | public int getRadioHalVersion() { |
| 8896 | Phone phone = getDefaultPhone(); |
| 8897 | if (phone == null) return -1; |
| 8898 | HalVersion hv = phone.getHalVersion(); |
| 8899 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8900 | return hv.major * 100 + hv.minor; |
| 8901 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8902 | |
| 8903 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8904 | * Get the current calling package name. |
| 8905 | * @return the current calling package name |
| 8906 | */ |
| 8907 | @Override |
| 8908 | public String getCurrentPackageName() { |
| 8909 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8910 | } |
| 8911 | |
| 8912 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8913 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8914 | * corresponding network requests on a subId. |
| 8915 | * |
| 8916 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8917 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8918 | * 2) APN is un-metered for this subscription, or |
| 8919 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8920 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8921 | * |
| 8922 | * @return whether data is allowed for a apn type. |
| 8923 | * |
| 8924 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8925 | */ |
| 8926 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8927 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8928 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8929 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8930 | |
| 8931 | // Now that all security checks passes, perform the operation as ourselves. |
| 8932 | final long identity = Binder.clearCallingIdentity(); |
| 8933 | try { |
| 8934 | Phone phone = getPhone(subId); |
| 8935 | if (phone == null) return false; |
| 8936 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8937 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8938 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8939 | } finally { |
| 8940 | Binder.restoreCallingIdentity(identity); |
| 8941 | } |
| 8942 | } |
| 8943 | |
| 8944 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8945 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8946 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8947 | |
| 8948 | // Now that all security checks passes, perform the operation as ourselves. |
| 8949 | final long identity = Binder.clearCallingIdentity(); |
| 8950 | try { |
| 8951 | Phone phone = getPhone(subId); |
| 8952 | if (phone == null) return true; // By default return true. |
| 8953 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8954 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8955 | } finally { |
| 8956 | Binder.restoreCallingIdentity(identity); |
| 8957 | } |
| 8958 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8959 | |
| 8960 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8961 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8962 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8963 | enforceModifyPermission(); |
| 8964 | long token = Binder.clearCallingIdentity(); |
| 8965 | try { |
| 8966 | Phone phone = getPhone(subscriptionId); |
| 8967 | if (phone == null) { |
| 8968 | try { |
| 8969 | if (resultCallback != null) { |
| 8970 | resultCallback.accept(false); |
| 8971 | } |
| 8972 | } catch (RemoteException e) { |
| 8973 | // ignore |
| 8974 | } |
| 8975 | return; |
| 8976 | } |
| 8977 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8978 | Pair.create(specifiers, (x) -> { |
| 8979 | try { |
| 8980 | if (resultCallback != null) { |
| 8981 | resultCallback.accept(x); |
| 8982 | } |
| 8983 | } catch (RemoteException e) { |
| 8984 | // ignore |
| 8985 | } |
| 8986 | }); |
| 8987 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8988 | } finally { |
| 8989 | Binder.restoreCallingIdentity(token); |
| 8990 | } |
| 8991 | } |
| 8992 | |
| 8993 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8994 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8995 | TelephonyPermissions |
| 8996 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8997 | mApp, subId, "getSystemSelectionChannels"); |
| 8998 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8999 | final long identity = Binder.clearCallingIdentity(); |
| 9000 | try { |
| 9001 | List<RadioAccessSpecifier> specifiers = |
| 9002 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9003 | null, subId, workSource); |
| 9004 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9005 | return specifiers; |
| 9006 | } finally { |
| 9007 | Binder.restoreCallingIdentity(identity); |
| 9008 | } |
| 9009 | } |
| 9010 | |
| 9011 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9012 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9013 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9014 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9015 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9016 | if (iccRecords == null) { |
| 9017 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9018 | return false; |
| 9019 | } |
| 9020 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9021 | } |
| 9022 | |
| 9023 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9024 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9025 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9026 | if (callingPackage == null) { |
| 9027 | callingPackage = getCurrentPackageName(); |
| 9028 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9029 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9030 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9031 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9032 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9033 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9034 | } |
| 9035 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9036 | Intent intent = new Intent(); |
| 9037 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9038 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9039 | // Bring up choose default SMS subscription dialog right now |
| 9040 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9041 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9042 | mApp.startActivity(intent); |
| 9043 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9044 | |
| 9045 | @Override |
| 9046 | public String getMmsUAProfUrl(int subId) { |
| 9047 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
| 9049 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9050 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9051 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9052 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9053 | return carrierUAProfUrl; |
| 9054 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9055 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9056 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9057 | } finally { |
| 9058 | Binder.restoreCallingIdentity(identity); |
| 9059 | } |
| 9060 | } |
| 9061 | |
| 9062 | @Override |
| 9063 | public String getMmsUserAgent(int subId) { |
| 9064 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9065 | final long identity = Binder.clearCallingIdentity(); |
| 9066 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9067 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9068 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9069 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9070 | return carrierUserAgent; |
| 9071 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9072 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9073 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9074 | } finally { |
| 9075 | Binder.restoreCallingIdentity(identity); |
| 9076 | } |
| 9077 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9078 | |
| 9079 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9080 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9081 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9082 | |
| 9083 | final long identity = Binder.clearCallingIdentity(); |
| 9084 | try { |
| 9085 | Phone phone = getPhone(subscriptionId); |
| 9086 | if (phone == null) return false; |
| 9087 | |
| 9088 | switch (policy) { |
| 9089 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9090 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9091 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9092 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9093 | default: |
| 9094 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9095 | } |
| 9096 | } finally { |
| 9097 | Binder.restoreCallingIdentity(identity); |
| 9098 | } |
| 9099 | } |
| 9100 | |
| 9101 | @Override |
| 9102 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9103 | boolean enabled) { |
| 9104 | enforceModifyPermission(); |
| 9105 | |
| 9106 | final long identity = Binder.clearCallingIdentity(); |
| 9107 | try { |
| 9108 | Phone phone = getPhone(subscriptionId); |
| 9109 | if (phone == null) return; |
| 9110 | |
| 9111 | switch (policy) { |
| 9112 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9113 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9114 | break; |
| 9115 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9116 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9117 | break; |
| 9118 | default: |
| 9119 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9120 | } |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
| 9123 | } |
| 9124 | } |
| 9125 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9126 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9127 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9128 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9129 | * otherwise. |
| 9130 | */ |
| 9131 | @Override |
| 9132 | public void setCepEnabled(boolean isCepEnabled) { |
| 9133 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9134 | |
| 9135 | final long identity = Binder.clearCallingIdentity(); |
| 9136 | try { |
| 9137 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9138 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9139 | Phone defaultPhone = phone.getImsPhone(); |
| 9140 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9141 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9142 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9143 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9144 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9145 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9146 | + imsPhone.getMsisdn()); |
| 9147 | } |
| 9148 | } |
| 9149 | } finally { |
| 9150 | Binder.restoreCallingIdentity(identity); |
| 9151 | } |
| 9152 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9153 | |
| 9154 | /** |
| 9155 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9156 | * |
| 9157 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9158 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9159 | * before being read. |
| 9160 | */ |
| 9161 | @Override |
| 9162 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9163 | isCompressed) { |
| 9164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9165 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9166 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9167 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9168 | } |
| 9169 | if (!isImsAvailableOnDevice()) { |
| 9170 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9171 | "IMS not available on device."); |
| 9172 | } |
| 9173 | |
| 9174 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9175 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9176 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9177 | } finally { |
| 9178 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9179 | } |
| 9180 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9181 | |
| 9182 | @Override |
| 9183 | public boolean isIccLockEnabled(int subId) { |
| 9184 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9185 | |
| 9186 | // Now that all security checks passes, perform the operation as ourselves. |
| 9187 | final long identity = Binder.clearCallingIdentity(); |
| 9188 | try { |
| 9189 | Phone phone = getPhone(subId); |
| 9190 | if (phone != null && phone.getIccCard() != null) { |
| 9191 | return phone.getIccCard().getIccLockEnabled(); |
| 9192 | } else { |
| 9193 | return false; |
| 9194 | } |
| 9195 | } finally { |
| 9196 | Binder.restoreCallingIdentity(identity); |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9201 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9202 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9203 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9204 | * three cases: |
| 9205 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9206 | * successfully. |
| 9207 | * - Positive number and zero for remaining password attempts. |
| 9208 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9209 | * |
| 9210 | */ |
| 9211 | @Override |
| 9212 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9213 | enforceModifyPermission(); |
| 9214 | |
| 9215 | Phone phone = getPhone(subId); |
| 9216 | if (phone == null) { |
| 9217 | return 0; |
| 9218 | } |
| 9219 | // Now that all security checks passes, perform the operation as ourselves. |
| 9220 | final long identity = Binder.clearCallingIdentity(); |
| 9221 | try { |
| 9222 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9223 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9224 | return attemptsRemaining; |
| 9225 | |
| 9226 | } catch (Exception e) { |
| 9227 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9228 | } finally { |
| 9229 | Binder.restoreCallingIdentity(identity); |
| 9230 | } |
| 9231 | return 0; |
| 9232 | } |
| 9233 | |
| 9234 | /** |
| 9235 | * Change the ICC password used in ICC pin lock. |
| 9236 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9237 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9238 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9239 | * - Positive number and zero for remaining password attempts. |
| 9240 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9241 | * |
| 9242 | */ |
| 9243 | @Override |
| 9244 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9245 | enforceModifyPermission(); |
| 9246 | |
| 9247 | Phone phone = getPhone(subId); |
| 9248 | if (phone == null) { |
| 9249 | return 0; |
| 9250 | } |
| 9251 | // Now that all security checks passes, perform the operation as ourselves. |
| 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
| 9254 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9255 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9256 | return attemptsRemaining; |
| 9257 | |
| 9258 | } catch (Exception e) { |
| 9259 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9260 | } finally { |
| 9261 | Binder.restoreCallingIdentity(identity); |
| 9262 | } |
| 9263 | return 0; |
| 9264 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9265 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9266 | /** |
| 9267 | * Request for receiving user activity notification |
| 9268 | */ |
| 9269 | @Override |
| 9270 | public void requestUserActivityNotification() { |
| 9271 | if (!mNotifyUserActivity.get() |
| 9272 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9273 | mNotifyUserActivity.set(true); |
| 9274 | } |
| 9275 | } |
| 9276 | |
| 9277 | /** |
| 9278 | * Called when userActivity is signalled in the power manager. |
| 9279 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9280 | */ |
| 9281 | @Override |
| 9282 | public void userActivity() { |
| 9283 | // *************************************** |
| 9284 | // * Inherited from PhoneWindowManager * |
| 9285 | // *************************************** |
| 9286 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9287 | // WITH ITS LOCKS HELD. |
| 9288 | // |
| 9289 | // This code must be VERY careful about the locks |
| 9290 | // it acquires. |
| 9291 | // In fact, the current code acquires way too many, |
| 9292 | // and probably has lurking deadlocks. |
| 9293 | |
| 9294 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9295 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9296 | } |
| 9297 | |
| 9298 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9299 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9300 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9301 | } |
| 9302 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9303 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9304 | @Override |
| 9305 | public boolean canConnectTo5GInDsdsMode() { |
| 9306 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9307 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9308 | |
| 9309 | @Override |
| 9310 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9311 | String callingFeatureId) { |
| 9312 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9313 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9314 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9315 | } |
| 9316 | |
| 9317 | Phone phone = getPhone(subId); |
| 9318 | if (phone == null) { |
| 9319 | throw new RuntimeException("phone is not available"); |
| 9320 | } |
| 9321 | // Now that all security checks passes, perform the operation as ourselves. |
| 9322 | final long identity = Binder.clearCallingIdentity(); |
| 9323 | try { |
| 9324 | return phone.getEquivalentHomePlmns(); |
| 9325 | } finally { |
| 9326 | Binder.restoreCallingIdentity(identity); |
| 9327 | } |
| 9328 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9329 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9330 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9331 | public boolean isRadioInterfaceCapabilitySupported( |
| 9332 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9333 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9334 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9335 | if (radioInterfaceCapabilities == null) { |
| 9336 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9337 | } else { |
| 9338 | return radioInterfaceCapabilities.isSupported(capability); |
| 9339 | } |
| 9340 | } |
| 9341 | |
| 9342 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9343 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9344 | UaSecurityProtocolIdentifier securityProtocol, |
| 9345 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9346 | throws RemoteException { |
| 9347 | enforceModifyPermission(); |
| 9348 | if (DBG) { |
| 9349 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9350 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9351 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9352 | } |
| 9353 | |
| 9354 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9355 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9356 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9357 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9358 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9359 | if (callback != null) { |
| 9360 | try { |
| 9361 | callback.onAuthenticationFailure( |
| 9362 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9363 | } catch (RemoteException exception) { |
| 9364 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9365 | } |
| 9366 | return; |
| 9367 | } |
| 9368 | } |
| 9369 | |
| 9370 | final long token = Binder.clearCallingIdentity(); |
| 9371 | try { |
| 9372 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9373 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9374 | forceBootStrapping, callback)); |
| 9375 | } finally { |
| 9376 | Binder.restoreCallingIdentity(token); |
| 9377 | } |
| 9378 | } |
| 9379 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9380 | /** |
| 9381 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9382 | * requested radio power state will actually be set. See {@link |
| 9383 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9384 | * |
| 9385 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9386 | * @param enable {@code true} if trying to turn radio on. |
| 9387 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9388 | * false}. |
| 9389 | */ |
| 9390 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9391 | Phone phone = getPhone(subId); |
| 9392 | if (phone != null) { |
| 9393 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9394 | return true; |
| 9395 | } |
| 9396 | return false; |
| 9397 | } |
| 9398 | |
| 9399 | private int handleDataThrottlingRequest(int subId, |
| 9400 | DataThrottlingRequest dataThrottlingRequest) { |
| 9401 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9402 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9403 | if (!setRadioPowerForThermal(subId, true)) { |
| 9404 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9405 | } |
| 9406 | |
| 9407 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9408 | |
| 9409 | int thermalMitigationResult = |
| 9410 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9411 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9412 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9413 | } |
| 9414 | return thermalMitigationResult; |
| 9415 | } |
| 9416 | |
| 9417 | /** |
| 9418 | * Thermal mitigation request to control functionalities at modem. |
| 9419 | * |
| 9420 | * @param subId the id of the subscription. |
| 9421 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9422 | * |
| 9423 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9424 | */ |
| 9425 | @Override |
| 9426 | @ThermalMitigationResult |
| 9427 | public int sendThermalMitigationRequest( |
| 9428 | int subId, |
| 9429 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9430 | enforceModifyPermission(); |
| 9431 | |
| 9432 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9433 | final long identity = Binder.clearCallingIdentity(); |
| 9434 | |
| 9435 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9436 | try { |
| 9437 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9438 | switch (thermalMitigationAction) { |
| 9439 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9440 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9441 | handleDataThrottlingRequest(subId, |
| 9442 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9443 | break; |
| 9444 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9445 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9446 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9447 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9448 | } |
| 9449 | |
| 9450 | // Ensure that radio is on. If not able to power on due to phone being |
| 9451 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9452 | if (!setRadioPowerForThermal(subId, true)) { |
| 9453 | thermalMitigationResult = |
| 9454 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9455 | break; |
| 9456 | } |
| 9457 | |
| 9458 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9459 | false); |
| 9460 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9461 | break; |
| 9462 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9463 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9464 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9465 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9466 | } |
| 9467 | |
| 9468 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9469 | if (registry != null) { |
| 9470 | TelephonyConnectionService service = |
| 9471 | registry.getTelephonyConnectionService(); |
| 9472 | Phone phone = getPhone(subId); |
| 9473 | if (phone == null) { |
| 9474 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9475 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9476 | break; |
| 9477 | } |
| 9478 | |
| 9479 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9480 | != TelephonyManager.CALL_STATE_IDLE |
| 9481 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9482 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9483 | String errorMessage = "Phone state is not valid. call state = " |
| 9484 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9485 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9486 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9487 | errorMessage += service == null |
| 9488 | ? " TelephonyConnectionService is null" |
| 9489 | : " isEmergencyCallPending = " |
| 9490 | + service.isEmergencyCallPending(); |
| 9491 | Log.e(LOG_TAG, errorMessage); |
| 9492 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9493 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9494 | break; |
| 9495 | } |
| 9496 | } else { |
| 9497 | thermalMitigationResult = |
| 9498 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9499 | break; |
| 9500 | } |
| 9501 | |
| 9502 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9503 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9504 | if (!setRadioPowerForThermal(subId, false)) { |
| 9505 | thermalMitigationResult = |
| 9506 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9507 | break; |
| 9508 | } |
| 9509 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9510 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9511 | break; |
| 9512 | default: |
| 9513 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9514 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9515 | } |
| 9516 | } catch (IllegalArgumentException e) { |
| 9517 | throw e; |
| 9518 | } catch (Exception e) { |
| 9519 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9520 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9521 | } finally { |
| 9522 | Binder.restoreCallingIdentity(identity); |
| 9523 | } |
| 9524 | |
| 9525 | if (DBG) { |
| 9526 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9527 | + thermalMitigationResult); |
| 9528 | } |
| 9529 | |
| 9530 | return thermalMitigationResult; |
| 9531 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9532 | |
| 9533 | /** |
| 9534 | * Set the GbaService Package Name that Telephony will bind to. |
| 9535 | * |
| 9536 | * @param subId The sim that the GbaService is associated with. |
| 9537 | * @param packageName The name of the package to be replaced with. |
| 9538 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9539 | */ |
| 9540 | @Override |
| 9541 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9542 | enforceModifyPermission(); |
| 9543 | |
| 9544 | final long identity = Binder.clearCallingIdentity(); |
| 9545 | try { |
| 9546 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9547 | } finally { |
| 9548 | Binder.restoreCallingIdentity(identity); |
| 9549 | } |
| 9550 | } |
| 9551 | |
| 9552 | /** |
| 9553 | * Return the package name of the currently bound GbaService. |
| 9554 | * |
| 9555 | * @param subId The sim that the GbaService is associated with. |
| 9556 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9557 | */ |
| 9558 | @Override |
| 9559 | public String getBoundGbaService(int subId) { |
| 9560 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9561 | |
| 9562 | final long identity = Binder.clearCallingIdentity(); |
| 9563 | try { |
| 9564 | return getGbaManager(subId).getServicePackage(); |
| 9565 | } finally { |
| 9566 | Binder.restoreCallingIdentity(identity); |
| 9567 | } |
| 9568 | } |
| 9569 | |
| 9570 | /** |
| 9571 | * Set the release time for telephony to unbind GbaService. |
| 9572 | * |
| 9573 | * @param subId The sim that the GbaService is associated with. |
| 9574 | * @param interval The release time to unbind GbaService by millisecond. |
| 9575 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9576 | */ |
| 9577 | @Override |
| 9578 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9579 | enforceModifyPermission(); |
| 9580 | |
| 9581 | final long identity = Binder.clearCallingIdentity(); |
| 9582 | try { |
| 9583 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9584 | } finally { |
| 9585 | Binder.restoreCallingIdentity(identity); |
| 9586 | } |
| 9587 | } |
| 9588 | |
| 9589 | /** |
| 9590 | * Return the release time for telephony to unbind GbaService. |
| 9591 | * |
| 9592 | * @param subId The sim that the GbaService is associated with. |
| 9593 | * @return The release time to unbind GbaService by millisecond. |
| 9594 | */ |
| 9595 | @Override |
| 9596 | public int getGbaReleaseTime(int subId) { |
| 9597 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9598 | |
| 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
| 9601 | return getGbaManager(subId).getReleaseTime(); |
| 9602 | } finally { |
| 9603 | Binder.restoreCallingIdentity(identity); |
| 9604 | } |
| 9605 | } |
| 9606 | |
| 9607 | private GbaManager getGbaManager(int subId) { |
| 9608 | GbaManager instance = GbaManager.getInstance(subId); |
| 9609 | if (instance == null) { |
| 9610 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9611 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9612 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9613 | } |
| 9614 | return instance; |
| 9615 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9616 | |
| 9617 | /** |
| 9618 | * indicate whether the device and the carrier can support |
| 9619 | * RCS VoLTE single registration. |
| 9620 | */ |
| 9621 | @Override |
| 9622 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9623 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9624 | |
| 9625 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9626 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9627 | } |
| 9628 | |
| 9629 | final long identity = Binder.clearCallingIdentity(); |
| 9630 | try { |
| 9631 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9632 | if (rpm != null) { |
| 9633 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9634 | } |
| 9635 | return false; |
| 9636 | } finally { |
| 9637 | Binder.restoreCallingIdentity(identity); |
| 9638 | } |
| 9639 | } |
| 9640 | |
| 9641 | /** |
| 9642 | * Register RCS provisioning callback. |
| 9643 | */ |
| 9644 | @Override |
| 9645 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9646 | IRcsConfigCallback callback) { |
| 9647 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9648 | |
| 9649 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9650 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9651 | } |
| 9652 | if (!isImsAvailableOnDevice()) { |
| 9653 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9654 | "IMS not available on device."); |
| 9655 | } |
| 9656 | |
| 9657 | final long identity = Binder.clearCallingIdentity(); |
| 9658 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9659 | if (!RcsProvisioningMonitor.getInstance() |
| 9660 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9661 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9662 | "Service not available for the subscription."); |
| 9663 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9664 | } finally { |
| 9665 | Binder.restoreCallingIdentity(identity); |
| 9666 | } |
| 9667 | } |
| 9668 | |
| 9669 | /** |
| 9670 | * Unregister RCS provisioning callback. |
| 9671 | */ |
| 9672 | @Override |
| 9673 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9674 | IRcsConfigCallback callback) { |
| 9675 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9676 | |
| 9677 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9678 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9679 | } |
| 9680 | if (!isImsAvailableOnDevice()) { |
| 9681 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9682 | "IMS not available on device."); |
| 9683 | } |
| 9684 | |
| 9685 | final long identity = Binder.clearCallingIdentity(); |
| 9686 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9687 | RcsProvisioningMonitor.getInstance() |
| 9688 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9689 | } finally { |
| 9690 | Binder.restoreCallingIdentity(identity); |
| 9691 | } |
| 9692 | } |
| 9693 | |
| 9694 | /** |
| 9695 | * trigger RCS reconfiguration. |
| 9696 | */ |
| 9697 | public void triggerRcsReconfiguration(int subId) { |
| 9698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9699 | mApp, subId, "triggerRcsReconfiguration"); |
| 9700 | |
| 9701 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9702 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9703 | } |
| 9704 | if (!isImsAvailableOnDevice()) { |
| 9705 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9706 | "IMS not available on device."); |
| 9707 | } |
| 9708 | |
| 9709 | final long identity = Binder.clearCallingIdentity(); |
| 9710 | try { |
| 9711 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9712 | } finally { |
| 9713 | Binder.restoreCallingIdentity(identity); |
| 9714 | } |
| 9715 | } |
| 9716 | |
| 9717 | /** |
| 9718 | * Provide the client configuration parameters of the RCS application. |
| 9719 | */ |
| 9720 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9722 | mApp, subId, "setRcsClientConfiguration"); |
| 9723 | |
| 9724 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9725 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9726 | } |
| 9727 | if (!isImsAvailableOnDevice()) { |
| 9728 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9729 | "IMS not available on device."); |
| 9730 | } |
| 9731 | |
| 9732 | final long identity = Binder.clearCallingIdentity(); |
| 9733 | |
| 9734 | try { |
| 9735 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9736 | if (configBinder == null) { |
| 9737 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9738 | } else { |
| 9739 | configBinder.setRcsClientConfiguration(rcc); |
| 9740 | } |
| 9741 | } catch (RemoteException e) { |
| 9742 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9743 | } finally { |
| 9744 | Binder.restoreCallingIdentity(identity); |
| 9745 | } |
| 9746 | } |
| 9747 | |
| 9748 | /** |
| 9749 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9750 | */ |
| 9751 | @Override |
| 9752 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9753 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9754 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9755 | enforceModifyPermission(); |
| 9756 | |
| 9757 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9758 | : Boolean.parseBoolean(enabledStr); |
| 9759 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9760 | } |
| 9761 | |
| 9762 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9763 | * Sends a device to device communication message. Only usable via shell. |
| 9764 | * @param message message to send. |
| 9765 | * @param value message value. |
| 9766 | */ |
| 9767 | @Override |
| 9768 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9769 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9770 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9771 | enforceModifyPermission(); |
| 9772 | |
| 9773 | final long identity = Binder.clearCallingIdentity(); |
| 9774 | try { |
| 9775 | TelephonyConnectionService service = |
| 9776 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9777 | if (service == null) { |
| 9778 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9779 | return; |
| 9780 | } |
| 9781 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9782 | } finally { |
| 9783 | Binder.restoreCallingIdentity(identity); |
| 9784 | } |
| 9785 | } |
| 9786 | |
| 9787 | |
| 9788 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9789 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9790 | */ |
| 9791 | @Override |
| 9792 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9793 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9794 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9795 | } |
| 9796 | |
| 9797 | /** |
| 9798 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9799 | */ |
| 9800 | @Override |
| 9801 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9802 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9803 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9804 | enforceModifyPermission(); |
| 9805 | |
| 9806 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9807 | : Boolean.parseBoolean(enabledStr); |
| 9808 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9809 | subId, enabled); |
| 9810 | } |
| 9811 | |
| 9812 | /** |
| 9813 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9814 | */ |
| 9815 | @Override |
| 9816 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9817 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9818 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9819 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9820 | |
| 9821 | /** |
| 9822 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9823 | * their mobile plan. |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public String getMobileProvisioningUrl() { |
| 9827 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9828 | final long identity = Binder.clearCallingIdentity(); |
| 9829 | try { |
| 9830 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9831 | } finally { |
| 9832 | Binder.restoreCallingIdentity(identity); |
| 9833 | } |
| 9834 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9835 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame^] | 9836 | /** |
| 9837 | * Remove the EAB contacts from the EAB database. |
| 9838 | */ |
| 9839 | @Override |
| 9840 | public int removeContactFromEab(int subId, String contacts) { |
| 9841 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9842 | enforceModifyPermission(); |
| 9843 | final long identity = Binder.clearCallingIdentity(); |
| 9844 | try { |
| 9845 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9846 | } finally { |
| 9847 | Binder.restoreCallingIdentity(identity); |
| 9848 | } |
| 9849 | } |
| 9850 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9851 | @Override |
| 9852 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9853 | String callingPackage) { |
| 9854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9855 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9856 | |
| 9857 | final int callingUid = Binder.getCallingUid(); |
| 9858 | // Verify that tha callingPackage belongs to the calling UID |
| 9859 | mApp.getSystemService(AppOpsManager.class) |
| 9860 | .checkPackage(callingUid, callingPackage); |
| 9861 | |
| 9862 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9863 | |
| 9864 | final long identity = Binder.clearCallingIdentity(); |
| 9865 | try { |
| 9866 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9867 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9868 | |
| 9869 | if (result instanceof IllegalStateException) { |
| 9870 | throw (IllegalStateException) result; |
| 9871 | } |
| 9872 | } finally { |
| 9873 | Binder.restoreCallingIdentity(identity); |
| 9874 | } |
| 9875 | } |
| 9876 | |
| 9877 | @Override |
| 9878 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9879 | String callingPackage) { |
| 9880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9881 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9882 | |
| 9883 | final int callingUid = Binder.getCallingUid(); |
| 9884 | // Verify that tha callingPackage belongs to the calling UID |
| 9885 | mApp.getSystemService(AppOpsManager.class) |
| 9886 | .checkPackage(callingUid, callingPackage); |
| 9887 | |
| 9888 | final long identity = Binder.clearCallingIdentity(); |
| 9889 | try { |
| 9890 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9891 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9892 | |
| 9893 | if (result instanceof IllegalStateException) { |
| 9894 | throw (IllegalStateException) result; |
| 9895 | } |
| 9896 | } finally { |
| 9897 | Binder.restoreCallingIdentity(identity); |
| 9898 | } |
| 9899 | } |
| 9900 | |
| 9901 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9902 | int callingUid) { |
| 9903 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9904 | // phone/system process do not have further restriction on request |
| 9905 | return; |
| 9906 | } |
| 9907 | |
| 9908 | // Applications has restrictions on how to use the request: |
| 9909 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9910 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9911 | // This is not system caller which has been checked above |
| 9912 | throw new IllegalArgumentException( |
| 9913 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9914 | } |
| 9915 | |
| 9916 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9917 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9918 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9919 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9920 | || info.isEnabled()) { |
| 9921 | throw new IllegalArgumentException( |
| 9922 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9923 | } |
| 9924 | |
| 9925 | // Thresholds length for each RAN need in range. This has been validated in |
| 9926 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9927 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9928 | final int[] thresholds = info.getThresholds(); |
| 9929 | Objects.requireNonNull(thresholds); |
| 9930 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9931 | || thresholds.length |
| 9932 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9933 | throw new IllegalArgumentException( |
| 9934 | "thresholds length is out of range: " + thresholds.length); |
| 9935 | } |
| 9936 | } |
| 9937 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9938 | } |