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; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
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; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 99 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 100 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 101 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 102 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 104 | import android.telephony.data.ApnSetting; |
| 105 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 106 | import android.telephony.gba.GbaAuthRequest; |
| 107 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 108 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 109 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 110 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 116 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 117 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 118 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 119 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 120 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 122 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 123 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 125 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 126 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 127 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 128 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 161 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 168 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 180 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 182 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 183 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 184 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 185 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 186 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 187 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 189 | import com.android.services.telephony.TelecomAccountRegistry; |
| 190 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 191 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 192 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 193 | import java.io.FileDescriptor; |
| 194 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 196 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 197 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 198 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 199 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 200 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 202 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 203 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 204 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 205 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | |
| 207 | /** |
| 208 | * Implementation of the ITelephony interface. |
| 209 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 210 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 212 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 213 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 214 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | |
| 216 | // Message codes used with mMainThreadHandler |
| 217 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 218 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 219 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 220 | private static final int CMD_OPEN_CHANNEL = 9; |
| 221 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 222 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 223 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 224 | private static final int CMD_NV_READ_ITEM = 13; |
| 225 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 226 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 227 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 228 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 229 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 230 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 231 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 232 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 233 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 234 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 235 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 236 | private static final int CMD_SEND_ENVELOPE = 25; |
| 237 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 238 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 239 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 240 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 241 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 242 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 243 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 244 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 245 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 246 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 247 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 248 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 249 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 250 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 251 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 252 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 253 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 254 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 255 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 256 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 257 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 258 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 259 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 260 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 261 | private static final int CMD_SWITCH_SLOTS = 50; |
| 262 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 263 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 264 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 265 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 266 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 267 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 268 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 269 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 270 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 271 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 272 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 273 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 274 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 275 | private static final int CMD_MODEM_REBOOT = 64; |
| 276 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 277 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 278 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 279 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 280 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 282 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 283 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 284 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 285 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 286 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 287 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 288 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 289 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 290 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 291 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 292 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 293 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 294 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 295 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 296 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 297 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 298 | private static final int CMD_GET_CALL_WAITING = 87; |
| 299 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 300 | private static final int CMD_SET_CALL_WAITING = 89; |
| 301 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 302 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 303 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 304 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 305 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 306 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 307 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 308 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 309 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 310 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 311 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 312 | private static final int CMD_SET_SIM_POWER = 101; |
| 313 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 314 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 315 | // Parameters of select command. |
| 316 | private static final int SELECT_COMMAND = 0xA4; |
| 317 | private static final int SELECT_P1 = 0x04; |
| 318 | private static final int SELECT_P2 = 0; |
| 319 | private static final int SELECT_P3 = 0x10; |
| 320 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 321 | /** The singleton instance. */ |
| 322 | private static PhoneInterfaceManager sInstance; |
| 323 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 324 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 325 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 326 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 327 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 328 | private AppOpsManager mAppOps; |
| 329 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 330 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 331 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 332 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 334 | /** User Activity */ |
| 335 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 336 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 337 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 338 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 339 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 340 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 341 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 342 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 343 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 344 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 345 | // String to store multi SIM allowed |
| 346 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 347 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 348 | // The AID of ISD-R. |
| 349 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 350 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 351 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 352 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 353 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 354 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 355 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 356 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 357 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 358 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 359 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 360 | */ |
| 361 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 362 | "reset_network_erase_modem_config_enabled"; |
| 363 | |
| 364 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 365 | * A request object to use for transmitting data to an ICC. |
| 366 | */ |
| 367 | private static final class IccAPDUArgument { |
| 368 | public int channel, cla, command, p1, p2, p3; |
| 369 | public String data; |
| 370 | |
| 371 | public IccAPDUArgument(int channel, int cla, int command, |
| 372 | int p1, int p2, int p3, String data) { |
| 373 | this.channel = channel; |
| 374 | this.cla = cla; |
| 375 | this.command = command; |
| 376 | this.p1 = p1; |
| 377 | this.p2 = p2; |
| 378 | this.p3 = p3; |
| 379 | this.data = data; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 384 | * A request object to use for transmitting data to an ICC. |
| 385 | */ |
| 386 | private static final class ManualNetworkSelectionArgument { |
| 387 | public OperatorInfo operatorInfo; |
| 388 | public boolean persistSelection; |
| 389 | |
| 390 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 391 | this.operatorInfo = operatorInfo; |
| 392 | this.persistSelection = persistSelection; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 397 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 398 | * request after sending. The main thread will notify the request when it is complete. |
| 399 | */ |
| 400 | private static final class MainThreadRequest { |
| 401 | /** The argument to use for the request */ |
| 402 | public Object argument; |
| 403 | /** The result of the request that is run on the main thread */ |
| 404 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 405 | // The subscriber id that this request applies to. Defaults to |
| 406 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 407 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 409 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 410 | public Phone phone; |
| 411 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 412 | public WorkSource workSource; |
| 413 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | public MainThreadRequest(Object argument) { |
| 415 | this.argument = argument; |
| 416 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 417 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 418 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 419 | this.argument = argument; |
| 420 | if (phone != null) { |
| 421 | this.phone = phone; |
| 422 | } |
| 423 | this.workSource = workSource; |
| 424 | } |
| 425 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 426 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 427 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 428 | if (subId != null) { |
| 429 | this.subId = subId; |
| 430 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 431 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 432 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 435 | private static final class IncomingThirdPartyCallArgs { |
| 436 | public final ComponentName component; |
| 437 | public final String callId; |
| 438 | public final String callerDisplayName; |
| 439 | |
| 440 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 441 | String callerDisplayName) { |
| 442 | this.component = component; |
| 443 | this.callId = callId; |
| 444 | this.callerDisplayName = callerDisplayName; |
| 445 | } |
| 446 | } |
| 447 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 448 | /** |
| 449 | * A handler that processes messages on the main thread in the phone process. Since many |
| 450 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 451 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 452 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 453 | * on, which will be notified when the operation completes and will contain the result of the |
| 454 | * request. |
| 455 | * |
| 456 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 457 | * note that request.result must be set to something non-null for the calling thread to |
| 458 | * unblock. |
| 459 | */ |
| 460 | private final class MainThreadHandler extends Handler { |
| 461 | @Override |
| 462 | public void handleMessage(Message msg) { |
| 463 | MainThreadRequest request; |
| 464 | Message onCompleted; |
| 465 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 466 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 468 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | |
| 470 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | case CMD_HANDLE_USSD_REQUEST: { |
| 472 | request = (MainThreadRequest) msg.obj; |
| 473 | final Phone phone = getPhoneFromRequest(request); |
| 474 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 475 | String ussdRequest = ussdObject.first; |
| 476 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 477 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 478 | if (!isUssdApiAllowed(request.subId)) { |
| 479 | // Carrier does not support use of this API, return failure. |
| 480 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 481 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 482 | Bundle returnData = new Bundle(); |
| 483 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 484 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 485 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 486 | request.result = true; |
| 487 | notifyRequester(request); |
| 488 | return; |
| 489 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 490 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 491 | try { |
| 492 | request.result = phone != null |
| 493 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 494 | } catch (CallStateException cse) { |
| 495 | request.result = false; |
| 496 | } |
| 497 | // Wake up the requesting thread |
| 498 | notifyRequester(request); |
| 499 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 502 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 503 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 504 | final Phone phone = getPhoneFromRequest(request); |
| 505 | request.result = phone != null ? |
| 506 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 507 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 508 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 513 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 514 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 516 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 517 | if (uiccCard == null) { |
| 518 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 519 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 520 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 521 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 523 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 524 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 526 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 527 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 528 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 529 | break; |
| 530 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 532 | ar = (AsyncResult) msg.obj; |
| 533 | request = (MainThreadRequest) ar.userObj; |
| 534 | if (ar.exception == null && ar.result != null) { |
| 535 | request.result = ar.result; |
| 536 | } else { |
| 537 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 538 | if (ar.result == null) { |
| 539 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 540 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 542 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 543 | } else { |
| 544 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 545 | } |
| 546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 551 | request = (MainThreadRequest) msg.obj; |
| 552 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 553 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 554 | if (uiccCard == null) { |
| 555 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | } else { |
| 559 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 560 | request); |
| 561 | uiccCard.iccTransmitApduBasicChannel( |
| 562 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 563 | iccArgument.p3, iccArgument.data, onCompleted); |
| 564 | } |
| 565 | break; |
| 566 | |
| 567 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 568 | ar = (AsyncResult) msg.obj; |
| 569 | request = (MainThreadRequest) ar.userObj; |
| 570 | if (ar.exception == null && ar.result != null) { |
| 571 | request.result = ar.result; |
| 572 | } else { |
| 573 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 574 | if (ar.result == null) { |
| 575 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 576 | } else if (ar.exception instanceof CommandException) { |
| 577 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 578 | ar.exception); |
| 579 | } else { |
| 580 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 581 | } |
| 582 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | break; |
| 585 | |
| 586 | case CMD_EXCHANGE_SIM_IO: |
| 587 | request = (MainThreadRequest) msg.obj; |
| 588 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 589 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | if (uiccCard == null) { |
| 591 | loge("iccExchangeSimIO: No UICC"); |
| 592 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
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 | } else { |
| 595 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 596 | request); |
| 597 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 598 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 599 | iccArgument.data, onCompleted); |
| 600 | } |
| 601 | break; |
| 602 | |
| 603 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
| 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
| 608 | } else { |
| 609 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 610 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 611 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 612 | break; |
| 613 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 614 | case CMD_SEND_ENVELOPE: |
| 615 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 616 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | if (uiccCard == null) { |
| 618 | loge("sendEnvelopeWithStatus: No UICC"); |
| 619 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } else { |
| 622 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 623 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 624 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 625 | break; |
| 626 | |
| 627 | case EVENT_SEND_ENVELOPE_DONE: |
| 628 | ar = (AsyncResult) msg.obj; |
| 629 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 630 | if (ar.exception == null && ar.result != null) { |
| 631 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 632 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 633 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 634 | if (ar.result == null) { |
| 635 | loge("sendEnvelopeWithStatus: Empty response"); |
| 636 | } else if (ar.exception instanceof CommandException) { |
| 637 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 638 | ar.exception); |
| 639 | } else { |
| 640 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 641 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 644 | break; |
| 645 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | case CMD_OPEN_CHANNEL: |
| 647 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 648 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 649 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 650 | if (uiccCard == null) { |
| 651 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 652 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 653 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 654 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 655 | } else { |
| 656 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 657 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 658 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case EVENT_OPEN_CHANNEL_DONE: |
| 663 | ar = (AsyncResult) msg.obj; |
| 664 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | int[] result = (int[]) ar.result; |
| 668 | int channelId = result[0]; |
| 669 | byte[] selectResponse = null; |
| 670 | if (result.length > 1) { |
| 671 | selectResponse = new byte[result.length - 1]; |
| 672 | for (int i = 1; i < result.length; ++i) { |
| 673 | selectResponse[i - 1] = (byte) result[i]; |
| 674 | } |
| 675 | } |
| 676 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 677 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | if (ar.result == null) { |
| 680 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 681 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | if (ar.exception != null) { |
| 683 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 684 | } |
| 685 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 686 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 687 | if (ar.exception instanceof CommandException) { |
| 688 | CommandException.Error error = |
| 689 | ((CommandException) (ar.exception)).getCommandError(); |
| 690 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 691 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 692 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 693 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 697 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 699 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case CMD_CLOSE_CHANNEL: |
| 704 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 705 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 706 | if (uiccCard == null) { |
| 707 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 708 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 709 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 710 | } else { |
| 711 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 712 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 713 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 717 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 718 | break; |
| 719 | |
| 720 | case CMD_NV_READ_ITEM: |
| 721 | request = (MainThreadRequest) msg.obj; |
| 722 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 724 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | ar = (AsyncResult) msg.obj; |
| 729 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | if (ar.exception == null && ar.result != null) { |
| 731 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 732 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | request.result = ""; |
| 734 | if (ar.result == null) { |
| 735 | loge("nvReadItem: Empty response"); |
| 736 | } else if (ar.exception instanceof CommandException) { |
| 737 | loge("nvReadItem: CommandException: " + |
| 738 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 739 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } |
| 742 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | break; |
| 745 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | case CMD_NV_WRITE_ITEM: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 749 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 750 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 751 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
| 754 | case EVENT_NV_WRITE_ITEM_DONE: |
| 755 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 756 | break; |
| 757 | |
| 758 | case CMD_NV_WRITE_CDMA_PRL: |
| 759 | request = (MainThreadRequest) msg.obj; |
| 760 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 761 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 762 | break; |
| 763 | |
| 764 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 765 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 766 | break; |
| 767 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 768 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 770 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 771 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 772 | break; |
| 773 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 774 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 775 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 778 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 779 | request = (MainThreadRequest) msg.obj; |
| 780 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 781 | request); |
| 782 | Phone phone = getPhoneFromRequest(request); |
| 783 | if (phone != null) { |
| 784 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 785 | } else { |
| 786 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 787 | request.result = false; |
| 788 | notifyRequester(request); |
| 789 | } |
| 790 | break; |
| 791 | } |
| 792 | |
| 793 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 794 | ar = (AsyncResult) msg.obj; |
| 795 | request = (MainThreadRequest) ar.userObj; |
| 796 | if (ar.exception == null && ar.result != null) { |
| 797 | request.result = ar.result; |
| 798 | } else { |
| 799 | // request.result must be set to something non-null |
| 800 | // for the calling thread to unblock |
| 801 | if (request.result != null) { |
| 802 | request.result = ar.result; |
| 803 | } else { |
| 804 | request.result = false; |
| 805 | } |
| 806 | if (ar.result == null) { |
| 807 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 808 | } else if (ar.exception instanceof CommandException) { |
| 809 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 810 | + ar.exception); |
| 811 | } else { |
| 812 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 813 | } |
| 814 | } |
| 815 | notifyRequester(request); |
| 816 | break; |
| 817 | |
| 818 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 821 | Phone phone = getPhoneFromRequest(request); |
| 822 | if (phone != null) { |
| 823 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 824 | request.workSource); |
| 825 | } else { |
| 826 | loge("enableNrDualConnectivity: No phone object"); |
| 827 | request.result = |
| 828 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 829 | notifyRequester(request); |
| 830 | } |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 835 | ar = (AsyncResult) msg.obj; |
| 836 | request = (MainThreadRequest) ar.userObj; |
| 837 | if (ar.exception == null) { |
| 838 | request.result = |
| 839 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 840 | } else { |
| 841 | request.result = |
| 842 | TelephonyManager |
| 843 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 844 | if (ar.exception instanceof CommandException) { |
| 845 | CommandException.Error error = |
| 846 | ((CommandException) (ar.exception)).getCommandError(); |
| 847 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 848 | request.result = |
| 849 | TelephonyManager |
| 850 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 851 | } |
| 852 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 853 | + ar.exception); |
| 854 | } else { |
| 855 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 856 | } |
| 857 | } |
| 858 | notifyRequester(request); |
| 859 | break; |
| 860 | } |
| 861 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 862 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 863 | request = (MainThreadRequest) msg.obj; |
| 864 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 865 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 869 | ar = (AsyncResult) msg.obj; |
| 870 | request = (MainThreadRequest) ar.userObj; |
| 871 | if (ar.exception == null && ar.result != null) { |
| 872 | request.result = ar.result; // Integer |
| 873 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 874 | // request.result must be set to something non-null |
| 875 | // for the calling thread to unblock |
| 876 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 877 | if (ar.result == null) { |
| 878 | loge("getPreferredNetworkType: Empty response"); |
| 879 | } else if (ar.exception instanceof CommandException) { |
| 880 | loge("getPreferredNetworkType: CommandException: " + |
| 881 | ar.exception); |
| 882 | } else { |
| 883 | loge("getPreferredNetworkType: Unknown exception"); |
| 884 | } |
| 885 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 886 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 890 | request = (MainThreadRequest) msg.obj; |
| 891 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 892 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 893 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 897 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 898 | break; |
| 899 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 900 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 901 | request = (MainThreadRequest)msg.obj; |
| 902 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 903 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 907 | ar = (AsyncResult)msg.obj; |
| 908 | request = (MainThreadRequest)ar.userObj; |
| 909 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 911 | break; |
| 912 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 913 | case CMD_SET_VOICEMAIL_NUMBER: |
| 914 | request = (MainThreadRequest) msg.obj; |
| 915 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 916 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 917 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 918 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 922 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 923 | break; |
| 924 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 925 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 926 | request = (MainThreadRequest) msg.obj; |
| 927 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 928 | request); |
| 929 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 930 | break; |
| 931 | |
| 932 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 933 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 934 | break; |
| 935 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 936 | case CMD_PERFORM_NETWORK_SCAN: |
| 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 939 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 940 | break; |
| 941 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 942 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 943 | request = (MainThreadRequest) msg.obj; |
| 944 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 945 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 946 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 947 | request.argument; |
| 948 | int callForwardingReason = args.first; |
| 949 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 950 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 951 | } |
| 952 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 953 | ar = (AsyncResult) msg.obj; |
| 954 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 955 | TelephonyManager.CallForwardingInfoCallback callback = |
| 956 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 957 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 958 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 960 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 961 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 962 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 963 | // any service for voice call. |
| 964 | if ((callForwardInfo.serviceClass |
| 965 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 966 | callForwardingInfo = new CallForwardingInfo(true, |
| 967 | callForwardInfo.reason, |
| 968 | callForwardInfo.number, |
| 969 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 970 | break; |
| 971 | } |
| 972 | } |
| 973 | // Didn't find a call forward info for voice call. |
| 974 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 976 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 977 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 979 | } else { |
| 980 | if (ar.result == null) { |
| 981 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 982 | } |
| 983 | if (ar.exception != null) { |
| 984 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 985 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 986 | int errorCode = TelephonyManager |
| 987 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 988 | if (ar.exception instanceof CommandException) { |
| 989 | CommandException.Error error = |
| 990 | ((CommandException) (ar.exception)).getCommandError(); |
| 991 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 992 | errorCode = TelephonyManager |
| 993 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 994 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 995 | errorCode = TelephonyManager |
| 996 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 997 | } |
| 998 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 999 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1000 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1001 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1003 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1005 | request = (MainThreadRequest) msg.obj; |
| 1006 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1008 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1009 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1010 | request.argument).first; |
| 1011 | request.phone.setCallForwardingOption( |
| 1012 | callForwardingInfoToSet.isEnabled() |
| 1013 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1014 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1015 | callForwardingInfoToSet.getReason(), |
| 1016 | callForwardingInfoToSet.getNumber(), |
| 1017 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1018 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1019 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1020 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1022 | ar = (AsyncResult) msg.obj; |
| 1023 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1024 | Consumer<Integer> callback = |
| 1025 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1026 | request.argument).second; |
| 1027 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1028 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1029 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1030 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | if (ar.exception instanceof CommandException) { |
| 1032 | CommandException.Error error = |
| 1033 | ((CommandException) (ar.exception)).getCommandError(); |
| 1034 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1035 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1036 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1039 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | callback.accept(errorCode); |
| 1043 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1044 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1045 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1046 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1048 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1052 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1053 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1055 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1057 | ar = (AsyncResult) msg.obj; |
| 1058 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1060 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1061 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1062 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1063 | // Service Class is a bit mask per 3gpp 27.007. |
| 1064 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1065 | if (callForwardResults.length > 1 |
| 1066 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1068 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1070 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1071 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1073 | } |
| 1074 | } else { |
| 1075 | if (ar.result == null) { |
| 1076 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1077 | } |
| 1078 | if (ar.exception != null) { |
| 1079 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1080 | } |
| 1081 | if (ar.exception instanceof CommandException) { |
| 1082 | CommandException.Error error = |
| 1083 | ((CommandException) (ar.exception)).getCommandError(); |
| 1084 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1085 | callForwardingStatus = |
| 1086 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1087 | } |
| 1088 | } |
| 1089 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1091 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1093 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1095 | request = (MainThreadRequest) msg.obj; |
| 1096 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1098 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1099 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1100 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1101 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1103 | ar = (AsyncResult) msg.obj; |
| 1104 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1106 | Consumer<Integer> callback = |
| 1107 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1108 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | if (ar.exception instanceof CommandException) { |
| 1111 | CommandException.Error error = |
| 1112 | ((CommandException) (ar.exception)).getCommandError(); |
| 1113 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1114 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1115 | } else { |
| 1116 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1117 | } |
| 1118 | } else { |
| 1119 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1120 | } |
| 1121 | } else { |
| 1122 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1123 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1124 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1125 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1126 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1127 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1128 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1129 | ar = (AsyncResult) msg.obj; |
| 1130 | request = (MainThreadRequest) ar.userObj; |
| 1131 | CellNetworkScanResult cellScanResult; |
| 1132 | if (ar.exception == null && ar.result != null) { |
| 1133 | cellScanResult = new CellNetworkScanResult( |
| 1134 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1135 | (List<OperatorInfo>) ar.result); |
| 1136 | } else { |
| 1137 | if (ar.result == null) { |
| 1138 | loge("getCellNetworkScanResults: Empty response"); |
| 1139 | } |
| 1140 | if (ar.exception != null) { |
| 1141 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1142 | } |
| 1143 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1144 | if (ar.exception instanceof CommandException) { |
| 1145 | CommandException.Error error = |
| 1146 | ((CommandException) (ar.exception)).getCommandError(); |
| 1147 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1148 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1149 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1150 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1151 | } |
| 1152 | } |
| 1153 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1154 | } |
| 1155 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1156 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1160 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1161 | ManualNetworkSelectionArgument selArg = |
| 1162 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1163 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1164 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1165 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1166 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1167 | break; |
| 1168 | |
| 1169 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1170 | ar = (AsyncResult) msg.obj; |
| 1171 | request = (MainThreadRequest) ar.userObj; |
| 1172 | if (ar.exception == null) { |
| 1173 | request.result = true; |
| 1174 | } else { |
| 1175 | request.result = false; |
| 1176 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1177 | } |
| 1178 | notifyRequester(request); |
| 1179 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1182 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1183 | request = (MainThreadRequest) msg.obj; |
| 1184 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1185 | if (defaultPhone != null) { |
| 1186 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1187 | } else { |
| 1188 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1189 | Bundle bundle = new Bundle(); |
| 1190 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1191 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1192 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1193 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | |
| 1196 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1197 | ar = (AsyncResult) msg.obj; |
| 1198 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1199 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1200 | |
| 1201 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1202 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1203 | // Update the last modem activity info and the result of the request. |
| 1204 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1205 | if (isModemActivityInfoValid(info)) { |
| 1206 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1207 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1208 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1209 | .getTransmitTimeMillis(); |
| 1210 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1211 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1212 | } |
| 1213 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1214 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1215 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1216 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1217 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1218 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1219 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1220 | info.getReceiveTimeMillis() |
| 1221 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1222 | } |
| 1223 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1224 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1225 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1226 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1227 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1228 | } else { |
| 1229 | if (ar.result == null) { |
| 1230 | loge("queryModemActivityInfo: Empty response"); |
| 1231 | } else if (ar.exception instanceof CommandException) { |
| 1232 | loge("queryModemActivityInfo: CommandException: " + |
| 1233 | ar.exception); |
| 1234 | } else { |
| 1235 | loge("queryModemActivityInfo: Unknown exception"); |
| 1236 | } |
| 1237 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1238 | Bundle bundle = new Bundle(); |
| 1239 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1240 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1241 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1242 | break; |
| 1243 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1244 | case CMD_SET_ALLOWED_CARRIERS: |
| 1245 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1246 | CarrierRestrictionRules argument = |
| 1247 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1248 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1249 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1250 | break; |
| 1251 | |
| 1252 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1253 | ar = (AsyncResult) msg.obj; |
| 1254 | request = (MainThreadRequest) ar.userObj; |
| 1255 | if (ar.exception == null && ar.result != null) { |
| 1256 | request.result = ar.result; |
| 1257 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1258 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1259 | if (ar.exception instanceof CommandException) { |
| 1260 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1261 | CommandException.Error error = |
| 1262 | ((CommandException) (ar.exception)).getCommandError(); |
| 1263 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1264 | request.result = |
| 1265 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1266 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1267 | } else { |
| 1268 | loge("setAllowedCarriers: Unknown exception"); |
| 1269 | } |
| 1270 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1271 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1272 | break; |
| 1273 | |
| 1274 | case CMD_GET_ALLOWED_CARRIERS: |
| 1275 | request = (MainThreadRequest) msg.obj; |
| 1276 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1277 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1278 | break; |
| 1279 | |
| 1280 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1281 | ar = (AsyncResult) msg.obj; |
| 1282 | request = (MainThreadRequest) ar.userObj; |
| 1283 | if (ar.exception == null && ar.result != null) { |
| 1284 | request.result = ar.result; |
| 1285 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1286 | request.result = new IllegalStateException( |
| 1287 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1288 | if (ar.result == null) { |
| 1289 | loge("getAllowedCarriers: Empty response"); |
| 1290 | } else if (ar.exception instanceof CommandException) { |
| 1291 | loge("getAllowedCarriers: CommandException: " + |
| 1292 | ar.exception); |
| 1293 | } else { |
| 1294 | loge("getAllowedCarriers: Unknown exception"); |
| 1295 | } |
| 1296 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1297 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1298 | break; |
| 1299 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1300 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1301 | ar = (AsyncResult) msg.obj; |
| 1302 | request = (MainThreadRequest) ar.userObj; |
| 1303 | if (ar.exception == null && ar.result != null) { |
| 1304 | request.result = ar.result; |
| 1305 | } else { |
| 1306 | request.result = new IllegalArgumentException( |
| 1307 | "Failed to retrieve Forbidden Plmns"); |
| 1308 | if (ar.result == null) { |
| 1309 | loge("getForbiddenPlmns: Empty response"); |
| 1310 | } else { |
| 1311 | loge("getForbiddenPlmns: Unknown exception"); |
| 1312 | } |
| 1313 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1314 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1315 | break; |
| 1316 | |
| 1317 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1318 | request = (MainThreadRequest) msg.obj; |
| 1319 | uiccCard = getUiccCardFromRequest(request); |
| 1320 | if (uiccCard == null) { |
| 1321 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1322 | request.result = new IllegalArgumentException( |
| 1323 | "getForbiddenPlmns() UiccCard is null"); |
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 | Integer appType = (Integer) request.argument; |
| 1328 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1329 | if (uiccApp == null) { |
| 1330 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1331 | + appType); |
| 1332 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1333 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1334 | break; |
| 1335 | } else { |
| 1336 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1337 | + " specified type -- " + appType); |
| 1338 | } |
| 1339 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1340 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1341 | onCompleted); |
| 1342 | break; |
| 1343 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1344 | case CMD_SWITCH_SLOTS: |
| 1345 | request = (MainThreadRequest) msg.obj; |
| 1346 | int[] physicalSlots = (int[]) request.argument; |
| 1347 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1348 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1349 | break; |
| 1350 | |
| 1351 | case EVENT_SWITCH_SLOTS_DONE: |
| 1352 | ar = (AsyncResult) msg.obj; |
| 1353 | request = (MainThreadRequest) ar.userObj; |
| 1354 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1355 | notifyRequester(request); |
| 1356 | break; |
| 1357 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1360 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1361 | break; |
| 1362 | |
| 1363 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1364 | ar = (AsyncResult) msg.obj; |
| 1365 | request = (MainThreadRequest) ar.userObj; |
| 1366 | if (ar.exception != null) { |
| 1367 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1368 | } else { |
| 1369 | int mode = ((int[]) ar.result)[0]; |
| 1370 | if (mode == 0) { |
| 1371 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1372 | } else { |
| 1373 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1374 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1375 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1376 | notifyRequester(request); |
| 1377 | break; |
| 1378 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1379 | request = (MainThreadRequest) msg.obj; |
| 1380 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1381 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1382 | break; |
| 1383 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1384 | ar = (AsyncResult) msg.obj; |
| 1385 | request = (MainThreadRequest) ar.userObj; |
| 1386 | if (ar.exception != null) { |
| 1387 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1388 | } else { |
| 1389 | request.result = ((int[]) ar.result)[0]; |
| 1390 | } |
| 1391 | notifyRequester(request); |
| 1392 | break; |
| 1393 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1394 | request = (MainThreadRequest) msg.obj; |
| 1395 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1396 | int mode = (int) request.argument; |
| 1397 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1398 | break; |
| 1399 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | request.result = ar.exception == null; |
| 1403 | notifyRequester(request); |
| 1404 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1405 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1406 | request = (MainThreadRequest) msg.obj; |
| 1407 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1408 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1409 | break; |
| 1410 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1411 | ar = (AsyncResult) msg.obj; |
| 1412 | request = (MainThreadRequest) ar.userObj; |
| 1413 | if (ar.exception != null) { |
| 1414 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1415 | } else { |
| 1416 | request.result = ((int[]) ar.result)[0]; |
| 1417 | } |
| 1418 | notifyRequester(request); |
| 1419 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1420 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1421 | request = (MainThreadRequest) msg.obj; |
| 1422 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1423 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1424 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1425 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1426 | break; |
| 1427 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1428 | ar = (AsyncResult) msg.obj; |
| 1429 | request = (MainThreadRequest) ar.userObj; |
| 1430 | request.result = ar.exception == null; |
| 1431 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1432 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1433 | case CMD_GET_ALL_CELL_INFO: |
| 1434 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1435 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1436 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1437 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1438 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1439 | ar = (AsyncResult) msg.obj; |
| 1440 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1441 | // If a timeout occurs, the response will be null |
| 1442 | request.result = (ar.exception == null && ar.result != null) |
| 1443 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1444 | synchronized (request) { |
| 1445 | request.notifyAll(); |
| 1446 | } |
| 1447 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1448 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1449 | request = (MainThreadRequest) msg.obj; |
| 1450 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1451 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1452 | break; |
| 1453 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
| 1456 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1457 | try { |
| 1458 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1459 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1460 | cb.onError( |
| 1461 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1462 | ar.exception.getClass().getName(), |
| 1463 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1464 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1465 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1466 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1467 | } else { |
| 1468 | // use the result as returned |
| 1469 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1470 | } |
| 1471 | } catch (RemoteException re) { |
| 1472 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1473 | } |
| 1474 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1475 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1476 | request = (MainThreadRequest) msg.obj; |
| 1477 | WorkSource ws = (WorkSource) request.argument; |
| 1478 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1479 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1480 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1481 | } |
| 1482 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1483 | ar = (AsyncResult) msg.obj; |
| 1484 | request = (MainThreadRequest) ar.userObj; |
| 1485 | if (ar.exception == null) { |
| 1486 | request.result = ar.result; |
| 1487 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1488 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1490 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | synchronized (request) { |
| 1494 | request.notifyAll(); |
| 1495 | } |
| 1496 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1497 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1498 | case CMD_MODEM_REBOOT: |
| 1499 | request = (MainThreadRequest) msg.obj; |
| 1500 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1501 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1502 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1503 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1504 | handleNullReturnEvent(msg, "rebootModem"); |
| 1505 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1506 | case CMD_REQUEST_ENABLE_MODEM: |
| 1507 | request = (MainThreadRequest) msg.obj; |
| 1508 | boolean enable = (boolean) request.argument; |
| 1509 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1510 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1511 | PhoneConfigurationManager.getInstance() |
| 1512 | .enablePhone(request.phone, enable, onCompleted); |
| 1513 | break; |
| 1514 | case EVENT_ENABLE_MODEM_DONE: |
| 1515 | ar = (AsyncResult) msg.obj; |
| 1516 | request = (MainThreadRequest) ar.userObj; |
| 1517 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1518 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1519 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1520 | if ((boolean) request.result) { |
| 1521 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1522 | updateModemStateMetrics(); |
| 1523 | } else { |
| 1524 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1525 | + ar.exception); |
| 1526 | } |
| 1527 | notifyRequester(request); |
| 1528 | break; |
| 1529 | case CMD_GET_MODEM_STATUS: |
| 1530 | request = (MainThreadRequest) msg.obj; |
| 1531 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1532 | PhoneConfigurationManager.getInstance() |
| 1533 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1534 | break; |
| 1535 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1536 | ar = (AsyncResult) msg.obj; |
| 1537 | request = (MainThreadRequest) ar.userObj; |
| 1538 | int id = request.phone.getPhoneId(); |
| 1539 | if (ar.exception == null && ar.result != null) { |
| 1540 | request.result = ar.result; |
| 1541 | //update the cache as modem status has changed |
| 1542 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1543 | (boolean) request.result); |
| 1544 | } else { |
| 1545 | // Return true if modem status cannot be retrieved. For most cases, |
| 1546 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1547 | // and disable modem are not supported. Modem is always on. |
| 1548 | // TODO: this should be fixed in R to support a third |
| 1549 | // status UNKNOWN b/131631629 |
| 1550 | request.result = true; |
| 1551 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1552 | + ar.exception); |
| 1553 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1554 | notifyRequester(request); |
| 1555 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1556 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1557 | request = (MainThreadRequest) msg.obj; |
| 1558 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1559 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1560 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1561 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1562 | break; |
| 1563 | } |
| 1564 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1565 | ar = (AsyncResult) msg.obj; |
| 1566 | request = (MainThreadRequest) ar.userObj; |
| 1567 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1568 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1569 | args.second.accept(ar.exception == null); |
| 1570 | notifyRequester(request); |
| 1571 | break; |
| 1572 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1573 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1574 | request = (MainThreadRequest) msg.obj; |
| 1575 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1576 | Phone phone = getPhoneFromRequest(request); |
| 1577 | if (phone != null) { |
| 1578 | phone.getSystemSelectionChannels(onCompleted); |
| 1579 | } else { |
| 1580 | loge("getSystemSelectionChannels: No phone object"); |
| 1581 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1582 | notifyRequester(request); |
| 1583 | } |
| 1584 | break; |
| 1585 | } |
| 1586 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1587 | ar = (AsyncResult) msg.obj; |
| 1588 | request = (MainThreadRequest) ar.userObj; |
| 1589 | if (ar.exception == null && ar.result != null) { |
| 1590 | request.result = ar.result; |
| 1591 | } else { |
| 1592 | request.result = new IllegalArgumentException( |
| 1593 | "Failed to retrieve system selection channels"); |
| 1594 | if (ar.result == null) { |
| 1595 | loge("getSystemSelectionChannels: Empty response"); |
| 1596 | } else { |
| 1597 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1598 | } |
| 1599 | } |
| 1600 | notifyRequester(request); |
| 1601 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1602 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1603 | ar = (AsyncResult) msg.obj; |
| 1604 | request = (MainThreadRequest) ar.userObj; |
| 1605 | if (ar.exception == null && ar.result != null) { |
| 1606 | request.result = ar.result; |
| 1607 | } else { |
| 1608 | request.result = -1; |
| 1609 | loge("Failed to set Forbidden Plmns"); |
| 1610 | if (ar.result == null) { |
| 1611 | loge("setForbidenPlmns: Empty response"); |
| 1612 | } else if (ar.exception != null) { |
| 1613 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1614 | request.result = -1; |
| 1615 | } else { |
| 1616 | loge("setForbiddenPlmns: Unknown exception"); |
| 1617 | } |
| 1618 | } |
| 1619 | notifyRequester(request); |
| 1620 | break; |
| 1621 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1622 | request = (MainThreadRequest) msg.obj; |
| 1623 | uiccCard = getUiccCardFromRequest(request); |
| 1624 | if (uiccCard == null) { |
| 1625 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1626 | request.result = -1; |
| 1627 | notifyRequester(request); |
| 1628 | break; |
| 1629 | } |
| 1630 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1631 | (Pair<Integer, List<String>>) request.argument; |
| 1632 | appType = setFplmnsArgs.first; |
| 1633 | List<String> fplmns = setFplmnsArgs.second; |
| 1634 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1635 | if (uiccApp == null) { |
| 1636 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1637 | request.result = -1; |
| 1638 | loge("Failed to get UICC App"); |
| 1639 | notifyRequester(request); |
| 1640 | } else { |
| 1641 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1642 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1643 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1644 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1645 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1646 | case CMD_ERASE_MODEM_CONFIG: |
| 1647 | request = (MainThreadRequest) msg.obj; |
| 1648 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1649 | defaultPhone.eraseModemConfig(onCompleted); |
| 1650 | break; |
| 1651 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1652 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1653 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1654 | |
| 1655 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1656 | request = (MainThreadRequest) msg.obj; |
| 1657 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1658 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1659 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1660 | changed.first, changed.second, onCompleted); |
| 1661 | break; |
| 1662 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1663 | ar = (AsyncResult) msg.obj; |
| 1664 | request = (MainThreadRequest) ar.userObj; |
| 1665 | if (ar.exception == null) { |
| 1666 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1667 | } else { |
| 1668 | request.result = msg.arg1; |
| 1669 | } |
| 1670 | notifyRequester(request); |
| 1671 | break; |
| 1672 | |
| 1673 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1676 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1677 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1678 | enabled.first, enabled.second, onCompleted); |
| 1679 | break; |
| 1680 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1681 | ar = (AsyncResult) msg.obj; |
| 1682 | request = (MainThreadRequest) ar.userObj; |
| 1683 | if (ar.exception == null) { |
| 1684 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1685 | } else { |
| 1686 | request.result = msg.arg1; |
| 1687 | } |
| 1688 | notifyRequester(request); |
| 1689 | break; |
| 1690 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1691 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1692 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1693 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1694 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1695 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1696 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1697 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1698 | |
| 1699 | case CMD_SET_DATA_THROTTLING: { |
| 1700 | request = (MainThreadRequest) msg.obj; |
| 1701 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1702 | DataThrottlingRequest dataThrottlingRequest = |
| 1703 | (DataThrottlingRequest) request.argument; |
| 1704 | Phone phone = getPhoneFromRequest(request); |
| 1705 | if (phone != null) { |
| 1706 | phone.setDataThrottling(onCompleted, |
| 1707 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1708 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1709 | } else { |
| 1710 | loge("setDataThrottling: No phone object"); |
| 1711 | request.result = |
| 1712 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1713 | notifyRequester(request); |
| 1714 | } |
| 1715 | |
| 1716 | break; |
| 1717 | } |
| 1718 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1719 | ar = (AsyncResult) msg.obj; |
| 1720 | request = (MainThreadRequest) ar.userObj; |
| 1721 | |
| 1722 | if (ar.exception == null) { |
| 1723 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1724 | } else if (ar.exception instanceof CommandException) { |
| 1725 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1726 | CommandException.Error error = |
| 1727 | ((CommandException) (ar.exception)).getCommandError(); |
| 1728 | |
| 1729 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1730 | request.result = TelephonyManager |
| 1731 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1732 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1733 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1734 | } else { |
| 1735 | request.result = |
| 1736 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1737 | } |
| 1738 | } else { |
| 1739 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1740 | } |
| 1741 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1742 | notifyRequester(request); |
| 1743 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1744 | |
| 1745 | case CMD_SET_SIM_POWER: { |
| 1746 | request = (MainThreadRequest) msg.obj; |
| 1747 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1748 | request = (MainThreadRequest) msg.obj; |
| 1749 | int stateToSet = |
| 1750 | ((Pair<Integer, IIntegerConsumer>) |
| 1751 | request.argument).first; |
| 1752 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1753 | break; |
| 1754 | } |
| 1755 | case EVENT_SET_SIM_POWER_DONE: { |
| 1756 | ar = (AsyncResult) msg.obj; |
| 1757 | request = (MainThreadRequest) ar.userObj; |
| 1758 | IIntegerConsumer callback = |
| 1759 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1760 | if (ar.exception != null) { |
| 1761 | loge("setSimPower exception: " + ar.exception); |
| 1762 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1763 | .RESULT_ERROR_UNKNOWN; |
| 1764 | if (ar.exception instanceof CommandException) { |
| 1765 | CommandException.Error error = |
| 1766 | ((CommandException) (ar.exception)).getCommandError(); |
| 1767 | if (error == CommandException.Error.SIM_ERR) { |
| 1768 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1769 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1770 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1771 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1772 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1773 | } else { |
| 1774 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1775 | } |
| 1776 | } |
| 1777 | try { |
| 1778 | callback.accept(errorCode); |
| 1779 | } catch (RemoteException e) { |
| 1780 | // Ignore if the remote process is no longer available to call back. |
| 1781 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1782 | } |
| 1783 | } else { |
| 1784 | try { |
| 1785 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1786 | } catch (RemoteException e) { |
| 1787 | // Ignore if the remote process is no longer available to call back. |
| 1788 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1789 | } |
| 1790 | } |
| 1791 | break; |
| 1792 | } |
| 1793 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1794 | default: |
| 1795 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1796 | break; |
| 1797 | } |
| 1798 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1799 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1800 | private void notifyRequester(MainThreadRequest request) { |
| 1801 | synchronized (request) { |
| 1802 | request.notifyAll(); |
| 1803 | } |
| 1804 | } |
| 1805 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1806 | private void handleNullReturnEvent(Message msg, String command) { |
| 1807 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1808 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1809 | if (ar.exception == null) { |
| 1810 | request.result = true; |
| 1811 | } else { |
| 1812 | request.result = false; |
| 1813 | if (ar.exception instanceof CommandException) { |
| 1814 | loge(command + ": CommandException: " + ar.exception); |
| 1815 | } else { |
| 1816 | loge(command + ": Unknown exception"); |
| 1817 | } |
| 1818 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1819 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1820 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | /** |
| 1824 | * Posts the specified command to be executed on the main thread, |
| 1825 | * waits for the request to complete, and returns the result. |
| 1826 | * @see #sendRequestAsync |
| 1827 | */ |
| 1828 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1829 | return sendRequest( |
| 1830 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * Posts the specified command to be executed on the main thread, |
| 1835 | * waits for the request to complete, and returns the result. |
| 1836 | * @see #sendRequestAsync |
| 1837 | */ |
| 1838 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1839 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1840 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * Posts the specified command to be executed on the main thread, |
| 1845 | * waits for the request to complete, and returns the result. |
| 1846 | * @see #sendRequestAsync |
| 1847 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1848 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1849 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * Posts the specified command to be executed on the main thread, |
| 1854 | * waits for the request to complete, and returns the result. |
| 1855 | * @see #sendRequestAsync |
| 1856 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1857 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1858 | return sendRequest(command, argument, subId, null, workSource); |
| 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * Posts the specified command to be executed on the main thread, |
| 1863 | * waits for the request to complete, and returns the result. |
| 1864 | * @see #sendRequestAsync |
| 1865 | */ |
| 1866 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1867 | return sendRequest( |
| 1868 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * Posts the specified command to be executed on the main thread, |
| 1873 | * waits for the request to complete, and returns the result. |
| 1874 | * @see #sendRequestAsync |
| 1875 | */ |
| 1876 | private Object sendRequest( |
| 1877 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1878 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1879 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1880 | } |
| 1881 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1882 | MainThreadRequest request = null; |
| 1883 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1884 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1885 | } else if (phone != null) { |
| 1886 | request = new MainThreadRequest(argument, phone, workSource); |
| 1887 | } else { |
| 1888 | request = new MainThreadRequest(argument, subId, workSource); |
| 1889 | } |
| 1890 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1892 | msg.sendToTarget(); |
| 1893 | |
| 1894 | // Wait for the request to complete |
| 1895 | synchronized (request) { |
| 1896 | while (request.result == null) { |
| 1897 | try { |
| 1898 | request.wait(); |
| 1899 | } catch (InterruptedException e) { |
| 1900 | // Do nothing, go back and wait until the request is complete |
| 1901 | } |
| 1902 | } |
| 1903 | } |
| 1904 | return request.result; |
| 1905 | } |
| 1906 | |
| 1907 | /** |
| 1908 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1909 | * Posts the specified command to be executed on the main thread, and |
| 1910 | * returns immediately. |
| 1911 | * @see #sendRequest |
| 1912 | */ |
| 1913 | private void sendRequestAsync(int command) { |
| 1914 | mMainThreadHandler.sendEmptyMessage(command); |
| 1915 | } |
| 1916 | |
| 1917 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1918 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1919 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1920 | */ |
| 1921 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1922 | sendRequestAsync(command, argument, null, null); |
| 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1927 | * @see {@link #sendRequest(int,Object)} |
| 1928 | */ |
| 1929 | private void sendRequestAsync( |
| 1930 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1931 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1932 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1933 | msg.sendToTarget(); |
| 1934 | } |
| 1935 | |
| 1936 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1937 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1938 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1939 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1940 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1941 | synchronized (PhoneInterfaceManager.class) { |
| 1942 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1943 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | } else { |
| 1945 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1946 | } |
| 1947 | return sInstance; |
| 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1952 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1955 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1956 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1958 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1959 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1960 | mTelephonySharedPreferences = |
| 1961 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1962 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1963 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1964 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1965 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | publish(); |
| 1967 | } |
| 1968 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1969 | private Phone getDefaultPhone() { |
| 1970 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1971 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1972 | } |
| 1973 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1974 | private void publish() { |
| 1975 | if (DBG) log("publish: " + this); |
| 1976 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1977 | TelephonyFrameworkInitializer |
| 1978 | .getTelephonyServiceManager() |
| 1979 | .getTelephonyServiceRegisterer() |
| 1980 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1983 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1984 | if (request.phone != null) { |
| 1985 | return request.phone; |
| 1986 | } else { |
| 1987 | return getPhoneFromSubId(request.subId); |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | private Phone getPhoneFromSubId(int subId) { |
| 1992 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1993 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1994 | } |
| 1995 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1996 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1997 | Phone phone = getPhoneFromRequest(request); |
| 1998 | return phone == null ? null : |
| 1999 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2000 | } |
| 2001 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2002 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2003 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2004 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2005 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2006 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2007 | private void sendEraseModemConfig(Phone phone) { |
| 2008 | if (phone != null) { |
| 2009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2010 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2011 | final long identity = Binder.clearCallingIdentity(); |
| 2012 | try { |
| 2013 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2014 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2015 | } finally { |
| 2016 | Binder.restoreCallingIdentity(identity); |
| 2017 | } |
| 2018 | } |
| 2019 | } |
| 2020 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2021 | private boolean isImsAvailableOnDevice() { |
| 2022 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2023 | if (pm == null) { |
| 2024 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2025 | // so do not throw error and allow. |
| 2026 | return true; |
| 2027 | } |
| 2028 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2029 | } |
| 2030 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2031 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2032 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2035 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2036 | if (DBG) log("dial: " + number); |
| 2037 | // No permission check needed here: This is just a wrapper around the |
| 2038 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2039 | // the UI before it does anything. |
| 2040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2041 | final long identity = Binder.clearCallingIdentity(); |
| 2042 | try { |
| 2043 | String url = createTelUrl(number); |
| 2044 | if (url == null) { |
| 2045 | return; |
| 2046 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2048 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2049 | PhoneConstants.State state = mCM.getState(subId); |
| 2050 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2051 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2052 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2053 | mApp.startActivity(intent); |
| 2054 | } |
| 2055 | } finally { |
| 2056 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | } |
| 2058 | } |
| 2059 | |
| 2060 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2061 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2064 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | if (DBG) log("call: " + number); |
| 2066 | |
| 2067 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2068 | // need to do a permission check since we're calling startActivity() |
| 2069 | // from the context of the phone app. |
| 2070 | enforceCallPermission(); |
| 2071 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2072 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | != AppOpsManager.MODE_ALLOWED) { |
| 2074 | return; |
| 2075 | } |
| 2076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2077 | final long identity = Binder.clearCallingIdentity(); |
| 2078 | try { |
| 2079 | String url = createTelUrl(number); |
| 2080 | if (url == null) { |
| 2081 | return; |
| 2082 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2084 | boolean isValid = false; |
| 2085 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2086 | if (slist != null) { |
| 2087 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2088 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2089 | isValid = true; |
| 2090 | break; |
| 2091 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2092 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2093 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | if (!isValid) { |
| 2095 | return; |
| 2096 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2098 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2099 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2100 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2101 | mApp.startActivity(intent); |
| 2102 | } finally { |
| 2103 | Binder.restoreCallingIdentity(identity); |
| 2104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2107 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2108 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2109 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2110 | } |
| 2111 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2112 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2113 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2114 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2115 | } |
| 2116 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2117 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2119 | |
| 2120 | final long identity = Binder.clearCallingIdentity(); |
| 2121 | try { |
| 2122 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2123 | checkSimPin.start(); |
| 2124 | return checkSimPin.unlockSim(null, pin); |
| 2125 | } finally { |
| 2126 | Binder.restoreCallingIdentity(identity); |
| 2127 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2130 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2132 | |
| 2133 | final long identity = Binder.clearCallingIdentity(); |
| 2134 | try { |
| 2135 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2136 | checkSimPuk.start(); |
| 2137 | return checkSimPuk.unlockSim(puk, pin); |
| 2138 | } finally { |
| 2139 | Binder.restoreCallingIdentity(identity); |
| 2140 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2144 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2145 | * a synchronous one. |
| 2146 | */ |
| 2147 | private static class UnlockSim extends Thread { |
| 2148 | |
| 2149 | private final IccCard mSimCard; |
| 2150 | |
| 2151 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2152 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2153 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | |
| 2155 | // For replies from SimCard interface |
| 2156 | private Handler mHandler; |
| 2157 | |
| 2158 | // For async handler to identify request type |
| 2159 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2160 | |
| 2161 | public UnlockSim(IccCard simCard) { |
| 2162 | mSimCard = simCard; |
| 2163 | } |
| 2164 | |
| 2165 | @Override |
| 2166 | public void run() { |
| 2167 | Looper.prepare(); |
| 2168 | synchronized (UnlockSim.this) { |
| 2169 | mHandler = new Handler() { |
| 2170 | @Override |
| 2171 | public void handleMessage(Message msg) { |
| 2172 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2173 | switch (msg.what) { |
| 2174 | case SUPPLY_PIN_COMPLETE: |
| 2175 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2176 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2177 | mRetryCount = msg.arg1; |
| 2178 | if (ar.exception != null) { |
| 2179 | if (ar.exception instanceof CommandException && |
| 2180 | ((CommandException)(ar.exception)).getCommandError() |
| 2181 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2182 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2183 | } //When UiccCardApp dispose,handle message and return exception |
| 2184 | else if (ar.exception instanceof CommandException && |
| 2185 | ((CommandException) (ar.exception)).getCommandError() |
| 2186 | == CommandException.Error.ABORTED) { |
| 2187 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2188 | } else { |
| 2189 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2190 | } |
| 2191 | } else { |
| 2192 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2193 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | mDone = true; |
| 2195 | UnlockSim.this.notifyAll(); |
| 2196 | } |
| 2197 | break; |
| 2198 | } |
| 2199 | } |
| 2200 | }; |
| 2201 | UnlockSim.this.notifyAll(); |
| 2202 | } |
| 2203 | Looper.loop(); |
| 2204 | } |
| 2205 | |
| 2206 | /* |
| 2207 | * Use PIN or PUK to unlock SIM card |
| 2208 | * |
| 2209 | * If PUK is null, unlock SIM card with PIN |
| 2210 | * |
| 2211 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2212 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2213 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2214 | |
| 2215 | while (mHandler == null) { |
| 2216 | try { |
| 2217 | wait(); |
| 2218 | } catch (InterruptedException e) { |
| 2219 | Thread.currentThread().interrupt(); |
| 2220 | } |
| 2221 | } |
| 2222 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2223 | |
| 2224 | if (puk == null) { |
| 2225 | mSimCard.supplyPin(pin, callback); |
| 2226 | } else { |
| 2227 | mSimCard.supplyPuk(puk, pin, callback); |
| 2228 | } |
| 2229 | |
| 2230 | while (!mDone) { |
| 2231 | try { |
| 2232 | Log.d(LOG_TAG, "wait for done"); |
| 2233 | wait(); |
| 2234 | } catch (InterruptedException e) { |
| 2235 | // Restore the interrupted status |
| 2236 | Thread.currentThread().interrupt(); |
| 2237 | } |
| 2238 | } |
| 2239 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2240 | int[] resultArray = new int[2]; |
| 2241 | resultArray[0] = mResult; |
| 2242 | resultArray[1] = mRetryCount; |
| 2243 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2247 | /** |
| 2248 | * This method has been removed due to privacy and stability concerns. |
| 2249 | */ |
| 2250 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2252 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2253 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2256 | @Override |
| 2257 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2258 | mApp.getSystemService(AppOpsManager.class) |
| 2259 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2260 | |
| 2261 | final int targetSdk = getTargetSdk(callingPackage); |
| 2262 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2263 | // Callers targeting S have no business invoking this method. |
| 2264 | return; |
| 2265 | } |
| 2266 | |
| 2267 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2268 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2269 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2270 | .setCallingPackage(callingPackage) |
| 2271 | .setCallingFeatureId(null) |
| 2272 | .setCallingPid(Binder.getCallingPid()) |
| 2273 | .setCallingUid(Binder.getCallingUid()) |
| 2274 | .setMethod("updateServiceLocation") |
| 2275 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2276 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2277 | .build()); |
| 2278 | // Apps that lack location permission have no business calling this method; |
| 2279 | // however, because no permission was declared in the public API, denials must |
| 2280 | // all be "soft". |
| 2281 | switch (locationResult) { |
| 2282 | case DENIED_HARD: /* fall through */ |
| 2283 | case DENIED_SOFT: |
| 2284 | return; |
| 2285 | } |
| 2286 | |
| 2287 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2288 | final long identity = Binder.clearCallingIdentity(); |
| 2289 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2290 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2291 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2292 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2293 | } |
| 2294 | } finally { |
| 2295 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2299 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2300 | @Override |
| 2301 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2302 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2305 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2306 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2307 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2308 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2309 | callingFeatureId); |
| 2310 | } |
| 2311 | |
| 2312 | @Deprecated |
| 2313 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2314 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2315 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2316 | } |
| 2317 | |
| 2318 | @Override |
| 2319 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2320 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2321 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2322 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2323 | return false; |
| 2324 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2325 | |
| 2326 | final long identity = Binder.clearCallingIdentity(); |
| 2327 | try { |
| 2328 | return isRadioOnForSubscriber(subId); |
| 2329 | } finally { |
| 2330 | Binder.restoreCallingIdentity(identity); |
| 2331 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2335 | final long identity = Binder.clearCallingIdentity(); |
| 2336 | try { |
| 2337 | final Phone phone = getPhone(subId); |
| 2338 | if (phone != null) { |
| 2339 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2340 | } else { |
| 2341 | return false; |
| 2342 | } |
| 2343 | } finally { |
| 2344 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2345 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2349 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2351 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2352 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2354 | |
| 2355 | final long identity = Binder.clearCallingIdentity(); |
| 2356 | try { |
| 2357 | final Phone phone = getPhone(subId); |
| 2358 | if (phone != null) { |
| 2359 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2360 | } |
| 2361 | } finally { |
| 2362 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2363 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
| 2366 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2367 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2370 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2371 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2372 | |
| 2373 | final long identity = Binder.clearCallingIdentity(); |
| 2374 | try { |
| 2375 | final Phone phone = getPhone(subId); |
| 2376 | if (phone == null) { |
| 2377 | return false; |
| 2378 | } |
| 2379 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2380 | toggleRadioOnOffForSubscriber(subId); |
| 2381 | } |
| 2382 | return true; |
| 2383 | } finally { |
| 2384 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2385 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2386 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2387 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2388 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2389 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2390 | /* |
| 2391 | * If any of the Radios are available, it will need to be |
| 2392 | * shutdown. So return true if any Radio is available. |
| 2393 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
| 2396 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2397 | Phone phone = PhoneFactory.getPhone(i); |
| 2398 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2399 | } |
| 2400 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2401 | return false; |
| 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2404 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2407 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2408 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2409 | enforceModifyPermission(); |
| 2410 | |
| 2411 | final long identity = Binder.clearCallingIdentity(); |
| 2412 | try { |
| 2413 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2414 | logv("Shutting down Phone " + i); |
| 2415 | shutdownRadioUsingPhoneId(i); |
| 2416 | } |
| 2417 | } finally { |
| 2418 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2423 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2424 | if (phone != null && phone.isRadioAvailable()) { |
| 2425 | phone.shutdownRadio(); |
| 2426 | } |
| 2427 | } |
| 2428 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2429 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2430 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | |
| 2432 | final long identity = Binder.clearCallingIdentity(); |
| 2433 | try { |
| 2434 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2435 | if (defaultPhone != null) { |
| 2436 | defaultPhone.setRadioPower(turnOn); |
| 2437 | return true; |
| 2438 | } else { |
| 2439 | loge("There's no default phone."); |
| 2440 | return false; |
| 2441 | } |
| 2442 | } finally { |
| 2443 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2444 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2447 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | |
| 2450 | final long identity = Binder.clearCallingIdentity(); |
| 2451 | try { |
| 2452 | final Phone phone = getPhone(subId); |
| 2453 | if (phone != null) { |
| 2454 | phone.setRadioPower(turnOn); |
| 2455 | return true; |
| 2456 | } else { |
| 2457 | return false; |
| 2458 | } |
| 2459 | } finally { |
| 2460 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2461 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2464 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2465 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | public boolean enableDataConnectivity() { |
| 2467 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | |
| 2469 | final long identity = Binder.clearCallingIdentity(); |
| 2470 | try { |
| 2471 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2472 | final Phone phone = getPhone(subId); |
| 2473 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2474 | phone.getDataEnabledSettings().setDataEnabled( |
| 2475 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2476 | return true; |
| 2477 | } else { |
| 2478 | return false; |
| 2479 | } |
| 2480 | } finally { |
| 2481 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2482 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2485 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2486 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | public boolean disableDataConnectivity() { |
| 2488 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | |
| 2490 | final long identity = Binder.clearCallingIdentity(); |
| 2491 | try { |
| 2492 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2493 | final Phone phone = getPhone(subId); |
| 2494 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2495 | phone.getDataEnabledSettings().setDataEnabled( |
| 2496 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | return true; |
| 2498 | } else { |
| 2499 | return false; |
| 2500 | } |
| 2501 | } finally { |
| 2502 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2506 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2507 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
| 2510 | final Phone phone = getPhone(subId); |
| 2511 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2512 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | } else { |
| 2514 | return false; |
| 2515 | } |
| 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2522 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2525 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | enforceCallPermission(); |
| 2527 | |
| 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2531 | return; |
| 2532 | } |
| 2533 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2534 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2538 | }; |
| 2539 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2540 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | |
| 2543 | final long identity = Binder.clearCallingIdentity(); |
| 2544 | try { |
| 2545 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2546 | return false; |
| 2547 | } |
| 2548 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2554 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2555 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2558 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | final long identity = Binder.clearCallingIdentity(); |
| 2560 | try { |
| 2561 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2562 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2563 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2564 | } finally { |
| 2565 | Binder.restoreCallingIdentity(identity); |
| 2566 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2569 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2570 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2571 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2572 | } |
| 2573 | |
| 2574 | @Override |
| 2575 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2576 | final long identity = Binder.clearCallingIdentity(); |
| 2577 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2578 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | if (phone != null) { |
| 2580 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2581 | } else { |
| 2582 | return PhoneConstantConversions.convertDataState( |
| 2583 | PhoneConstants.DataState.DISCONNECTED); |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2590 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2591 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2592 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2593 | } |
| 2594 | |
| 2595 | @Override |
| 2596 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2597 | final long identity = Binder.clearCallingIdentity(); |
| 2598 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2599 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | if (phone != null) { |
| 2601 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2602 | } else { |
| 2603 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2604 | } |
| 2605 | } finally { |
| 2606 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2611 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2612 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2613 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2614 | |
| 2615 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2616 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2617 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2618 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2619 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2620 | .setCallingPid(Binder.getCallingPid()) |
| 2621 | .setCallingUid(Binder.getCallingUid()) |
| 2622 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2623 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2624 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2625 | .build()); |
| 2626 | switch (locationResult) { |
| 2627 | case DENIED_HARD: |
| 2628 | throw new SecurityException("Not allowed to access cell location"); |
| 2629 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2630 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2631 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2634 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2638 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2639 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
| 2642 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2645 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2646 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2647 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2648 | // registered cell info, so return a NULL country instead. |
| 2649 | final long identity = Binder.clearCallingIdentity(); |
| 2650 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2651 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2652 | // Get default phone in this case. |
| 2653 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2654 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2655 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2657 | if (phone == null) return ""; |
| 2658 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2659 | if (sst == null) return ""; |
| 2660 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2661 | if (lt == null) return ""; |
| 2662 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2663 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2664 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
| 2667 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2670 | /** |
| 2671 | * This method was removed due to potential issues caused by performing partial |
| 2672 | * updates of service state, and lack of a credible use case. |
| 2673 | * |
| 2674 | * This has the ability to break the telephony implementation by disabling notification of |
| 2675 | * changes in device connectivity. DO NOT USE THIS! |
| 2676 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2677 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | public void enableLocationUpdates() { |
| 2679 | mApp.enforceCallingOrSelfPermission( |
| 2680 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2683 | /** |
| 2684 | * This method was removed due to potential issues caused by performing partial |
| 2685 | * updates of service state, and lack of a credible use case. |
| 2686 | * |
| 2687 | * This has the ability to break the telephony implementation by disabling notification of |
| 2688 | * changes in device connectivity. DO NOT USE THIS! |
| 2689 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2690 | @Override |
| 2691 | public void disableLocationUpdates() { |
| 2692 | mApp.enforceCallingOrSelfPermission( |
| 2693 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2696 | /** |
| 2697 | * Returns the target SDK version number for a given package name. |
| 2698 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2699 | * This call MUST be invoked before clearing the calling UID. |
| 2700 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2701 | * @return target SDK if the package is found or INT_MAX. |
| 2702 | */ |
| 2703 | private int getTargetSdk(String packageName) { |
| 2704 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2705 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2706 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2707 | if (ai != null) return ai.targetSdkVersion; |
| 2708 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2709 | loge("Failed to get package info for pkg=" |
| 2710 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2711 | } |
| 2712 | return Integer.MAX_VALUE; |
| 2713 | } |
| 2714 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | @Override |
| 2716 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2717 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2718 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2719 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2720 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2721 | throw new SecurityException( |
| 2722 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2723 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2724 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2725 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2727 | return null; |
| 2728 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2729 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2730 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2732 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2733 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2735 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2736 | for (CellInfo ci : info) { |
| 2737 | if (ci instanceof CellInfoGsm) { |
| 2738 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2739 | } else if (ci instanceof CellInfoWcdma) { |
| 2740 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2741 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2743 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2746 | private List<CellInfo> getCachedCellInfo() { |
| 2747 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2748 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2749 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2750 | if (info != null) cellInfos.addAll(info); |
| 2751 | } |
| 2752 | return cellInfos; |
| 2753 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | |
| 2755 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2756 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2757 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2758 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2759 | |
| 2760 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2761 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2762 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2763 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2764 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2765 | .setCallingPid(Binder.getCallingPid()) |
| 2766 | .setCallingUid(Binder.getCallingUid()) |
| 2767 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2768 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2769 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2770 | .build()); |
| 2771 | switch (locationResult) { |
| 2772 | case DENIED_HARD: |
| 2773 | throw new SecurityException("Not allowed to access cell info"); |
| 2774 | case DENIED_SOFT: |
| 2775 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2778 | final int targetSdk = getTargetSdk(callingPackage); |
| 2779 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2780 | return getCachedCellInfo(); |
| 2781 | } |
| 2782 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2783 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2784 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | final long identity = Binder.clearCallingIdentity(); |
| 2786 | try { |
| 2787 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2788 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2789 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2790 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2791 | if (info != null) cellInfos.addAll(info); |
| 2792 | } |
| 2793 | return cellInfos; |
| 2794 | } finally { |
| 2795 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | } |
| 2797 | } |
| 2798 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2799 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2800 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2801 | String callingFeatureId) { |
| 2802 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2803 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2807 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2808 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2809 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2810 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2813 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2814 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2815 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2816 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2817 | |
| 2818 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2819 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2820 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2821 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2822 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2823 | .setCallingPid(Binder.getCallingPid()) |
| 2824 | .setCallingUid(Binder.getCallingUid()) |
| 2825 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2826 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2827 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2828 | .build()); |
| 2829 | switch (locationResult) { |
| 2830 | case DENIED_HARD: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2831 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2832 | // Safetynet logging for b/154934934 |
| 2833 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2834 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2835 | throw new SecurityException("Not allowed to access cell info"); |
| 2836 | case DENIED_SOFT: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2837 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2838 | // Safetynet logging for b/154934934 |
| 2839 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2840 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2841 | try { |
| 2842 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2843 | } catch (RemoteException re) { |
| 2844 | // Drop without consequences |
| 2845 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2846 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2849 | |
| 2850 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2851 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2852 | |
| 2853 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2854 | } |
| 2855 | |
| 2856 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2858 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2859 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2860 | |
| 2861 | final long identity = Binder.clearCallingIdentity(); |
| 2862 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2863 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | } finally { |
| 2865 | Binder.restoreCallingIdentity(identity); |
| 2866 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | } |
| 2868 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2869 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2870 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2871 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2872 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2873 | return null; |
| 2874 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2875 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2876 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2877 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2878 | return null; |
| 2879 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | |
| 2881 | final long identity = Binder.clearCallingIdentity(); |
| 2882 | try { |
| 2883 | return phone.getImei(); |
| 2884 | } finally { |
| 2885 | Binder.restoreCallingIdentity(identity); |
| 2886 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2890 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2891 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2892 | String tac = null; |
| 2893 | if (phone != null) { |
| 2894 | String imei = phone.getImei(); |
| 2895 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2896 | } |
| 2897 | return tac; |
| 2898 | } |
| 2899 | |
| 2900 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2901 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2902 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2903 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2904 | return null; |
| 2905 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2906 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2907 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2908 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2909 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2910 | return null; |
| 2911 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2912 | |
| 2913 | final long identity = Binder.clearCallingIdentity(); |
| 2914 | try { |
| 2915 | return phone.getMeid(); |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
| 2918 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2922 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2923 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2924 | String manufacturerCode = null; |
| 2925 | if (phone != null) { |
| 2926 | String meid = phone.getMeid(); |
| 2927 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2928 | } |
| 2929 | return manufacturerCode; |
| 2930 | } |
| 2931 | |
| 2932 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2933 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2934 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2935 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2936 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2937 | return null; |
| 2938 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2939 | int subId = phone.getSubId(); |
| 2940 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2941 | mApp, subId, callingPackage, callingFeatureId, |
| 2942 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2943 | return null; |
| 2944 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | |
| 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | return phone.getDeviceSvn(); |
| 2949 | } finally { |
| 2950 | Binder.restoreCallingIdentity(identity); |
| 2951 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2954 | @Override |
| 2955 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | final Phone phone = getPhone(subId); |
| 2959 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2960 | } finally { |
| 2961 | Binder.restoreCallingIdentity(identity); |
| 2962 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | @Override |
| 2966 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | final Phone phone = getPhone(subId); |
| 2970 | return phone == null ? null : phone.getCarrierName(); |
| 2971 | } finally { |
| 2972 | Binder.restoreCallingIdentity(identity); |
| 2973 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2974 | } |
| 2975 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2976 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2977 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
| 2980 | final Phone phone = getPhone(subId); |
| 2981 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2982 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2983 | } finally { |
| 2984 | Binder.restoreCallingIdentity(identity); |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2989 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2990 | final long identity = Binder.clearCallingIdentity(); |
| 2991 | try { |
| 2992 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2993 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
| 2996 | } |
| 2997 | } |
| 2998 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2999 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3000 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3001 | if (!isSubscriptionMccMnc) { |
| 3002 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3003 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3004 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3005 | if (phone == null) { |
| 3006 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3007 | } |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
| 3013 | } |
| 3014 | } |
| 3015 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | // |
| 3017 | // Internal helper methods. |
| 3018 | // |
| 3019 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3020 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3021 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3022 | * |
| 3023 | * @throws SecurityException if the caller does not have the required permission |
| 3024 | */ |
| 3025 | private void enforceModifyPermission() { |
| 3026 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3027 | } |
| 3028 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3029 | /** |
| 3030 | * Make sure the caller is system. |
| 3031 | * |
| 3032 | * @throws SecurityException if the caller is not system. |
| 3033 | */ |
| 3034 | private void enforceSystemCaller() { |
| 3035 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3036 | throw new SecurityException("Caller must be system"); |
| 3037 | } |
| 3038 | } |
| 3039 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3040 | private void enforceActiveEmergencySessionPermission() { |
| 3041 | mApp.enforceCallingOrSelfPermission( |
| 3042 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3043 | } |
| 3044 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3045 | /** |
| 3046 | * Make sure the caller has the CALL_PHONE permission. |
| 3047 | * |
| 3048 | * @throws SecurityException if the caller does not have the required permission |
| 3049 | */ |
| 3050 | private void enforceCallPermission() { |
| 3051 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3052 | } |
| 3053 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3054 | private void enforceSettingsPermission() { |
| 3055 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3058 | private String createTelUrl(String number) { |
| 3059 | if (TextUtils.isEmpty(number)) { |
| 3060 | return null; |
| 3061 | } |
| 3062 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3063 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3064 | } |
| 3065 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3066 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3068 | } |
| 3069 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3070 | private static void logv(String msg) { |
| 3071 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3072 | } |
| 3073 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3074 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3075 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3076 | } |
| 3077 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3078 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3079 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3080 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3083 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3084 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | try { |
| 3087 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3088 | if (phone == null) { |
| 3089 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3090 | } else { |
| 3091 | return phone.getPhoneType(); |
| 3092 | } |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3095 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | /** |
| 3099 | * Returns the CDMA ERI icon index to display |
| 3100 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3101 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3102 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3103 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3104 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3107 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3108 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3109 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3111 | mApp, subId, callingPackage, callingFeatureId, |
| 3112 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3113 | return -1; |
| 3114 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | |
| 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
| 3118 | final Phone phone = getPhone(subId); |
| 3119 | if (phone != null) { |
| 3120 | return phone.getCdmaEriIconIndex(); |
| 3121 | } else { |
| 3122 | return -1; |
| 3123 | } |
| 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | /** |
| 3130 | * Returns the CDMA ERI icon mode, |
| 3131 | * 0 - ON |
| 3132 | * 1 - FLASHING |
| 3133 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3134 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3135 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3136 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3137 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3140 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3141 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3142 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3143 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3144 | mApp, subId, callingPackage, callingFeatureId, |
| 3145 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3146 | return -1; |
| 3147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | |
| 3149 | final long identity = Binder.clearCallingIdentity(); |
| 3150 | try { |
| 3151 | final Phone phone = getPhone(subId); |
| 3152 | if (phone != null) { |
| 3153 | return phone.getCdmaEriIconMode(); |
| 3154 | } else { |
| 3155 | return -1; |
| 3156 | } |
| 3157 | } finally { |
| 3158 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | /** |
| 3163 | * Returns the CDMA ERI text, |
| 3164 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3165 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3166 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3167 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3168 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3171 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3172 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3173 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3175 | mApp, subId, callingPackage, callingFeatureId, |
| 3176 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3177 | return null; |
| 3178 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3179 | |
| 3180 | final long identity = Binder.clearCallingIdentity(); |
| 3181 | try { |
| 3182 | final Phone phone = getPhone(subId); |
| 3183 | if (phone != null) { |
| 3184 | return phone.getCdmaEriText(); |
| 3185 | } else { |
| 3186 | return null; |
| 3187 | } |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3190 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3194 | * Returns the CDMA MDN. |
| 3195 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3196 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3197 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3199 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | |
| 3201 | final long identity = Binder.clearCallingIdentity(); |
| 3202 | try { |
| 3203 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3204 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | return phone.getLine1Number(); |
| 3206 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | return null; |
| 3209 | } |
| 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | /** |
| 3216 | * Returns the CDMA MIN. |
| 3217 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3218 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3219 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3221 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | |
| 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
| 3225 | final Phone phone = getPhone(subId); |
| 3226 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3227 | return phone.getCdmaMin(); |
| 3228 | } else { |
| 3229 | return null; |
| 3230 | } |
| 3231 | } finally { |
| 3232 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3233 | } |
| 3234 | } |
| 3235 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3236 | @Override |
| 3237 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3238 | INumberVerificationCallback callback, String callingPackage) { |
| 3239 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3240 | != PERMISSION_GRANTED) { |
| 3241 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3242 | } |
| 3243 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3244 | |
| 3245 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3246 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3247 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3248 | } |
| 3249 | |
| 3250 | if (range == null) { |
| 3251 | throw new NullPointerException("Range must be non-null"); |
| 3252 | } |
| 3253 | |
| 3254 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3255 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3256 | |
| 3257 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3258 | } |
| 3259 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3260 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3261 | * Returns true if CDMA provisioning needs to run. |
| 3262 | */ |
| 3263 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3264 | final long identity = Binder.clearCallingIdentity(); |
| 3265 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3266 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(identity); |
| 3269 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3273 | * Sets the voice mail number of a given subId. |
| 3274 | */ |
| 3275 | @Override |
| 3276 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3277 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3278 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3279 | |
| 3280 | final long identity = Binder.clearCallingIdentity(); |
| 3281 | try { |
| 3282 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3283 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3284 | return success; |
| 3285 | } finally { |
| 3286 | Binder.restoreCallingIdentity(identity); |
| 3287 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3288 | } |
| 3289 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3290 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3291 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3292 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3293 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3294 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3295 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3296 | throw new SecurityException("caller must be system dialer"); |
| 3297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3298 | |
| 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3302 | if (phoneAccountHandle == null) { |
| 3303 | return null; |
| 3304 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3305 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3306 | } finally { |
| 3307 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3308 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3312 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3313 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3314 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3315 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3316 | mApp, subId, callingPackage, callingFeatureId, |
| 3317 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3318 | return null; |
| 3319 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3320 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3323 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3324 | } finally { |
| 3325 | Binder.restoreCallingIdentity(identity); |
| 3326 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3330 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3331 | VisualVoicemailSmsFilterSettings settings) { |
| 3332 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | |
| 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3337 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | } finally { |
| 3339 | Binder.restoreCallingIdentity(identity); |
| 3340 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3344 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3345 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3346 | |
| 3347 | final long identity = Binder.clearCallingIdentity(); |
| 3348 | try { |
| 3349 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3350 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
| 3353 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
| 3356 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3357 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3358 | String callingPackage, int subId) { |
| 3359 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3360 | |
| 3361 | final long identity = Binder.clearCallingIdentity(); |
| 3362 | try { |
| 3363 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3364 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3365 | } finally { |
| 3366 | Binder.restoreCallingIdentity(identity); |
| 3367 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3371 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3372 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3373 | |
| 3374 | final long identity = Binder.clearCallingIdentity(); |
| 3375 | try { |
| 3376 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3377 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 | } finally { |
| 3379 | Binder.restoreCallingIdentity(identity); |
| 3380 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3384 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3385 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3386 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3387 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3388 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3389 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3390 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3391 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3392 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3393 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3394 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3395 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3396 | * Sets the voice activation state of a given subId. |
| 3397 | */ |
| 3398 | @Override |
| 3399 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3400 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3401 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3402 | |
| 3403 | final long identity = Binder.clearCallingIdentity(); |
| 3404 | try { |
| 3405 | final Phone phone = getPhone(subId); |
| 3406 | if (phone != null) { |
| 3407 | phone.setVoiceActivationState(activationState); |
| 3408 | } else { |
| 3409 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3410 | } |
| 3411 | } finally { |
| 3412 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3413 | } |
| 3414 | } |
| 3415 | |
| 3416 | /** |
| 3417 | * Sets the data activation state of a given subId. |
| 3418 | */ |
| 3419 | @Override |
| 3420 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3421 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3422 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | |
| 3424 | final long identity = Binder.clearCallingIdentity(); |
| 3425 | try { |
| 3426 | final Phone phone = getPhone(subId); |
| 3427 | if (phone != null) { |
| 3428 | phone.setDataActivationState(activationState); |
| 3429 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3430 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3431 | } |
| 3432 | } finally { |
| 3433 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | /** |
| 3438 | * Returns the voice activation state of a given subId. |
| 3439 | */ |
| 3440 | @Override |
| 3441 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3442 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3444 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3445 | final long identity = Binder.clearCallingIdentity(); |
| 3446 | try { |
| 3447 | if (phone != null) { |
| 3448 | return phone.getVoiceActivationState(); |
| 3449 | } else { |
| 3450 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3451 | } |
| 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3454 | } |
| 3455 | } |
| 3456 | |
| 3457 | /** |
| 3458 | * Returns the data activation state of a given subId. |
| 3459 | */ |
| 3460 | @Override |
| 3461 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3462 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3463 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3464 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | final long identity = Binder.clearCallingIdentity(); |
| 3466 | try { |
| 3467 | if (phone != null) { |
| 3468 | return phone.getDataActivationState(); |
| 3469 | } else { |
| 3470 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3471 | } |
| 3472 | } finally { |
| 3473 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3478 | * Returns the unread count of voicemails for a subId |
| 3479 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3480 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3481 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3482 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3483 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3484 | mApp, subId, callingPackage, callingFeatureId, |
| 3485 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3486 | return 0; |
| 3487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | final long identity = Binder.clearCallingIdentity(); |
| 3489 | try { |
| 3490 | final Phone phone = getPhone(subId); |
| 3491 | if (phone != null) { |
| 3492 | return phone.getVoiceMessageCount(); |
| 3493 | } else { |
| 3494 | return 0; |
| 3495 | } |
| 3496 | } finally { |
| 3497 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3502 | * returns true, if the device is in a state where both voice and data |
| 3503 | * are supported simultaneously. This can change based on location or network condition. |
| 3504 | */ |
| 3505 | @Override |
| 3506 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3507 | final long identity = Binder.clearCallingIdentity(); |
| 3508 | try { |
| 3509 | final Phone phone = getPhone(subId); |
| 3510 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3511 | } finally { |
| 3512 | Binder.restoreCallingIdentity(identity); |
| 3513 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3517 | * Send the dialer code if called from the current default dialer or the caller has |
| 3518 | * carrier privilege. |
| 3519 | * @param inputCode The dialer code to send |
| 3520 | */ |
| 3521 | @Override |
| 3522 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3523 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3524 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3525 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3526 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3527 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3529 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3530 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3531 | |
| 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3534 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3535 | } finally { |
| 3536 | Binder.restoreCallingIdentity(identity); |
| 3537 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3538 | } |
| 3539 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3540 | @Override |
| 3541 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3542 | TelephonyPermissions |
| 3543 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3544 | mApp, subId, "getNetworkSelectionMode"); |
| 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | if (!isActiveSubscription(subId)) { |
| 3548 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3549 | } |
| 3550 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3551 | } finally { |
| 3552 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3553 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3556 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3557 | public boolean isInEmergencySmsMode() { |
| 3558 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3559 | final long identity = Binder.clearCallingIdentity(); |
| 3560 | try { |
| 3561 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3562 | if (phone.isInEmergencySmsMode()) { |
| 3563 | return true; |
| 3564 | } |
| 3565 | } |
| 3566 | } finally { |
| 3567 | Binder.restoreCallingIdentity(identity); |
| 3568 | } |
| 3569 | return false; |
| 3570 | } |
| 3571 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3572 | /** |
| 3573 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3574 | * @param subId The subscription to use to check the configuration. |
| 3575 | * @param c The callback that will be used to send the result. |
| 3576 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3577 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3578 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3579 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3580 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3581 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3582 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3583 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3584 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3585 | "IMS not available on device."); |
| 3586 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3587 | final long token = Binder.clearCallingIdentity(); |
| 3588 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3589 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3590 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3591 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3592 | } catch (ImsException e) { |
| 3593 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(token); |
| 3596 | } |
| 3597 | } |
| 3598 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3599 | /** |
| 3600 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3601 | * @param subId The subscription to use to check the configuration. |
| 3602 | * @param c The callback that will be used to send the result. |
| 3603 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3605 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3606 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3607 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3609 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3610 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3611 | final long token = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3614 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3615 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3616 | } catch (ImsException e) { |
| 3617 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3618 | + "is inactive, ignoring unregister."); |
| 3619 | // If the subscription is no longer active, just return, since the callback |
| 3620 | // will already have been removed internally. |
| 3621 | } finally { |
| 3622 | Binder.restoreCallingIdentity(token); |
| 3623 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3624 | } |
| 3625 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3626 | /** |
| 3627 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3628 | */ |
| 3629 | @Override |
| 3630 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3631 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3632 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3633 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3634 | "IMS not available on device."); |
| 3635 | } |
| 3636 | final long token = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | Phone phone = getPhone(subId); |
| 3639 | if (phone == null) { |
| 3640 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3641 | + subId + "'"); |
| 3642 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3643 | } |
| 3644 | phone.getImsRegistrationState(regState -> { |
| 3645 | try { |
| 3646 | consumer.accept((regState == null) |
| 3647 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3648 | } catch (RemoteException e) { |
| 3649 | // Ignore if the remote process is no longer available to call back. |
| 3650 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3651 | } |
| 3652 | }); |
| 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(token); |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * Get the transport type for the IMS service registration state. |
| 3660 | */ |
| 3661 | @Override |
| 3662 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3663 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3664 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3665 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3667 | "IMS not available on device."); |
| 3668 | } |
| 3669 | final long token = Binder.clearCallingIdentity(); |
| 3670 | try { |
| 3671 | Phone phone = getPhone(subId); |
| 3672 | if (phone == null) { |
| 3673 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3674 | + subId + "'"); |
| 3675 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3676 | } |
| 3677 | phone.getImsRegistrationTech(regTech -> { |
| 3678 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3679 | int regTechConverted = (regTech == null) |
| 3680 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3681 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3682 | regTechConverted); |
| 3683 | try { |
| 3684 | consumer.accept(regTechConverted); |
| 3685 | } catch (RemoteException e) { |
| 3686 | // Ignore if the remote process is no longer available to call back. |
| 3687 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3688 | } |
| 3689 | }); |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(token); |
| 3692 | } |
| 3693 | } |
| 3694 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3695 | /** |
| 3696 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3697 | * @param subId The subscription to use to check the configuration. |
| 3698 | * @param c The callback that will be used to send the result. |
| 3699 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3701 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3702 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3703 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3704 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3705 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3706 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3707 | "IMS not available on device."); |
| 3708 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3709 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3710 | final long token = Binder.clearCallingIdentity(); |
| 3711 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3712 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3713 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3714 | } catch (ImsException e) { |
| 3715 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(token); |
| 3718 | } |
| 3719 | } |
| 3720 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3721 | /** |
| 3722 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3723 | * @param subId The subscription to use to check the configuration. |
| 3724 | * @param c The callback that will be used to send the result. |
| 3725 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3726 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3727 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3728 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3729 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3730 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3731 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3732 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3733 | |
| 3734 | final long token = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3737 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3738 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3739 | } catch (ImsException e) { |
| 3740 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3741 | + "is inactive, ignoring unregister."); |
| 3742 | // If the subscription is no longer active, just return, since the callback |
| 3743 | // will already have been removed internally. |
| 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(token); |
| 3746 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3750 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3751 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3753 | final long token = Binder.clearCallingIdentity(); |
| 3754 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3755 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3757 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3758 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3759 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3760 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3761 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3762 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(token); |
| 3765 | } |
| 3766 | } |
| 3767 | |
| 3768 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3769 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3770 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3771 | final long token = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | Phone phone = getPhone(subId); |
| 3774 | if (phone == null) return false; |
| 3775 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3776 | } catch (com.android.ims.ImsException e) { |
| 3777 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3778 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(token); |
| 3781 | } |
| 3782 | } |
| 3783 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3784 | /** |
| 3785 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3786 | * subscription. |
| 3787 | * @param subId The subscription to use to check the configuration. |
| 3788 | * @param callback The callback that will be used to send the result. |
| 3789 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3790 | * @param transportType The transport type of the MmTelFeature capability. |
| 3791 | */ |
| 3792 | @Override |
| 3793 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3794 | int transportType) { |
| 3795 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3796 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3798 | "IMS not available on device."); |
| 3799 | } |
| 3800 | final long token = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | int slotId = getSlotIndex(subId); |
| 3803 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3804 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3805 | + subId + "'"); |
| 3806 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3807 | } |
| 3808 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3809 | transportType, aBoolean -> { |
| 3810 | try { |
| 3811 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3812 | } catch (RemoteException e) { |
| 3813 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3814 | + "running. Ignore"); |
| 3815 | } |
| 3816 | }); |
| 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(token); |
| 3819 | } |
| 3820 | } |
| 3821 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3822 | /** |
| 3823 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3824 | * @param subId The subscription to use to check the configuration. |
| 3825 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | @Override |
| 3827 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3828 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3829 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3830 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3832 | final long token = Binder.clearCallingIdentity(); |
| 3833 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3834 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3835 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3836 | } catch (ImsException e) { |
| 3837 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | } finally { |
| 3839 | Binder.restoreCallingIdentity(token); |
| 3840 | } |
| 3841 | } |
| 3842 | |
| 3843 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3844 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3846 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3847 | final long identity = Binder.clearCallingIdentity(); |
| 3848 | try { |
| 3849 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3850 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3851 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3852 | } catch (ImsException e) { |
| 3853 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(identity); |
| 3856 | } |
| 3857 | } |
| 3858 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3859 | /** |
| 3860 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3861 | * @param subId The subscription to use to check the configuration. |
| 3862 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3863 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3864 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3865 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3866 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3867 | final long identity = Binder.clearCallingIdentity(); |
| 3868 | try { |
| 3869 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3870 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3871 | } catch (ImsException e) { |
| 3872 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
| 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3879 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3881 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3885 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3886 | } catch (ImsException e) { |
| 3887 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3888 | } finally { |
| 3889 | Binder.restoreCallingIdentity(identity); |
| 3890 | } |
| 3891 | } |
| 3892 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3893 | /** |
| 3894 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3895 | * @param subId The subscription to use to check the configuration. |
| 3896 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3897 | @Override |
| 3898 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3899 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3900 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3904 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3905 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3906 | } catch (ImsException e) { |
| 3907 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3908 | } finally { |
| 3909 | Binder.restoreCallingIdentity(identity); |
| 3910 | } |
| 3911 | } |
| 3912 | |
| 3913 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3914 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3916 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3917 | final long identity = Binder.clearCallingIdentity(); |
| 3918 | try { |
| 3919 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3920 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3921 | } catch (ImsException e) { |
| 3922 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(identity); |
| 3925 | } |
| 3926 | } |
| 3927 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3928 | /** |
| 3929 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3930 | * @param subId The subscription to use to check the configuration. |
| 3931 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3932 | @Override |
| 3933 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3934 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3935 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
| 3938 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3939 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3940 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3941 | } catch (ImsException e) { |
| 3942 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3943 | } finally { |
| 3944 | Binder.restoreCallingIdentity(identity); |
| 3945 | } |
| 3946 | } |
| 3947 | |
| 3948 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3949 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3951 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3956 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3957 | } catch (ImsException e) { |
| 3958 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | } finally { |
| 3960 | Binder.restoreCallingIdentity(identity); |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | @Override |
| 3965 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3967 | "setVoWiFiNonPersistent"); |
| 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3972 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3973 | } catch (ImsException e) { |
| 3974 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(identity); |
| 3977 | } |
| 3978 | } |
| 3979 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3980 | /** |
| 3981 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3982 | * @param subId The subscription to use to check the configuration. |
| 3983 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3984 | @Override |
| 3985 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3986 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3987 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
| 3990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3991 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3993 | } catch (ImsException e) { |
| 3994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | @Override |
| 4001 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4003 | "setVoWiFiModeSetting"); |
| 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4007 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4008 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4009 | } catch (ImsException e) { |
| 4010 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | @Override |
| 4017 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4018 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4019 | final long identity = Binder.clearCallingIdentity(); |
| 4020 | try { |
| 4021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4022 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4024 | } catch (ImsException e) { |
| 4025 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(identity); |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | @Override |
| 4032 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4034 | "setVoWiFiRoamingModeSetting"); |
| 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4038 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4040 | } catch (ImsException e) { |
| 4041 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4042 | } finally { |
| 4043 | Binder.restoreCallingIdentity(identity); |
| 4044 | } |
| 4045 | } |
| 4046 | |
| 4047 | @Override |
| 4048 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4050 | "setRttCapabilityEnabled"); |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4054 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4055 | } catch (ImsException e) { |
| 4056 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
| 4060 | } |
| 4061 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4062 | /** |
| 4063 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4064 | * @param subId The subscription to use to check the configuration. |
| 4065 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4066 | @Override |
| 4067 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4068 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4069 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
| 4072 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4073 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4075 | } catch (ImsException e) { |
| 4076 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4077 | } finally { |
| 4078 | Binder.restoreCallingIdentity(identity); |
| 4079 | } |
| 4080 | } |
| 4081 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4082 | @Override |
| 4083 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4084 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4085 | final long identity = Binder.clearCallingIdentity(); |
| 4086 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4087 | if (!isImsAvailableOnDevice()) { |
| 4088 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4089 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4090 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4091 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4092 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4093 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4094 | } catch (ImsException e) { |
| 4095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4096 | } finally { |
| 4097 | Binder.restoreCallingIdentity(identity); |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | @Override |
| 4102 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4103 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4104 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4105 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4106 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4107 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4108 | try { |
| 4109 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4110 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4111 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4112 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4113 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4114 | + "is inactive, ignoring unregister."); |
| 4115 | // If the subscription is no longer active, just return, since the callback will already |
| 4116 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4117 | } finally { |
| 4118 | Binder.restoreCallingIdentity(identity); |
| 4119 | } |
| 4120 | } |
| 4121 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4122 | |
| 4123 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4125 | message); |
| 4126 | } |
| 4127 | |
| 4128 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4129 | boolean isMmtelCapability) { |
| 4130 | Phone phone = getPhone(subId); |
| 4131 | if (phone == null) { |
| 4132 | loge("phone instance null for subid " + subId); |
| 4133 | return false; |
| 4134 | } |
| 4135 | if (isMmtelCapability) { |
| 4136 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4137 | return false; |
| 4138 | } |
| 4139 | } else { |
| 4140 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4141 | return false; |
| 4142 | } |
| 4143 | } |
| 4144 | return true; |
| 4145 | } |
| 4146 | |
| 4147 | @Override |
| 4148 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4149 | boolean isProvisioned) { |
| 4150 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4151 | |
| 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
| 4154 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4155 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4156 | return; |
| 4157 | } |
| 4158 | |
| 4159 | // this capability requires provisioning, route to the correct API. |
| 4160 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4161 | switch (capability) { |
| 4162 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4163 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4164 | ims.setEabProvisioned(isProvisioned); |
| 4165 | break; |
| 4166 | default: { |
| 4167 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4168 | + "rcs capability '" + capability + "', which does not require " |
| 4169 | + "provisioning."); |
| 4170 | } |
| 4171 | } |
| 4172 | } finally { |
| 4173 | Binder.restoreCallingIdentity(identity); |
| 4174 | } |
| 4175 | |
| 4176 | } |
| 4177 | |
| 4178 | |
| 4179 | @Override |
| 4180 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4181 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4182 | final long identity = Binder.clearCallingIdentity(); |
| 4183 | try { |
| 4184 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4185 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4186 | return true; |
| 4187 | } |
| 4188 | |
| 4189 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4190 | switch (capability) { |
| 4191 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4192 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4193 | return ims.isEabProvisionedOnDevice(); |
| 4194 | |
| 4195 | default: { |
| 4196 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4197 | + "capability '" + capability + "', which does not require " |
| 4198 | + "provisioning."); |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
| 4204 | } |
| 4205 | } |
| 4206 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4207 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4208 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4209 | boolean isProvisioned) { |
| 4210 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4211 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4212 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4213 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4214 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4215 | final long identity = Binder.clearCallingIdentity(); |
| 4216 | try { |
| 4217 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4218 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4219 | return; |
| 4220 | } |
| 4221 | |
| 4222 | // this capability requires provisioning, route to the correct API. |
| 4223 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4224 | switch (capability) { |
| 4225 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4226 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4227 | ims.setVolteProvisioned(isProvisioned); |
| 4228 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4229 | ims.setWfcProvisioned(isProvisioned); |
| 4230 | } |
| 4231 | break; |
| 4232 | } |
| 4233 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4234 | // There is currently no difference in VT provisioning type. |
| 4235 | ims.setVtProvisioned(isProvisioned); |
| 4236 | break; |
| 4237 | } |
| 4238 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4239 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4240 | // change the capability of the feature instead if needed. |
| 4241 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4242 | == isProvisioned) { |
| 4243 | // No change in provisioning. |
| 4244 | return; |
| 4245 | } |
| 4246 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4247 | try { |
| 4248 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4249 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4250 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4251 | + ", Exception" + e.getMessage()); |
| 4252 | } |
| 4253 | break; |
| 4254 | } |
| 4255 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4256 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4257 | + "MmTel capability '" + capability + "', which does not require " |
| 4258 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(identity); |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | @Override |
| 4268 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4269 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4270 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4271 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4272 | } |
| 4273 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4274 | final long identity = Binder.clearCallingIdentity(); |
| 4275 | try { |
| 4276 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4277 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4278 | return true; |
| 4279 | } |
| 4280 | |
| 4281 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4282 | switch (capability) { |
| 4283 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4284 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4285 | return ims.isVolteProvisionedOnDevice(); |
| 4286 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4287 | return ims.isWfcProvisionedOnDevice(); |
| 4288 | } |
| 4289 | // This should never happen, since we are checking tech above to make sure it |
| 4290 | // is either LTE or IWLAN. |
| 4291 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4292 | + "capability."); |
| 4293 | } |
| 4294 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4295 | // There is currently no difference in VT provisioning type. |
| 4296 | return ims.isVtProvisionedOnDevice(); |
| 4297 | } |
| 4298 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4299 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4300 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4301 | } |
| 4302 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4303 | throw new IllegalArgumentException( |
| 4304 | "Tried to get provisioning for MmTel capability '" + capability |
| 4305 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | } finally { |
| 4310 | Binder.restoreCallingIdentity(identity); |
| 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | @Override |
| 4315 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4316 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4317 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4318 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4319 | } |
| 4320 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4321 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4322 | return (provisionedBits & capability) > 0; |
| 4323 | } |
| 4324 | |
| 4325 | @Override |
| 4326 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4327 | boolean isProvisioned) { |
| 4328 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4329 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4330 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4331 | } |
| 4332 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4333 | "setProvisioningStatusForCapability"); |
| 4334 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4335 | // If the current provisioning status for capability already matches isProvisioned, |
| 4336 | // do nothing. |
| 4337 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4338 | return; |
| 4339 | } |
| 4340 | if (isProvisioned) { |
| 4341 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4342 | } else { |
| 4343 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4344 | } |
| 4345 | } |
| 4346 | |
| 4347 | /** |
| 4348 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4349 | * technology. The bitfield should mirror the bitfield defined by |
| 4350 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4351 | */ |
| 4352 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4353 | String key = getMmTelProvisioningKey(subId, tech); |
| 4354 | // Default is no capabilities are provisioned. |
| 4355 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4356 | } |
| 4357 | |
| 4358 | /** |
| 4359 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4360 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4361 | * technology specified. |
| 4362 | * |
| 4363 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4364 | */ |
| 4365 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4366 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4367 | String key = getMmTelProvisioningKey(subId, tech); |
| 4368 | editor.putInt(key, newField); |
| 4369 | editor.commit(); |
| 4370 | } |
| 4371 | |
| 4372 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4373 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4374 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4375 | } |
| 4376 | |
| 4377 | /** |
| 4378 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4379 | * carrier associated with the subscription id. |
| 4380 | */ |
| 4381 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4382 | int capability) { |
| 4383 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4384 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4385 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4386 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4387 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4388 | false); |
| 4389 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4390 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4391 | |
| 4392 | // First check to make sure that the capability requires provisioning. |
| 4393 | switch (capability) { |
| 4394 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4395 | // intentional fallthrough |
| 4396 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4397 | if (requireVoiceVtProvisioning) { |
| 4398 | // Voice and Video requires provisioning |
| 4399 | return true; |
| 4400 | } |
| 4401 | break; |
| 4402 | } |
| 4403 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4404 | if (requireUtProvisioning) { |
| 4405 | // UT requires provisioning |
| 4406 | return true; |
| 4407 | } |
| 4408 | break; |
| 4409 | } |
| 4410 | } |
| 4411 | return false; |
| 4412 | } |
| 4413 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4414 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4415 | int capability) { |
| 4416 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4417 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4418 | |
| 4419 | boolean requireRcsProvisioning = c.getBoolean( |
| 4420 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4421 | |
| 4422 | // First check to make sure that the capability requires provisioning. |
| 4423 | switch (capability) { |
| 4424 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4425 | // intentional fallthrough |
| 4426 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4427 | if (requireRcsProvisioning) { |
| 4428 | // OPTION or PRESENCE requires provisioning |
| 4429 | return true; |
| 4430 | } |
| 4431 | break; |
| 4432 | } |
| 4433 | } |
| 4434 | return false; |
| 4435 | } |
| 4436 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4437 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4438 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4439 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4440 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4441 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4442 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4443 | final long identity = Binder.clearCallingIdentity(); |
| 4444 | try { |
| 4445 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4446 | int slotId = getSlotIndex(subId); |
| 4447 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4448 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4449 | + subId + "' for key:" + key); |
| 4450 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4451 | } |
| 4452 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4453 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4454 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4455 | + subId + "' for key:" + key); |
| 4456 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4457 | } finally { |
| 4458 | Binder.restoreCallingIdentity(identity); |
| 4459 | } |
| 4460 | } |
| 4461 | |
| 4462 | @Override |
| 4463 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4464 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4465 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4466 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4467 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
| 4470 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4471 | int slotId = getSlotIndex(subId); |
| 4472 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4473 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4474 | + subId + "' for key:" + key); |
| 4475 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4476 | } |
| 4477 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4478 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4479 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4480 | + subId + "' for key:" + key); |
| 4481 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4482 | } finally { |
| 4483 | Binder.restoreCallingIdentity(identity); |
| 4484 | } |
| 4485 | } |
| 4486 | |
| 4487 | @Override |
| 4488 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4489 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4490 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4491 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4493 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4494 | final long identity = Binder.clearCallingIdentity(); |
| 4495 | try { |
| 4496 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4497 | int slotId = getSlotIndex(subId); |
| 4498 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4499 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4500 | + subId + "' for key:" + key); |
| 4501 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4502 | } |
| 4503 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4504 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4505 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4506 | + "' for key:" + key); |
| 4507 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | @Override |
| 4514 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4515 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4516 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4517 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4519 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
| 4522 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4523 | int slotId = getSlotIndex(subId); |
| 4524 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4525 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4526 | + subId + "' for key:" + key); |
| 4527 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4528 | } |
| 4529 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4530 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4531 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4532 | + "' for key:" + key); |
| 4533 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4534 | } finally { |
| 4535 | Binder.restoreCallingIdentity(identity); |
| 4536 | } |
| 4537 | } |
| 4538 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4539 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4540 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4541 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4542 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4543 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | } |
| 4545 | return slotId; |
| 4546 | } |
| 4547 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4548 | private int getSlotIndex(int subId) { |
| 4549 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4550 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4551 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4552 | } |
| 4553 | return slotId; |
| 4554 | } |
| 4555 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4556 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4557 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4558 | */ |
| 4559 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4560 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4561 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4562 | final int targetSdk = getTargetSdk(callingPackage); |
| 4563 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4564 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4565 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4566 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4567 | mApp, subId, callingPackage, callingFeatureId, |
| 4568 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4569 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4570 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4572 | final long identity = Binder.clearCallingIdentity(); |
| 4573 | try { |
| 4574 | final Phone phone = getPhone(subId); |
| 4575 | if (phone != null) { |
| 4576 | return phone.getServiceState().getDataNetworkType(); |
| 4577 | } else { |
| 4578 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4579 | } |
| 4580 | } finally { |
| 4581 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | /** |
| 4586 | * Returns the data network type |
| 4587 | */ |
| 4588 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4589 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4590 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4591 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4592 | } |
| 4593 | |
| 4594 | /** |
| 4595 | * Returns the data network type for a subId |
| 4596 | */ |
| 4597 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4598 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4599 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4600 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4601 | mApp, subId, callingPackage, callingFeatureId, |
| 4602 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4603 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4604 | } |
| 4605 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
| 4608 | final Phone phone = getPhone(subId); |
| 4609 | if (phone != null) { |
| 4610 | return phone.getServiceState().getDataNetworkType(); |
| 4611 | } else { |
| 4612 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4613 | } |
| 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4616 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4620 | * Returns the Voice network type for a subId |
| 4621 | */ |
| 4622 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4623 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4624 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4625 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4626 | mApp, subId, callingPackage, callingFeatureId, |
| 4627 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4628 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4629 | } |
| 4630 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
| 4633 | final Phone phone = getPhone(subId); |
| 4634 | if (phone != null) { |
| 4635 | return phone.getServiceState().getVoiceNetworkType(); |
| 4636 | } else { |
| 4637 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4638 | } |
| 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | /** |
| 4645 | * @return true if a ICC card is present |
| 4646 | */ |
| 4647 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4648 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4649 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4650 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4651 | } |
| 4652 | |
| 4653 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4654 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4655 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4656 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4657 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
| 4660 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4661 | if (phone != null) { |
| 4662 | return phone.getIccCard().hasIccCard(); |
| 4663 | } else { |
| 4664 | return false; |
| 4665 | } |
| 4666 | } finally { |
| 4667 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4669 | } |
| 4670 | |
| 4671 | /** |
| 4672 | * Return if the current radio is LTE on CDMA. This |
| 4673 | * is a tri-state return value as for a period of time |
| 4674 | * the mode may be unknown. |
| 4675 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4676 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4677 | * @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] | 4678 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4679 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4680 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4681 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4682 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4683 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4684 | } |
| 4685 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4686 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4687 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4688 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4689 | try { |
| 4690 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4691 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4692 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4693 | } |
| 4694 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | final long identity = Binder.clearCallingIdentity(); |
| 4696 | try { |
| 4697 | final Phone phone = getPhone(subId); |
| 4698 | if (phone == null) { |
| 4699 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4700 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4701 | return TelephonyProperties.lte_on_cdma_device() |
| 4702 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4703 | } |
| 4704 | } finally { |
| 4705 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4706 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4707 | } |
| 4708 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4709 | /** |
| 4710 | * {@hide} |
| 4711 | * Returns Default subId, 0 in the case of single standby. |
| 4712 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4713 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4714 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4717 | private int getSlotForDefaultSubscription() { |
| 4718 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4719 | } |
| 4720 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4721 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4722 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4723 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4724 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4725 | private boolean isActiveSubscription(int subId) { |
| 4726 | return mSubscriptionController.isActiveSubId(subId); |
| 4727 | } |
| 4728 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4729 | /** |
| 4730 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4731 | */ |
| 4732 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | final long identity = Binder.clearCallingIdentity(); |
| 4734 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4735 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4736 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4737 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4738 | } finally { |
| 4739 | Binder.restoreCallingIdentity(identity); |
| 4740 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | /** |
| 4744 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4745 | */ |
| 4746 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4747 | final long identity = Binder.clearCallingIdentity(); |
| 4748 | try { |
| 4749 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4750 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4751 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
| 4754 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4755 | } |
| 4756 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4757 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4758 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4759 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4760 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4761 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4762 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4763 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4764 | if (phoneId == -1) { |
| 4765 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4766 | + " does not correspond to an active phone"); |
| 4767 | } |
| 4768 | return PhoneFactory.getPhone(phoneId); |
| 4769 | } |
| 4770 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4771 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4772 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4773 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4774 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4775 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4777 | if (DBG) { |
| 4778 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4779 | } |
| 4780 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4781 | p2); |
| 4782 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4783 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4784 | |
| 4785 | @Override |
| 4786 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4787 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4788 | enforceModifyPermission(); |
| 4789 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4790 | if (DBG) { |
| 4791 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4792 | } |
| 4793 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4794 | callingPackage, aid, p2); |
| 4795 | } |
| 4796 | |
| 4797 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4798 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
| 4801 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4802 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4803 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4804 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4805 | if (bestComponent == null |
| 4806 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4807 | loge("The calling package is not allowed to access ISD-R."); |
| 4808 | throw new SecurityException( |
| 4809 | "The calling package is not allowed to access ISD-R."); |
| 4810 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4811 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4812 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4813 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4814 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4815 | null /* workSource */); |
| 4816 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4817 | return response; |
| 4818 | } finally { |
| 4819 | Binder.restoreCallingIdentity(identity); |
| 4820 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4824 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4826 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4827 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4828 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4829 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4830 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4831 | @Override |
| 4832 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4833 | enforceModifyPermission(); |
| 4834 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4835 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4836 | channel); |
| 4837 | } |
| 4838 | |
| 4839 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4840 | final long identity = Binder.clearCallingIdentity(); |
| 4841 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | if (channel < 0) { |
| 4843 | return false; |
| 4844 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4845 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4846 | null /* workSource */); |
| 4847 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 | return success; |
| 4849 | } finally { |
| 4850 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4851 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4852 | } |
| 4853 | |
| 4854 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4855 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4856 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4858 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4859 | if (DBG) { |
| 4860 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4861 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4862 | + p3 + " data=" + data); |
| 4863 | } |
| 4864 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4865 | command, p1, p2, p3, data); |
| 4866 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4867 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4868 | @Override |
| 4869 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4870 | int command, int p1, int p2, int p3, String data) { |
| 4871 | enforceModifyPermission(); |
| 4872 | if (DBG) { |
| 4873 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4874 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4875 | + p3 + " data=" + data); |
| 4876 | } |
| 4877 | return iccTransmitApduLogicalChannelWithPermission( |
| 4878 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4879 | data); |
| 4880 | } |
| 4881 | |
| 4882 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4883 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4884 | final long identity = Binder.clearCallingIdentity(); |
| 4885 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4886 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4887 | return ""; |
| 4888 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4889 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4891 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4892 | null /* workSource */); |
| 4893 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4894 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | // Append the returned status code to the end of the response payload. |
| 4896 | String s = Integer.toHexString( |
| 4897 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4898 | if (response.payload != null) { |
| 4899 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4900 | } |
| 4901 | return s; |
| 4902 | } finally { |
| 4903 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4904 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4905 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4906 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4907 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4908 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4909 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4911 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4912 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4913 | if (DBG) { |
| 4914 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4915 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4916 | } |
| 4917 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4918 | cla, command, p1, p2, p3, data); |
| 4919 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4920 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4921 | @Override |
| 4922 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4923 | int command, int p1, int p2, int p3, String data) { |
| 4924 | enforceModifyPermission(); |
| 4925 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4926 | if (DBG) { |
| 4927 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4928 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4929 | + " data=" + data); |
| 4930 | } |
| 4931 | |
| 4932 | return iccTransmitApduBasicChannelWithPermission( |
| 4933 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4934 | p2, p3, data); |
| 4935 | } |
| 4936 | |
| 4937 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4938 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4939 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | final long identity = Binder.clearCallingIdentity(); |
| 4941 | try { |
| 4942 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4943 | && TextUtils.equals(ISDR_AID, data)) { |
| 4944 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4945 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4946 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4947 | if (bestComponent == null |
| 4948 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4949 | loge("The calling package is not allowed to select ISD-R."); |
| 4950 | throw new SecurityException( |
| 4951 | "The calling package is not allowed to select ISD-R."); |
| 4952 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4953 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4954 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4955 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4956 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4957 | null /* workSource */); |
| 4958 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | // Append the returned status code to the end of the response payload. |
| 4961 | String s = Integer.toHexString( |
| 4962 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4963 | if (response.payload != null) { |
| 4964 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4965 | } |
| 4966 | return s; |
| 4967 | } finally { |
| 4968 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4969 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4970 | } |
| 4971 | |
| 4972 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4973 | 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] | 4974 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4976 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4977 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | final long identity = Binder.clearCallingIdentity(); |
| 4979 | try { |
| 4980 | if (DBG) { |
| 4981 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4982 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4983 | } |
| 4984 | |
| 4985 | IccIoResult response = |
| 4986 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4987 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4988 | subId); |
| 4989 | |
| 4990 | if (DBG) { |
| 4991 | log("Exchange SIM_IO [R]" + response); |
| 4992 | } |
| 4993 | |
| 4994 | byte[] result = null; |
| 4995 | int length = 2; |
| 4996 | if (response.payload != null) { |
| 4997 | length = 2 + response.payload.length; |
| 4998 | result = new byte[length]; |
| 4999 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5000 | } else { |
| 5001 | result = new byte[length]; |
| 5002 | } |
| 5003 | |
| 5004 | result[length - 1] = (byte) response.sw2; |
| 5005 | result[length - 2] = (byte) response.sw1; |
| 5006 | return result; |
| 5007 | } finally { |
| 5008 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5009 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5010 | } |
| 5011 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5012 | /** |
| 5013 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5014 | * on a particular subscription |
| 5015 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5016 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5017 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5018 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5019 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5020 | return null; |
| 5021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | |
| 5023 | final long identity = Binder.clearCallingIdentity(); |
| 5024 | try { |
| 5025 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5026 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5027 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5028 | return null; |
| 5029 | } |
| 5030 | Object response = sendRequest( |
| 5031 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5032 | if (response instanceof String[]) { |
| 5033 | return (String[]) response; |
| 5034 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5035 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5036 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5037 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5040 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5041 | } |
| 5042 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5043 | /** |
| 5044 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5045 | * subscription. |
| 5046 | * |
| 5047 | * @param subId the id of the subscription. |
| 5048 | * @param appType the uicc app type, must be USIM or SIM. |
| 5049 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5050 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5051 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5052 | * @return number of fplmns that is successfully written to the SIM. |
| 5053 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5054 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5055 | String callingFeatureId) { |
| 5056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5057 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5058 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5059 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5060 | } |
| 5061 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5062 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5063 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5064 | } |
| 5065 | if (fplmns == null) { |
| 5066 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5067 | } |
| 5068 | for (String fplmn : fplmns) { |
| 5069 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5070 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5071 | } |
| 5072 | } |
| 5073 | final long identity = Binder.clearCallingIdentity(); |
| 5074 | try { |
| 5075 | Object response = sendRequest( |
| 5076 | CMD_SET_FORBIDDEN_PLMNS, |
| 5077 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5078 | subId); |
| 5079 | return (int) response; |
| 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
| 5082 | } |
| 5083 | } |
| 5084 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5085 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5086 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5088 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
| 5092 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5093 | if (response.payload == null) { |
| 5094 | return ""; |
| 5095 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5096 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | // Append the returned status code to the end of the response payload. |
| 5098 | String s = Integer.toHexString( |
| 5099 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5100 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5101 | return s; |
| 5102 | } finally { |
| 5103 | Binder.restoreCallingIdentity(identity); |
| 5104 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5107 | /** |
| 5108 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5109 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5110 | * |
| 5111 | * @param itemID the ID of the item to read |
| 5112 | * @return the NV item as a String, or null on error. |
| 5113 | */ |
| 5114 | @Override |
| 5115 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5116 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5117 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5118 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5119 | |
| 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
| 5122 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5123 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5124 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5125 | return value; |
| 5126 | } finally { |
| 5127 | Binder.restoreCallingIdentity(identity); |
| 5128 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | /** |
| 5132 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5133 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5134 | * |
| 5135 | * @param itemID the ID of the item to read |
| 5136 | * @param itemValue the value to write, as a String |
| 5137 | * @return true on success; false on any failure |
| 5138 | */ |
| 5139 | @Override |
| 5140 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5141 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5143 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | |
| 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
| 5147 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5148 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5149 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5151 | return success; |
| 5152 | } finally { |
| 5153 | Binder.restoreCallingIdentity(identity); |
| 5154 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5155 | } |
| 5156 | |
| 5157 | /** |
| 5158 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5159 | * Used for device configuration by some CDMA operators. |
| 5160 | * |
| 5161 | * @param preferredRoamingList byte array containing the new PRL |
| 5162 | * @return true on success; false on any failure |
| 5163 | */ |
| 5164 | @Override |
| 5165 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5167 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
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("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5172 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5173 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5174 | return success; |
| 5175 | } finally { |
| 5176 | Binder.restoreCallingIdentity(identity); |
| 5177 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5181 | * 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] | 5182 | * Used for device configuration by some CDMA operators. |
| 5183 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5184 | * @param slotIndex - device slot. |
| 5185 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5186 | * @return true on success; false on any failure |
| 5187 | */ |
| 5188 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5189 | public boolean resetModemConfig(int slotIndex) { |
| 5190 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5191 | if (phone != null) { |
| 5192 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5193 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5194 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5195 | final long identity = Binder.clearCallingIdentity(); |
| 5196 | try { |
| 5197 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5198 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5199 | return success; |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
| 5202 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5204 | return false; |
| 5205 | } |
| 5206 | |
| 5207 | /** |
| 5208 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5209 | * |
| 5210 | * @param slotIndex - device slot. |
| 5211 | * |
| 5212 | * @return true on success; false on any failure |
| 5213 | */ |
| 5214 | @Override |
| 5215 | public boolean rebootModem(int slotIndex) { |
| 5216 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5217 | if (phone != null) { |
| 5218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5219 | mApp, phone.getSubId(), "rebootModem"); |
| 5220 | |
| 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
| 5223 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5224 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5225 | return success; |
| 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(identity); |
| 5228 | } |
| 5229 | } |
| 5230 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5231 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5232 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5233 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5234 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5235 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5237 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5238 | return new String[0]; |
| 5239 | } |
| 5240 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5243 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5247 | } |
| 5248 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5249 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5250 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5251 | * {@link #disableIms(int)}. |
| 5252 | * @param slotIndex device slot. |
| 5253 | */ |
| 5254 | public void resetIms(int slotIndex) { |
| 5255 | enforceModifyPermission(); |
| 5256 | |
| 5257 | final long identity = Binder.clearCallingIdentity(); |
| 5258 | try { |
| 5259 | if (mImsResolver == null) { |
| 5260 | // may happen if the does not support IMS. |
| 5261 | return; |
| 5262 | } |
| 5263 | mImsResolver.disableIms(slotIndex); |
| 5264 | mImsResolver.enableIms(slotIndex); |
| 5265 | } finally { |
| 5266 | Binder.restoreCallingIdentity(identity); |
| 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5271 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5272 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5273 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5274 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5275 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | |
| 5277 | final long identity = Binder.clearCallingIdentity(); |
| 5278 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5279 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5280 | // may happen if the device does not support IMS. |
| 5281 | return; |
| 5282 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5283 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | } finally { |
| 5285 | Binder.restoreCallingIdentity(identity); |
| 5286 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5290 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5291 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5292 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5293 | public void disableIms(int slotId) { |
| 5294 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | |
| 5296 | final long identity = Binder.clearCallingIdentity(); |
| 5297 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5298 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5299 | // may happen if the device does not support IMS. |
| 5300 | return; |
| 5301 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5302 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | } finally { |
| 5304 | Binder.restoreCallingIdentity(identity); |
| 5305 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5309 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5310 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5311 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5312 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5313 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5314 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5315 | |
| 5316 | final long identity = Binder.clearCallingIdentity(); |
| 5317 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5318 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5319 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5320 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5321 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5322 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | } finally { |
| 5324 | Binder.restoreCallingIdentity(identity); |
| 5325 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5326 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5327 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5328 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5329 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5330 | @Override |
| 5331 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5332 | enforceModifyPermission(); |
| 5333 | |
| 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
| 5336 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5337 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5338 | } finally { |
| 5339 | Binder.restoreCallingIdentity(identity); |
| 5340 | } |
| 5341 | } |
| 5342 | |
| 5343 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5344 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5345 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5346 | */ |
| 5347 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5348 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | |
| 5350 | final long identity = Binder.clearCallingIdentity(); |
| 5351 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5352 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5353 | // may happen if the device does not support IMS. |
| 5354 | return null; |
| 5355 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5356 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
| 5359 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5362 | /** |
| 5363 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5364 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5365 | */ |
| 5366 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5367 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5368 | |
| 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5371 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5372 | // may happen if the device does not support IMS. |
| 5373 | return null; |
| 5374 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5375 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | } finally { |
| 5377 | Binder.restoreCallingIdentity(identity); |
| 5378 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5379 | } |
| 5380 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5381 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5382 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5383 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5384 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5385 | * @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] | 5386 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5387 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5388 | * @param packageName The name of the package that the current configuration will be replaced |
| 5389 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5390 | * @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] | 5391 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5392 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5393 | int[] featureTypes, String packageName) { |
| 5394 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5395 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5396 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5397 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5398 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | final long identity = Binder.clearCallingIdentity(); |
| 5401 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5402 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5403 | // may happen if the device does not support IMS. |
| 5404 | return false; |
| 5405 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5406 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5407 | for (int featureType : featureTypes) { |
| 5408 | featureConfig.put(featureType, packageName); |
| 5409 | } |
| 5410 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5411 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | } finally { |
| 5413 | Binder.restoreCallingIdentity(identity); |
| 5414 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5418 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5419 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5420 | * |
| 5421 | * This should only be used for testing. |
| 5422 | * |
| 5423 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5424 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5425 | */ |
| 5426 | @Override |
| 5427 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5428 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5429 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5430 | "clearCarrierImsServiceOverride"); |
| 5431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5432 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5433 | "clearCarrierImsServiceOverride"); |
| 5434 | |
| 5435 | final long identity = Binder.clearCallingIdentity(); |
| 5436 | try { |
| 5437 | if (mImsResolver == null) { |
| 5438 | // may happen if the device does not support IMS. |
| 5439 | return false; |
| 5440 | } |
| 5441 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
| 5444 | } |
| 5445 | } |
| 5446 | |
| 5447 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5448 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5449 | * |
| 5450 | * @param slotId The slot that the ImsService is associated with. |
| 5451 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5452 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5453 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5454 | * @return the package name of the ImsService configuration. |
| 5455 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5456 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5457 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5458 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5459 | TelephonyPermissions |
| 5460 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5461 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5462 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5464 | final long identity = Binder.clearCallingIdentity(); |
| 5465 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5466 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5467 | // may happen if the device does not support IMS. |
| 5468 | return ""; |
| 5469 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5470 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5471 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5472 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5473 | } finally { |
| 5474 | Binder.restoreCallingIdentity(identity); |
| 5475 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5476 | } |
| 5477 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5478 | /** |
| 5479 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5480 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5481 | * @param callback A callback with an integer containing the |
| 5482 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5483 | */ |
| 5484 | @Override |
| 5485 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5486 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5487 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5488 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5489 | "IMS not available on device."); |
| 5490 | } |
| 5491 | final long token = Binder.clearCallingIdentity(); |
| 5492 | try { |
| 5493 | int slotId = getSlotIndex(subId); |
| 5494 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5495 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5496 | + subId + "'"); |
| 5497 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5498 | } |
| 5499 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5500 | try { |
| 5501 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5502 | } catch (RemoteException e) { |
| 5503 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5504 | + "Ignore"); |
| 5505 | } |
| 5506 | }); |
| 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(token); |
| 5509 | } |
| 5510 | } |
| 5511 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5512 | public void setImsRegistrationState(boolean registered) { |
| 5513 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | |
| 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5517 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
| 5520 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5521 | } |
| 5522 | |
| 5523 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5524 | * Set the network selection mode to automatic. |
| 5525 | * |
| 5526 | */ |
| 5527 | @Override |
| 5528 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5530 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5531 | |
| 5532 | final long identity = Binder.clearCallingIdentity(); |
| 5533 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5534 | if (!isActiveSubscription(subId)) { |
| 5535 | return; |
| 5536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5537 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5538 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
| 5541 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5544 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5545 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5546 | * |
| 5547 | * @param subId the id of the subscription. |
| 5548 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5549 | * the operator to attach to. |
| 5550 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5551 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5552 | * normal network selection next time. |
| 5553 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5554 | */ |
| 5555 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5556 | public boolean setNetworkSelectionModeManual( |
| 5557 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5559 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5560 | |
| 5561 | if (!isActiveSubscription(subId)) { |
| 5562 | return false; |
| 5563 | } |
| 5564 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | final long identity = Binder.clearCallingIdentity(); |
| 5566 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5567 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5568 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5569 | if (DBG) { |
| 5570 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5571 | + " operator: " + operatorInfo); |
| 5572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5574 | } finally { |
| 5575 | Binder.restoreCallingIdentity(identity); |
| 5576 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5577 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5578 | /** |
| 5579 | * Get the manual network selection |
| 5580 | * |
| 5581 | * @param subId the id of the subscription. |
| 5582 | * |
| 5583 | * @return the previously saved user selected PLMN |
| 5584 | */ |
| 5585 | @Override |
| 5586 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5587 | TelephonyPermissions |
| 5588 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5589 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5590 | |
| 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
| 5593 | if (!isActiveSubscription(subId)) { |
| 5594 | return ""; |
| 5595 | } |
| 5596 | |
| 5597 | final Phone phone = getPhone(subId); |
| 5598 | if (phone == null) { |
| 5599 | return ""; |
| 5600 | } |
| 5601 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5602 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5603 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5604 | } finally { |
| 5605 | Binder.restoreCallingIdentity(identity); |
| 5606 | } |
| 5607 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5608 | |
| 5609 | /** |
| 5610 | * Scans for available networks. |
| 5611 | */ |
| 5612 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5613 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5614 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5616 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5617 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5618 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5619 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5620 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5621 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5622 | .setCallingPid(Binder.getCallingPid()) |
| 5623 | .setCallingUid(Binder.getCallingUid()) |
| 5624 | .setMethod("getCellNetworkScanResults") |
| 5625 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5626 | .build()); |
| 5627 | switch (locationResult) { |
| 5628 | case DENIED_HARD: |
| 5629 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5630 | case DENIED_SOFT: |
| 5631 | return null; |
| 5632 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5634 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | try { |
| 5636 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5637 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5638 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | } finally { |
| 5640 | Binder.restoreCallingIdentity(identity); |
| 5641 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5642 | } |
| 5643 | |
| 5644 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5645 | * Get the call forwarding info, given the call forwarding reason. |
| 5646 | */ |
| 5647 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5648 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5649 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5650 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5651 | long identity = Binder.clearCallingIdentity(); |
| 5652 | try { |
| 5653 | if (DBG) { |
| 5654 | log("getCallForwarding: subId " + subId |
| 5655 | + " callForwardingReason" + callForwardingReason); |
| 5656 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5657 | |
| 5658 | Phone phone = getPhone(subId); |
| 5659 | if (phone == null) { |
| 5660 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5661 | callback.onError( |
| 5662 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5663 | } catch (RemoteException e) { |
| 5664 | // ignore |
| 5665 | } |
| 5666 | return; |
| 5667 | } |
| 5668 | |
| 5669 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5670 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5671 | @Override |
| 5672 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5673 | try { |
| 5674 | callback.onCallForwardingInfoAvailable(info); |
| 5675 | } catch (RemoteException e) { |
| 5676 | // ignore |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | @Override |
| 5681 | public void onError(int error) { |
| 5682 | try { |
| 5683 | callback.onError(error); |
| 5684 | } catch (RemoteException e) { |
| 5685 | // ignore |
| 5686 | } |
| 5687 | } |
| 5688 | }); |
| 5689 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5690 | } finally { |
| 5691 | Binder.restoreCallingIdentity(identity); |
| 5692 | } |
| 5693 | } |
| 5694 | |
| 5695 | /** |
| 5696 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5697 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5698 | */ |
| 5699 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5700 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5701 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5702 | enforceModifyPermission(); |
| 5703 | long identity = Binder.clearCallingIdentity(); |
| 5704 | try { |
| 5705 | if (DBG) { |
| 5706 | log("setCallForwarding: subId " + subId |
| 5707 | + " callForwardingInfo" + callForwardingInfo); |
| 5708 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5709 | |
| 5710 | Phone phone = getPhone(subId); |
| 5711 | if (phone == null) { |
| 5712 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5713 | callback.accept( |
| 5714 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5715 | } catch (RemoteException e) { |
| 5716 | // ignore |
| 5717 | } |
| 5718 | return; |
| 5719 | } |
| 5720 | |
| 5721 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5722 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5723 | |
| 5724 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5725 | } finally { |
| 5726 | Binder.restoreCallingIdentity(identity); |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5731 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5732 | */ |
| 5733 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5734 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5735 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5736 | long identity = Binder.clearCallingIdentity(); |
| 5737 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5738 | |
| 5739 | Phone phone = getPhone(subId); |
| 5740 | if (phone == null) { |
| 5741 | try { |
| 5742 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5743 | } catch (RemoteException e) { |
| 5744 | // ignore |
| 5745 | } |
| 5746 | return; |
| 5747 | } |
| 5748 | |
| 5749 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5750 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5751 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5752 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5753 | } finally { |
| 5754 | Binder.restoreCallingIdentity(identity); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5759 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5760 | */ |
| 5761 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5762 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5763 | enforceModifyPermission(); |
| 5764 | long identity = Binder.clearCallingIdentity(); |
| 5765 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5766 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5767 | |
| 5768 | Phone phone = getPhone(subId); |
| 5769 | if (phone == null) { |
| 5770 | try { |
| 5771 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5772 | } catch (RemoteException e) { |
| 5773 | // ignore |
| 5774 | } |
| 5775 | return; |
| 5776 | } |
| 5777 | |
| 5778 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5779 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5780 | |
| 5781 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5782 | } finally { |
| 5783 | Binder.restoreCallingIdentity(identity); |
| 5784 | } |
| 5785 | } |
| 5786 | |
| 5787 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5788 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5789 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5790 | * @param subId id of the subscription |
| 5791 | * @param request contains the radio access networks with bands/channels to scan |
| 5792 | * @param messenger callback messenger for scan results or errors |
| 5793 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5794 | * @return the id of the requested scan which can be used to stop the scan. |
| 5795 | */ |
| 5796 | @Override |
| 5797 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5798 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5800 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5801 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5802 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5803 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5804 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5805 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5806 | .setCallingPid(Binder.getCallingPid()) |
| 5807 | .setCallingUid(Binder.getCallingUid()) |
| 5808 | .setMethod("requestNetworkScan") |
| 5809 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5810 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5811 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5812 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5813 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5814 | if (e != null) { |
| 5815 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5816 | throw e; |
| 5817 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5818 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5819 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5820 | } |
| 5821 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5823 | int callingUid = Binder.getCallingUid(); |
| 5824 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5825 | final long identity = Binder.clearCallingIdentity(); |
| 5826 | try { |
| 5827 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5828 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5829 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5830 | } finally { |
| 5831 | Binder.restoreCallingIdentity(identity); |
| 5832 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5835 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5836 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5837 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5838 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5839 | boolean hasNetworkScanPermission = |
| 5840 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5841 | == PERMISSION_GRANTED; |
| 5842 | |
| 5843 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5844 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5845 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5846 | } |
| 5847 | |
| 5848 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5849 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5850 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5851 | return new SecurityException("Specific channels must not be" |
| 5852 | + " scanned without location access."); |
| 5853 | } |
| 5854 | } |
| 5855 | } |
| 5856 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5857 | return null; |
| 5858 | } |
| 5859 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5860 | /** |
| 5861 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5862 | * |
| 5863 | * @param subId id of the subscription |
| 5864 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5865 | */ |
| 5866 | @Override |
| 5867 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5868 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5869 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5871 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | final long identity = Binder.clearCallingIdentity(); |
| 5873 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5874 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | } finally { |
| 5876 | Binder.restoreCallingIdentity(identity); |
| 5877 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5878 | } |
| 5879 | |
| 5880 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5881 | * Get the calculated preferred network type. |
| 5882 | * Used for debugging incorrect network type. |
| 5883 | * |
| 5884 | * @return the preferred network type, defined in RILConstants.java. |
| 5885 | */ |
| 5886 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5887 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5888 | final Phone defaultPhone = getDefaultPhone(); |
| 5889 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5890 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5891 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5892 | } |
| 5893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5894 | final long identity = Binder.clearCallingIdentity(); |
| 5895 | try { |
| 5896 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5897 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | } finally { |
| 5899 | Binder.restoreCallingIdentity(identity); |
| 5900 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5904 | * Get the preferred network type. |
| 5905 | * Used for device configuration by some CDMA operators. |
| 5906 | * |
| 5907 | * @return the preferred network type, defined in RILConstants.java. |
| 5908 | */ |
| 5909 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5910 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5911 | TelephonyPermissions |
| 5912 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5913 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | |
| 5915 | final long identity = Binder.clearCallingIdentity(); |
| 5916 | try { |
| 5917 | if (DBG) log("getPreferredNetworkType"); |
| 5918 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5919 | int networkType = (result != null ? result[0] : -1); |
| 5920 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5921 | return networkType; |
| 5922 | } finally { |
| 5923 | Binder.restoreCallingIdentity(identity); |
| 5924 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | /** |
| 5928 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5929 | * |
| 5930 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5931 | * @return true on success; false on any failure. |
| 5932 | */ |
| 5933 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5934 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5936 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | |
| 5938 | final long identity = Binder.clearCallingIdentity(); |
| 5939 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5940 | Boolean success = (Boolean) sendRequest( |
| 5941 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5942 | |
| 5943 | if (success) { |
| 5944 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5945 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5946 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5947 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5948 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5951 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5952 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5953 | |
| 5954 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5955 | * Get the allowed network types that store in the telephony provider. |
| 5956 | * |
| 5957 | * @param subId the id of the subscription. |
| 5958 | * @return allowedNetworkTypes the allowed network types. |
| 5959 | */ |
| 5960 | @Override |
| 5961 | public long getAllowedNetworkTypes(int subId) { |
| 5962 | TelephonyPermissions |
| 5963 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5964 | mApp, subId, "getAllowedNetworkTypes"); |
| 5965 | |
| 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
| 5968 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5969 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
| 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | /** |
| 5976 | * Set the allowed network types. |
| 5977 | * |
| 5978 | * @param subId the id of the subscription. |
| 5979 | * @param allowedNetworkTypes the allowed network types. |
| 5980 | * @return true on success; false on any failure. |
| 5981 | */ |
| 5982 | @Override |
| 5983 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5985 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5986 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5987 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5988 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5989 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5990 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5991 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5992 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5993 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5994 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5998 | * Get the allowed network types for certain reason. |
| 5999 | * |
| 6000 | * @param subId the id of the subscription. |
| 6001 | * @param reason the reason the allowed network type change is taking place |
| 6002 | * @return the allowed network types. |
| 6003 | */ |
| 6004 | @Override |
| 6005 | public long getAllowedNetworkTypesForReason(int subId, |
| 6006 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6007 | TelephonyPermissions |
| 6008 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6009 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6010 | final long identity = Binder.clearCallingIdentity(); |
| 6011 | try { |
| 6012 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6013 | } finally { |
| 6014 | Binder.restoreCallingIdentity(identity); |
| 6015 | } |
| 6016 | } |
| 6017 | |
| 6018 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6019 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6020 | * @param subId subscription id of the sim card |
| 6021 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6022 | * This can be passed following states |
| 6023 | * <ol> |
| 6024 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6025 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6026 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6027 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6028 | * </ol> |
| 6029 | * @return operation result. |
| 6030 | */ |
| 6031 | @Override |
| 6032 | public int setNrDualConnectivityState(int subId, |
| 6033 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6034 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6035 | mApp, subId, "enableNRDualConnectivity"); |
| 6036 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6037 | final long identity = Binder.clearCallingIdentity(); |
| 6038 | try { |
| 6039 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6040 | nrDualConnectivityState, subId, |
| 6041 | workSource); |
| 6042 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6043 | return result; |
| 6044 | } finally { |
| 6045 | Binder.restoreCallingIdentity(identity); |
| 6046 | } |
| 6047 | } |
| 6048 | |
| 6049 | /** |
| 6050 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6051 | * @return true if dual connectivity is enabled else false |
| 6052 | */ |
| 6053 | @Override |
| 6054 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6055 | TelephonyPermissions |
| 6056 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6057 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6058 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6059 | final long identity = Binder.clearCallingIdentity(); |
| 6060 | try { |
| 6061 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6062 | null, subId, workSource); |
| 6063 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6064 | return isEnabled; |
| 6065 | } finally { |
| 6066 | Binder.restoreCallingIdentity(identity); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6071 | * get carrier bandwidth per primary and secondary carrier |
| 6072 | * @param subId subscription id of the sim card |
| 6073 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6074 | */ |
| 6075 | @Override |
| 6076 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6077 | TelephonyPermissions |
| 6078 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6079 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6080 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6081 | final long identity = Binder.clearCallingIdentity(); |
| 6082 | try { |
| 6083 | CarrierBandwidth carrierBandwidth = |
| 6084 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6085 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6086 | return carrierBandwidth; |
| 6087 | } finally { |
| 6088 | Binder.restoreCallingIdentity(identity); |
| 6089 | } |
| 6090 | } |
| 6091 | |
| 6092 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6093 | * Get the effective allowed network types on the device. |
| 6094 | * This API will return an intersection of allowed network types for all reasons, |
| 6095 | * including the configuration done through setAllowedNetworkTypes |
| 6096 | * |
| 6097 | * @param subId the id of the subscription. |
| 6098 | * @return the allowed network types |
| 6099 | */ |
| 6100 | @Override |
| 6101 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6102 | TelephonyPermissions |
| 6103 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6104 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6105 | final long identity = Binder.clearCallingIdentity(); |
| 6106 | try { |
| 6107 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6108 | } finally { |
| 6109 | Binder.restoreCallingIdentity(identity); |
| 6110 | } |
| 6111 | } |
| 6112 | |
| 6113 | /** |
| 6114 | * Set the allowed network types of the device and |
| 6115 | * provide the reason triggering the allowed network change. |
| 6116 | * |
| 6117 | * @param subId the id of the subscription. |
| 6118 | * @param reason the reason the allowed network type change is taking place |
| 6119 | * @param allowedNetworkTypes the allowed network types. |
| 6120 | * @return true on success; false on any failure. |
| 6121 | */ |
| 6122 | @Override |
| 6123 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6124 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6126 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6127 | final long identity = Binder.clearCallingIdentity(); |
| 6128 | try { |
| 6129 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6130 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6131 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6132 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6133 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6140 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6141 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6142 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6143 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6144 | * @hide |
| 6145 | */ |
| 6146 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6147 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6148 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6149 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6150 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6152 | if (phone != null) { |
| 6153 | return phone.hasMatchedTetherApnSetting(); |
| 6154 | } else { |
| 6155 | return false; |
| 6156 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | } finally { |
| 6158 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6159 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6163 | * Enable or disable always reporting signal strength changes from radio. |
| 6164 | * |
| 6165 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6166 | */ |
| 6167 | @Override |
| 6168 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6169 | enforceModifyPermission(); |
| 6170 | enforceSystemCaller(); |
| 6171 | |
| 6172 | final long identity = Binder.clearCallingIdentity(); |
| 6173 | final Phone phone = getPhone(subId); |
| 6174 | try { |
| 6175 | if (phone != null) { |
| 6176 | if (DBG) { |
| 6177 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6178 | + " isEnable=" + isEnable); |
| 6179 | } |
| 6180 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6181 | } else { |
| 6182 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6183 | + subId); |
| 6184 | } |
| 6185 | } finally { |
| 6186 | Binder.restoreCallingIdentity(identity); |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6191 | * Get the user enabled state of Mobile Data. |
| 6192 | * |
| 6193 | * TODO: remove and use isUserDataEnabled. |
| 6194 | * This can't be removed now because some vendor codes |
| 6195 | * calls through ITelephony directly while they should |
| 6196 | * use TelephonyManager. |
| 6197 | * |
| 6198 | * @return true on enabled |
| 6199 | */ |
| 6200 | @Override |
| 6201 | public boolean getDataEnabled(int subId) { |
| 6202 | return isUserDataEnabled(subId); |
| 6203 | } |
| 6204 | |
| 6205 | /** |
| 6206 | * Get whether mobile data is enabled per user setting. |
| 6207 | * |
| 6208 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6209 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6210 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6211 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6212 | * |
| 6213 | * @return {@code true} if data is enabled else {@code false} |
| 6214 | */ |
| 6215 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6216 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6217 | try { |
| 6218 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6219 | null); |
| 6220 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6222 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6224 | |
| 6225 | final long identity = Binder.clearCallingIdentity(); |
| 6226 | try { |
| 6227 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6228 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6229 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6230 | if (phone != null) { |
| 6231 | boolean retVal = phone.isUserDataEnabled(); |
| 6232 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6233 | return retVal; |
| 6234 | } else { |
| 6235 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6236 | return false; |
| 6237 | } |
| 6238 | } finally { |
| 6239 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6240 | } |
| 6241 | } |
| 6242 | |
| 6243 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6244 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6245 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6246 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6247 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6248 | * @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] | 6249 | */ |
| 6250 | @Override |
| 6251 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6252 | try { |
| 6253 | try { |
| 6254 | mApp.enforceCallingOrSelfPermission( |
| 6255 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6256 | null); |
| 6257 | } catch (Exception e) { |
| 6258 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6259 | "isDataEnabled"); |
| 6260 | } |
| 6261 | } catch (Exception e) { |
| 6262 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6263 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6264 | |
| 6265 | final long identity = Binder.clearCallingIdentity(); |
| 6266 | try { |
| 6267 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6268 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6269 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6270 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6271 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6273 | return retVal; |
| 6274 | } else { |
| 6275 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6276 | return false; |
| 6277 | } |
| 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6280 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6281 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6282 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6283 | /** |
| 6284 | * Check if data is enabled for a specific reason |
| 6285 | * @param subId Subscription index |
| 6286 | * @param reason the reason the data enable change is taking place |
| 6287 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6288 | */ |
| 6289 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6290 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6291 | @TelephonyManager.DataEnabledReason int reason) { |
| 6292 | try { |
| 6293 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6294 | null); |
| 6295 | } catch (Exception e) { |
| 6296 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6297 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | |
| 6301 | final long identity = Binder.clearCallingIdentity(); |
| 6302 | try { |
| 6303 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6304 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6305 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6306 | + " reason=" + reason); |
| 6307 | } |
| 6308 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6309 | if (phone != null) { |
| 6310 | boolean retVal; |
| 6311 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6312 | retVal = phone.isUserDataEnabled(); |
| 6313 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6314 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6315 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6316 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6317 | return retVal; |
| 6318 | } else { |
| 6319 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6320 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6321 | + subId + " retVal=false"); |
| 6322 | } |
| 6323 | return false; |
| 6324 | } |
| 6325 | } finally { |
| 6326 | Binder.restoreCallingIdentity(identity); |
| 6327 | } |
| 6328 | } |
| 6329 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6330 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6331 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6332 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6333 | // Skip the check if it's one of these special uids |
| 6334 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6335 | } |
| 6336 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6337 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6338 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6339 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6340 | || subController == null) return privilegeFromSim; |
| 6341 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6342 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6343 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6344 | |
| 6345 | final long identity = Binder.clearCallingIdentity(); |
| 6346 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6347 | int subId = phone.getSubId(); |
| 6348 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6349 | // A test override is in place for the privileges for this subId, so don't try to |
| 6350 | // read the subscription privileges. |
| 6351 | return privilegeFromSim; |
| 6352 | } |
| 6353 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6354 | SubscriptionManager subManager = (SubscriptionManager) |
| 6355 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6356 | for (String pkg : packages) { |
| 6357 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6358 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6359 | } |
| 6360 | } |
| 6361 | return privilegeFromSim; |
| 6362 | } finally { |
| 6363 | Binder.restoreCallingIdentity(identity); |
| 6364 | } |
| 6365 | } |
| 6366 | |
| 6367 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6368 | String pkgName) { |
| 6369 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6370 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6371 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6372 | || subController == null) return privilegeFromSim; |
| 6373 | |
| 6374 | final long identity = Binder.clearCallingIdentity(); |
| 6375 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6376 | int subId = phone.getSubId(); |
| 6377 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6378 | // A test override is in place for the privileges for this subId, so don't try to |
| 6379 | // read the subscription privileges. |
| 6380 | return privilegeFromSim; |
| 6381 | } |
| 6382 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6383 | SubscriptionManager subManager = (SubscriptionManager) |
| 6384 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6385 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6386 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6387 | } finally { |
| 6388 | Binder.restoreCallingIdentity(identity); |
| 6389 | } |
| 6390 | } |
| 6391 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6392 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6393 | public int getCarrierPrivilegeStatus(int subId) { |
| 6394 | final Phone phone = getPhone(subId); |
| 6395 | if (phone == null) { |
| 6396 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6397 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6398 | } |
| 6399 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6400 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6401 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6402 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6403 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6404 | |
| 6405 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6406 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6407 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6408 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6409 | |
| 6410 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6411 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6412 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6413 | final Phone phone = getPhone(subId); |
| 6414 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6415 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6416 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6417 | } |
| 6418 | UiccProfile profile = |
| 6419 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6420 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6421 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6422 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6423 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6424 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6425 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6426 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6427 | } |
| 6428 | |
| 6429 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6430 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6431 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6432 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6433 | } |
| 6434 | |
| 6435 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6436 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6437 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6438 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6439 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6440 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6441 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6442 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6443 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6444 | } |
| 6445 | |
| 6446 | @Override |
| 6447 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6448 | if (TextUtils.isEmpty(pkgName)) |
| 6449 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6450 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6451 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6452 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6453 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6454 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6455 | continue; |
| 6456 | } |
| 6457 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6458 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6459 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6460 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6461 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6462 | break; |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6467 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6468 | |
| 6469 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6470 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6471 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6472 | loge("phoneId " + phoneId + " is not valid."); |
| 6473 | return null; |
| 6474 | } |
| 6475 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6476 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6477 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6478 | return null ; |
| 6479 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6480 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6481 | } |
| 6482 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6483 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6484 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6485 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6486 | List<String> privilegedPackages = new ArrayList<>(); |
| 6487 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6488 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6489 | // has UICC in that slot. |
| 6490 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6491 | if (card.hasCarrierPrivilegeRules()) { |
| 6492 | if (packages == null) { |
| 6493 | // Only check packages in user 0 for now |
| 6494 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6495 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6496 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6497 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6498 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6499 | } |
| 6500 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6501 | PackageInfo pkgInfo = packages.get(p); |
| 6502 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6503 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6504 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6505 | privilegedPackages.add(pkgInfo.packageName); |
| 6506 | } |
| 6507 | } |
| 6508 | } |
| 6509 | } |
| 6510 | return privilegedPackages; |
| 6511 | } |
| 6512 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6513 | @Override |
| 6514 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6515 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6516 | |
| 6517 | final long identity = Binder.clearCallingIdentity(); |
| 6518 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6519 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6520 | try { |
| 6521 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6522 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6523 | } |
| 6524 | } finally { |
| 6525 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6526 | } |
| 6527 | return privilegedPackages; |
| 6528 | } |
| 6529 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6530 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6531 | final Phone phone = getPhone(subId); |
| 6532 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6533 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6534 | return null; |
| 6535 | } |
| 6536 | String iccId = card.getIccId(); |
| 6537 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6538 | return null; |
| 6539 | } |
| 6540 | return iccId; |
| 6541 | } |
| 6542 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6543 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6544 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6545 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6546 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6547 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | final String iccId = getIccId(subId); |
| 6552 | final Phone phone = getPhone(subId); |
| 6553 | if (phone == null) { |
| 6554 | return false; |
| 6555 | } |
| 6556 | final String subscriberId = phone.getSubscriberId(); |
| 6557 | |
| 6558 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6559 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | + subscriberId + " to " + number); |
| 6561 | } |
| 6562 | |
| 6563 | if (TextUtils.isEmpty(iccId)) { |
| 6564 | return false; |
| 6565 | } |
| 6566 | |
| 6567 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6568 | |
| 6569 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6570 | if (alphaTag == null) { |
| 6571 | editor.remove(alphaTagPrefKey); |
| 6572 | } else { |
| 6573 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6574 | } |
| 6575 | |
| 6576 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6577 | // track all merged IMSIs based on line number |
| 6578 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6579 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6580 | if (number == null) { |
| 6581 | editor.remove(numberPrefKey); |
| 6582 | editor.remove(subscriberPrefKey); |
| 6583 | } else { |
| 6584 | editor.putString(numberPrefKey, number); |
| 6585 | editor.putString(subscriberPrefKey, subscriberId); |
| 6586 | } |
| 6587 | |
| 6588 | editor.commit(); |
| 6589 | return true; |
| 6590 | } finally { |
| 6591 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6592 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6596 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6597 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6598 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6600 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6601 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6602 | return null; |
| 6603 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6604 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | final long identity = Binder.clearCallingIdentity(); |
| 6606 | try { |
| 6607 | String iccId = getIccId(subId); |
| 6608 | if (iccId != null) { |
| 6609 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6610 | if (DBG_MERGE) { |
| 6611 | log("getLine1NumberForDisplay returning " |
| 6612 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6613 | } |
| 6614 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6617 | return null; |
| 6618 | } finally { |
| 6619 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6620 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6624 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6625 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6626 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6627 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6628 | return null; |
| 6629 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6630 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6631 | final long identity = Binder.clearCallingIdentity(); |
| 6632 | try { |
| 6633 | String iccId = getIccId(subId); |
| 6634 | if (iccId != null) { |
| 6635 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6636 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6637 | } |
| 6638 | return null; |
| 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6641 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6642 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6643 | |
| 6644 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6645 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6646 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6647 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6648 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6650 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6651 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6652 | return null; |
| 6653 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6654 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6655 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6656 | // the process, where TelephonyManager was instantiated. |
| 6657 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6660 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6661 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6662 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6663 | |
| 6664 | // Figure out what subscribers are currently active |
| 6665 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6666 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6667 | // Only consider subs which match the current subId |
| 6668 | // This logic can be simplified. See b/131189269 for progress. |
| 6669 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6670 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6672 | |
| 6673 | // First pass, find a number override for an active subscriber |
| 6674 | String mergeNumber = null; |
| 6675 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6676 | for (String key : prefs.keySet()) { |
| 6677 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6678 | final String subscriberId = (String) prefs.get(key); |
| 6679 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6680 | final String iccId = key.substring( |
| 6681 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6682 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6683 | mergeNumber = (String) prefs.get(numberKey); |
| 6684 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6685 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | + " for active subscriber " + subscriberId); |
| 6687 | } |
| 6688 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6689 | break; |
| 6690 | } |
| 6691 | } |
| 6692 | } |
| 6693 | } |
| 6694 | |
| 6695 | // Shortcut when no active merged subscribers |
| 6696 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6697 | return null; |
| 6698 | } |
| 6699 | |
| 6700 | // Second pass, find all subscribers under that line override |
| 6701 | final ArraySet<String> result = new ArraySet<>(); |
| 6702 | for (String key : prefs.keySet()) { |
| 6703 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6704 | final String number = (String) prefs.get(key); |
| 6705 | if (mergeNumber.equals(number)) { |
| 6706 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6707 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6708 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6709 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6710 | result.add(subscriberId); |
| 6711 | } |
| 6712 | } |
| 6713 | } |
| 6714 | } |
| 6715 | |
| 6716 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6717 | Arrays.sort(resultArray); |
| 6718 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6719 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6721 | } |
| 6722 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6725 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6726 | } |
| 6727 | |
| 6728 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6729 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6730 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6731 | |
| 6732 | final long identity = Binder.clearCallingIdentity(); |
| 6733 | try { |
| 6734 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6735 | TelephonyManager.class); |
| 6736 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6737 | if (subscriberId == null) { |
| 6738 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6739 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6740 | + subId); |
| 6741 | } |
| 6742 | return null; |
| 6743 | } |
| 6744 | |
| 6745 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6746 | .getSubscriptionInfo(subId); |
| 6747 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6748 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6749 | if (groupUuid == null) { |
| 6750 | return new String[]{subscriberId}; |
| 6751 | } |
| 6752 | |
| 6753 | // Get all subscriberIds from the group. |
| 6754 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6755 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6756 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6757 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6758 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6759 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6760 | if (subscriberId != null) { |
| 6761 | mergedSubscriberIds.add(subscriberId); |
| 6762 | } |
| 6763 | } |
| 6764 | |
| 6765 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6766 | } finally { |
| 6767 | Binder.restoreCallingIdentity(identity); |
| 6768 | |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6773 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6774 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6775 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | |
| 6777 | final long identity = Binder.clearCallingIdentity(); |
| 6778 | try { |
| 6779 | final Phone phone = getPhone(subId); |
| 6780 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6781 | } finally { |
| 6782 | Binder.restoreCallingIdentity(identity); |
| 6783 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6784 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6785 | |
| 6786 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6787 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6788 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6789 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6790 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6791 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | |
| 6793 | final long identity = Binder.clearCallingIdentity(); |
| 6794 | try { |
| 6795 | final Phone phone = getPhone(subId); |
| 6796 | if (phone == null) { |
| 6797 | return false; |
| 6798 | } |
| 6799 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6800 | cdmaNonRoamingList); |
| 6801 | } finally { |
| 6802 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6803 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6804 | } |
| 6805 | |
| 6806 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6807 | @Deprecated |
| 6808 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6809 | enforceModifyPermission(); |
| 6810 | |
| 6811 | int returnValue = 0; |
| 6812 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6813 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6814 | if(result.exception == null) { |
| 6815 | if (result.result != null) { |
| 6816 | byte[] responseData = (byte[])(result.result); |
| 6817 | if(responseData.length > oemResp.length) { |
| 6818 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6819 | responseData.length + "bytes. Buffer Size is " + |
| 6820 | oemResp.length + "bytes."); |
| 6821 | } |
| 6822 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6823 | returnValue = responseData.length; |
| 6824 | } |
| 6825 | } else { |
| 6826 | CommandException ex = (CommandException) result.exception; |
| 6827 | returnValue = ex.getCommandError().ordinal(); |
| 6828 | if(returnValue > 0) returnValue *= -1; |
| 6829 | } |
| 6830 | } catch (RuntimeException e) { |
| 6831 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6832 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6833 | if(returnValue > 0) returnValue *= -1; |
| 6834 | } |
| 6835 | |
| 6836 | return returnValue; |
| 6837 | } |
| 6838 | |
| 6839 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6840 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6841 | try { |
| 6842 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6843 | } catch (RuntimeException e) { |
| 6844 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6845 | } |
| 6846 | } |
| 6847 | |
| 6848 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6849 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6850 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6851 | try { |
| 6852 | TelephonyPermissions |
| 6853 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6854 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6855 | } catch (SecurityException e) { |
| 6856 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6857 | throw e; |
| 6858 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6859 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6860 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6861 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6862 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | final long identity = Binder.clearCallingIdentity(); |
| 6864 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6865 | TelephonyPermissions |
| 6866 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6867 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6868 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6869 | } finally { |
| 6870 | Binder.restoreCallingIdentity(identity); |
| 6871 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6872 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6873 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6874 | |
| 6875 | @Override |
| 6876 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6877 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6878 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6879 | |
| 6880 | final long identity = Binder.clearCallingIdentity(); |
| 6881 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6882 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6883 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6884 | } finally { |
| 6885 | Binder.restoreCallingIdentity(identity); |
| 6886 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6887 | } |
| 6888 | |
| 6889 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6890 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6891 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6893 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6894 | return false; |
| 6895 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6897 | final long identity = Binder.clearCallingIdentity(); |
| 6898 | try { |
| 6899 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6900 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6901 | // In the long run, we may instead need to check if there exists a connection service |
| 6902 | // which can support video calling. |
| 6903 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6904 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6905 | return imsManager.isVtEnabledByPlatform() |
| 6906 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6907 | && imsManager.isVtEnabledByUser(); |
| 6908 | } finally { |
| 6909 | Binder.restoreCallingIdentity(identity); |
| 6910 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6911 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6912 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6913 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6914 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6915 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6917 | mApp, subId, callingPackage, callingFeatureId, |
| 6918 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | return false; |
| 6920 | } |
| 6921 | |
| 6922 | final long identity = Binder.clearCallingIdentity(); |
| 6923 | try { |
| 6924 | CarrierConfigManager configManager = |
| 6925 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6926 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6928 | } finally { |
| 6929 | Binder.restoreCallingIdentity(identity); |
| 6930 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6931 | } |
| 6932 | |
| 6933 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6934 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6936 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 | return false; |
| 6938 | } |
| 6939 | |
| 6940 | final long identity = Binder.clearCallingIdentity(); |
| 6941 | try { |
| 6942 | CarrierConfigManager configManager = |
| 6943 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6944 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6945 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6946 | } finally { |
| 6947 | Binder.restoreCallingIdentity(identity); |
| 6948 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6949 | } |
| 6950 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6951 | @Override |
| 6952 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6953 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6954 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | @Override |
| 6958 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6959 | final long identity = Binder.clearCallingIdentity(); |
| 6960 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6961 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
| 6964 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6967 | /** |
| 6968 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6969 | * support for the feature and device firmware support. |
| 6970 | * |
| 6971 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6972 | */ |
| 6973 | @Override |
| 6974 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6975 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6976 | final Phone phone = getPhone(subscriptionId); |
| 6977 | if (phone == null) { |
| 6978 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6979 | return false; |
| 6980 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6981 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6982 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6983 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6984 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6985 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6986 | return isCarrierSupported && isDeviceSupported; |
| 6987 | } finally { |
| 6988 | Binder.restoreCallingIdentity(identity); |
| 6989 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6990 | } |
| 6991 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6992 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6993 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6994 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6995 | * 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] | 6996 | */ |
| 6997 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | final long identity = Binder.clearCallingIdentity(); |
| 6999 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7000 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7001 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7002 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7003 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7004 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7005 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7006 | } finally { |
| 7007 | Binder.restoreCallingIdentity(identity); |
| 7008 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7009 | } |
| 7010 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7011 | @Deprecated |
| 7012 | @Override |
| 7013 | public String getDeviceId(String callingPackage) { |
| 7014 | return getDeviceIdWithFeature(callingPackage, null); |
| 7015 | } |
| 7016 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7017 | /** |
| 7018 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7019 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7020 | * |
| 7021 | * <p>Requires Permission: |
| 7022 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7023 | */ |
| 7024 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7025 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7026 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7027 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7028 | return null; |
| 7029 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7030 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7031 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7032 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7033 | return null; |
| 7034 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | |
| 7036 | final long identity = Binder.clearCallingIdentity(); |
| 7037 | try { |
| 7038 | return phone.getDeviceId(); |
| 7039 | } finally { |
| 7040 | Binder.restoreCallingIdentity(identity); |
| 7041 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7042 | } |
| 7043 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7044 | /** |
| 7045 | * {@hide} |
| 7046 | * Returns the IMS Registration Status on a particular subid |
| 7047 | * |
| 7048 | * @param subId |
| 7049 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7050 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7051 | Phone phone = getPhone(subId); |
| 7052 | if (phone != null) { |
| 7053 | return phone.isImsRegistered(); |
| 7054 | } else { |
| 7055 | return false; |
| 7056 | } |
| 7057 | } |
| 7058 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7059 | @Override |
| 7060 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | final long identity = Binder.clearCallingIdentity(); |
| 7062 | try { |
| 7063 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7064 | } finally { |
| 7065 | Binder.restoreCallingIdentity(identity); |
| 7066 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7067 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7068 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7069 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7070 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7071 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7073 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7074 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7075 | } |
| 7076 | final long identity = Binder.clearCallingIdentity(); |
| 7077 | try { |
| 7078 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7079 | } finally { |
| 7080 | Binder.restoreCallingIdentity(identity); |
| 7081 | } |
| 7082 | } |
| 7083 | |
| 7084 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7085 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7086 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7087 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7088 | final long identity = Binder.clearCallingIdentity(); |
| 7089 | try { |
| 7090 | Phone phone = getPhone(subscriptionId); |
| 7091 | if (phone == null) { |
| 7092 | return null; |
| 7093 | } |
| 7094 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7095 | } finally { |
| 7096 | Binder.restoreCallingIdentity(identity); |
| 7097 | } |
| 7098 | } |
| 7099 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7100 | /** |
| 7101 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7102 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7103 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7104 | final long identity = Binder.clearCallingIdentity(); |
| 7105 | try { |
| 7106 | Phone phone = getPhone(subId); |
| 7107 | if (phone != null) { |
| 7108 | return phone.isWifiCallingEnabled(); |
| 7109 | } else { |
| 7110 | return false; |
| 7111 | } |
| 7112 | } finally { |
| 7113 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7114 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7115 | } |
| 7116 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7117 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7118 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7119 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7120 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7121 | final long identity = Binder.clearCallingIdentity(); |
| 7122 | try { |
| 7123 | Phone phone = getPhone(subId); |
| 7124 | if (phone != null) { |
| 7125 | return phone.isVideoEnabled(); |
| 7126 | } else { |
| 7127 | return false; |
| 7128 | } |
| 7129 | } finally { |
| 7130 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7131 | } |
| 7132 | } |
| 7133 | |
| 7134 | /** |
| 7135 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7136 | * defined in {@link ImsRegistrationImplBase}. |
| 7137 | */ |
| 7138 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7139 | final long identity = Binder.clearCallingIdentity(); |
| 7140 | try { |
| 7141 | Phone phone = getPhone(subId); |
| 7142 | if (phone != null) { |
| 7143 | return phone.getImsRegistrationTech(); |
| 7144 | } else { |
| 7145 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7146 | } |
| 7147 | } finally { |
| 7148 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7149 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7152 | @Override |
| 7153 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7154 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7155 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7156 | return; |
| 7157 | } |
| 7158 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7159 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7160 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7161 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7162 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7163 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7164 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7165 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7166 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7167 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7168 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7169 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7170 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7171 | // There has been issues when Sms raw table somehow stores orphan |
| 7172 | // fragments. They lead to garbled message when new fragments come |
| 7173 | // in and combined with those stale ones. In case this happens again, |
| 7174 | // user can reset all network settings which will clean up this table. |
| 7175 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7176 | // Clean up IMS settings as well here. |
| 7177 | int slotId = getSlotIndex(subId); |
| 7178 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7179 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7180 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7181 | |
| 7182 | // Erase modem config if erase modem on network setting is enabled. |
| 7183 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7184 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7185 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7186 | sendEraseModemConfig(getDefaultPhone()); |
| 7187 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7190 | } |
| 7191 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7192 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7193 | private void cleanUpSmsRawTable(Context context) { |
| 7194 | ContentResolver resolver = context.getContentResolver(); |
| 7195 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7196 | resolver.delete(uri, null, null); |
| 7197 | } |
| 7198 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7199 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7200 | public String getSimLocaleForSubscriber(int subId) { |
| 7201 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7202 | final Phone phone = getPhone(subId); |
| 7203 | if (phone == null) { |
| 7204 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7205 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7206 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7207 | final long identity = Binder.clearCallingIdentity(); |
| 7208 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7209 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7210 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7211 | if (info == null) { |
| 7212 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7213 | return null; |
| 7214 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7215 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7216 | // preferences (EF-PL and EF-LI)... |
| 7217 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7219 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7220 | if (localeFromDefaultSim != null) { |
| 7221 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7222 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7223 | + localeFromDefaultSim); |
| 7224 | return localeFromDefaultSim.toLanguageTag(); |
| 7225 | } else { |
| 7226 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | } |
| 7228 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7230 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7231 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7232 | // the SIM and carrier preferences does not include a country we add the country |
| 7233 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7234 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7236 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7237 | return mccLocale.toLanguageTag(); |
| 7238 | } |
| 7239 | |
| 7240 | if (DBG) log("No locale found - returning null"); |
| 7241 | return null; |
| 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
| 7244 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7248 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7249 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7250 | } |
| 7251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7252 | /** |
| 7253 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7254 | */ |
| 7255 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7256 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7257 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7258 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7259 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7260 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7261 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7262 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7263 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7264 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7265 | * representing the state of the modem. |
| 7266 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7267 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7268 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7269 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7270 | */ |
| 7271 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7272 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7273 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7274 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7275 | |
| 7276 | final long identity = Binder.clearCallingIdentity(); |
| 7277 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7278 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | } finally { |
| 7280 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7281 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7282 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7283 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7284 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7285 | // less than total activity duration. |
| 7286 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7287 | if (info == null) { |
| 7288 | return false; |
| 7289 | } |
| 7290 | int activityDurationMs = |
| 7291 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7292 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7293 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7294 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7295 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7296 | } |
| 7297 | return (info.isValid() |
| 7298 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7299 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7300 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7301 | && (totalTxTimeMs <= activityDurationMs)); |
| 7302 | } |
| 7303 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7304 | /** |
| 7305 | * {@hide} |
| 7306 | * Returns the service state information on specified subscription. |
| 7307 | */ |
| 7308 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7309 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7310 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7311 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7312 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7313 | return null; |
| 7314 | } |
| 7315 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7316 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7317 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7318 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7319 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7320 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7321 | .setCallingPid(Binder.getCallingPid()) |
| 7322 | .setCallingUid(Binder.getCallingUid()) |
| 7323 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7324 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7325 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7326 | .build()); |
| 7327 | |
| 7328 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7329 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7330 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7331 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7332 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7333 | .setCallingPid(Binder.getCallingPid()) |
| 7334 | .setCallingUid(Binder.getCallingUid()) |
| 7335 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7336 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7337 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7338 | .build()); |
| 7339 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7340 | boolean hasFinePermission = |
| 7341 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7342 | boolean hasCoarsePermission = |
| 7343 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7347 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7348 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7349 | Rlog.d(LOG_TAG, |
| 7350 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7351 | return null; |
| 7352 | } |
| 7353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7354 | final Phone phone = getPhone(subId); |
| 7355 | if (phone == null) { |
| 7356 | return null; |
| 7357 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7358 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7359 | ServiceState ss = phone.getServiceState(); |
| 7360 | |
| 7361 | // Scrub out the location info in ServiceState depending on what level of access |
| 7362 | // the caller has. |
| 7363 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7364 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7365 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | } finally { |
| 7367 | Binder.restoreCallingIdentity(identity); |
| 7368 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7369 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7370 | |
| 7371 | /** |
| 7372 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7373 | * |
| 7374 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7375 | * voicemail ringtone. |
| 7376 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7377 | * PhoneAccount. |
| 7378 | */ |
| 7379 | @Override |
| 7380 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | final long identity = Binder.clearCallingIdentity(); |
| 7382 | try { |
| 7383 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7384 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7385 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7386 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7387 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7389 | } finally { |
| 7390 | Binder.restoreCallingIdentity(identity); |
| 7391 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7392 | } |
| 7393 | |
| 7394 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7395 | * Sets the per-account voicemail ringtone. |
| 7396 | * |
| 7397 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7398 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7399 | * |
| 7400 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7401 | * voicemail ringtone. |
| 7402 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7403 | * PhoneAccount. |
| 7404 | */ |
| 7405 | @Override |
| 7406 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7407 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7408 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7409 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7410 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7411 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7413 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7414 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | |
| 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7420 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7421 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7422 | } |
| 7423 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7424 | } finally { |
| 7425 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7426 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7430 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7431 | * |
| 7432 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7433 | * voicemail vibration setting. |
| 7434 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7435 | */ |
| 7436 | @Override |
| 7437 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | final long identity = Binder.clearCallingIdentity(); |
| 7439 | try { |
| 7440 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7441 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7442 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7446 | } finally { |
| 7447 | Binder.restoreCallingIdentity(identity); |
| 7448 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7451 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7452 | * Sets the per-account voicemail vibration. |
| 7453 | * |
| 7454 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7455 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7456 | * |
| 7457 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7458 | * voicemail vibration setting. |
| 7459 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7460 | * specific PhoneAccount. |
| 7461 | */ |
| 7462 | @Override |
| 7463 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7464 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7465 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7466 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7467 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7468 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7469 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7470 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7471 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7472 | } |
| 7473 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
| 7476 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7477 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7478 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | } |
| 7480 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7481 | } finally { |
| 7482 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7483 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7487 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7488 | * |
| 7489 | * @throws SecurityException if the caller does not have the required permission |
| 7490 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7491 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7492 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7493 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7497 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7498 | * permission. |
| 7499 | * |
| 7500 | * @throws SecurityException if the caller does not have the required permission |
| 7501 | */ |
| 7502 | private void enforceSendSmsPermission() { |
| 7503 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7504 | } |
| 7505 | |
| 7506 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7507 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7508 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7509 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7510 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7511 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | final long identity = Binder.clearCallingIdentity(); |
| 7513 | try { |
| 7514 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7515 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | if (componentName == null) { |
| 7517 | throw new SecurityException( |
| 7518 | "Caller not current active visual voicemail package[null]"); |
| 7519 | } |
| 7520 | String vvmPackage = componentName.getPackageName(); |
| 7521 | if (!callingPackage.equals(vvmPackage)) { |
| 7522 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7523 | + vvmPackage + "]"); |
| 7524 | } |
| 7525 | } finally { |
| 7526 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7527 | } |
| 7528 | } |
| 7529 | |
| 7530 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7531 | * Return the application ID for the app type. |
| 7532 | * |
| 7533 | * @param subId the subscription ID that this request applies to. |
| 7534 | * @param appType the uicc app type. |
| 7535 | * @return Application ID for specificied app type, or null if no uicc. |
| 7536 | */ |
| 7537 | @Override |
| 7538 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7539 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7540 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | |
| 7542 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7543 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | if (phone == null) { |
| 7545 | return null; |
| 7546 | } |
| 7547 | String aid = null; |
| 7548 | try { |
| 7549 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7550 | .getApplicationByType(appType).getAid(); |
| 7551 | } catch (Exception e) { |
| 7552 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7553 | } |
| 7554 | return aid; |
| 7555 | } finally { |
| 7556 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7557 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7558 | } |
| 7559 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7560 | /** |
| 7561 | * Return the Electronic Serial Number. |
| 7562 | * |
| 7563 | * @param subId the subscription ID that this request applies to. |
| 7564 | * @return ESN or null if error. |
| 7565 | */ |
| 7566 | @Override |
| 7567 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7568 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7569 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7570 | |
| 7571 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7572 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | if (phone == null) { |
| 7574 | return null; |
| 7575 | } |
| 7576 | String esn = null; |
| 7577 | try { |
| 7578 | esn = phone.getEsn(); |
| 7579 | } catch (Exception e) { |
| 7580 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7581 | } |
| 7582 | return esn; |
| 7583 | } finally { |
| 7584 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7585 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7586 | } |
| 7587 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7588 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7589 | * Return the Preferred Roaming List Version. |
| 7590 | * |
| 7591 | * @param subId the subscription ID that this request applies to. |
| 7592 | * @return PRLVersion or null if error. |
| 7593 | */ |
| 7594 | @Override |
| 7595 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7596 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7597 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7598 | |
| 7599 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7600 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | if (phone == null) { |
| 7602 | return null; |
| 7603 | } |
| 7604 | String cdmaPrlVersion = null; |
| 7605 | try { |
| 7606 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7607 | } catch (Exception e) { |
| 7608 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7609 | } |
| 7610 | return cdmaPrlVersion; |
| 7611 | } finally { |
| 7612 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7613 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7614 | } |
| 7615 | |
| 7616 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7617 | * Get snapshot of Telephony histograms |
| 7618 | * @return List of Telephony histograms |
| 7619 | * @hide |
| 7620 | */ |
| 7621 | @Override |
| 7622 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7624 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | |
| 7626 | final long identity = Binder.clearCallingIdentity(); |
| 7627 | try { |
| 7628 | return RIL.getTelephonyRILTimingHistograms(); |
| 7629 | } finally { |
| 7630 | Binder.restoreCallingIdentity(identity); |
| 7631 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7632 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7633 | |
| 7634 | /** |
| 7635 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7636 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7637 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7638 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7639 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7640 | * @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] | 7641 | */ |
| 7642 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7643 | @TelephonyManager.SetCarrierRestrictionResult |
| 7644 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7645 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7646 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7647 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7648 | if (carrierRestrictionRules == null) { |
| 7649 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7650 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7651 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7652 | final long identity = Binder.clearCallingIdentity(); |
| 7653 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7654 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7655 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 | } finally { |
| 7657 | Binder.restoreCallingIdentity(identity); |
| 7658 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7659 | } |
| 7660 | |
| 7661 | /** |
| 7662 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7663 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7664 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7665 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7666 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7667 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7668 | */ |
| 7669 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7670 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7671 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7672 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7673 | |
| 7674 | final long identity = Binder.clearCallingIdentity(); |
| 7675 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7676 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7677 | if (response instanceof CarrierRestrictionRules) { |
| 7678 | return (CarrierRestrictionRules) response; |
| 7679 | } |
| 7680 | // Response is an Exception of some kind, |
| 7681 | // which is signalled to the user as a NULL retval |
| 7682 | return null; |
| 7683 | } catch (Exception e) { |
| 7684 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7685 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | } finally { |
| 7687 | Binder.restoreCallingIdentity(identity); |
| 7688 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7689 | } |
| 7690 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7691 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7692 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7693 | * @param subId the subscription ID that this action applies to. |
| 7694 | * @param enabled control enable or disable radio. |
| 7695 | * {@hide} |
| 7696 | */ |
| 7697 | @Override |
| 7698 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7699 | enforceModifyPermission(); |
| 7700 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7701 | |
| 7702 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7703 | if (phone == null) { |
| 7704 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7705 | return; |
| 7706 | } |
| 7707 | try { |
| 7708 | phone.carrierActionSetRadioEnabled(enabled); |
| 7709 | } catch (Exception e) { |
| 7710 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | } finally { |
| 7712 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7713 | } |
| 7714 | } |
| 7715 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7716 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7717 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7718 | * network status based on which carrier apps could apply actions accordingly, |
| 7719 | * enable/disable default url handler for example. |
| 7720 | * |
| 7721 | * @param subId the subscription ID that this action applies to. |
| 7722 | * @param report control start/stop reporting the default network status. |
| 7723 | * {@hide} |
| 7724 | */ |
| 7725 | @Override |
| 7726 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7727 | enforceModifyPermission(); |
| 7728 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7729 | |
| 7730 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7731 | if (phone == null) { |
| 7732 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7733 | return; |
| 7734 | } |
| 7735 | try { |
| 7736 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7737 | } catch (Exception e) { |
| 7738 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | } finally { |
| 7740 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7741 | } |
| 7742 | } |
| 7743 | |
| 7744 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7745 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7746 | * @param subId the subscription ID that this action applies to. |
| 7747 | * {@hide} |
| 7748 | */ |
| 7749 | @Override |
| 7750 | public void carrierActionResetAll(int subId) { |
| 7751 | enforceModifyPermission(); |
| 7752 | final Phone phone = getPhone(subId); |
| 7753 | if (phone == null) { |
| 7754 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7755 | return; |
| 7756 | } |
| 7757 | try { |
| 7758 | phone.carrierActionResetAll(); |
| 7759 | } catch (Exception e) { |
| 7760 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7761 | } |
| 7762 | } |
| 7763 | |
| 7764 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7765 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7766 | * bug report is being generated. |
| 7767 | */ |
| 7768 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7769 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7770 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7771 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7772 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7773 | + Binder.getCallingPid() |
| 7774 | + ", uid=" + Binder.getCallingUid() |
| 7775 | + "without permission " |
| 7776 | + android.Manifest.permission.DUMP); |
| 7777 | return; |
| 7778 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7779 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7780 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7781 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7782 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7783 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7784 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7785 | @NonNull String[] args) { |
| 7786 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7787 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7788 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7791 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7792 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7793 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7794 | * @param reason the reason the data enable change is taking place |
| 7795 | * @param enabled True if enabling the data, otherwise disabling. |
| 7796 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7797 | */ |
| 7798 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7799 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7800 | boolean enabled) { |
| 7801 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7802 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7803 | try { |
| 7804 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7805 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7806 | } catch (SecurityException se) { |
| 7807 | enforceModifyPermission(); |
| 7808 | } |
| 7809 | } else { |
| 7810 | enforceModifyPermission(); |
| 7811 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | |
| 7813 | final long identity = Binder.clearCallingIdentity(); |
| 7814 | try { |
| 7815 | Phone phone = getPhone(subId); |
| 7816 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7817 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7818 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7819 | } else { |
| 7820 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7821 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | } |
| 7823 | } finally { |
| 7824 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7825 | } |
| 7826 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7827 | |
| 7828 | /** |
| 7829 | * Get Client request stats |
| 7830 | * @return List of Client Request Stats |
| 7831 | * @hide |
| 7832 | */ |
| 7833 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7834 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7835 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7836 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7837 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7838 | return null; |
| 7839 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7840 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7841 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7842 | final long identity = Binder.clearCallingIdentity(); |
| 7843 | try { |
| 7844 | if (phone != null) { |
| 7845 | return phone.getClientRequestStats(); |
| 7846 | } |
| 7847 | |
| 7848 | return null; |
| 7849 | } finally { |
| 7850 | Binder.restoreCallingIdentity(identity); |
| 7851 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7852 | } |
| 7853 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7854 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7855 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7856 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7857 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7858 | |
| 7859 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7860 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7861 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7862 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7863 | * @param state State of SIM (power down, power up, pass through) |
| 7864 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7865 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7866 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7867 | * |
| 7868 | **/ |
| 7869 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7870 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7871 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7872 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7873 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7874 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7875 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | final long identity = Binder.clearCallingIdentity(); |
| 7877 | try { |
| 7878 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7879 | phone.setSimPowerState(state, null, workSource); |
| 7880 | } |
| 7881 | } finally { |
| 7882 | Binder.restoreCallingIdentity(identity); |
| 7883 | } |
| 7884 | } |
| 7885 | |
| 7886 | /** |
| 7887 | * Set SIM card power state. |
| 7888 | * |
| 7889 | * @param slotIndex SIM slot id. |
| 7890 | * @param state State of SIM (power down, power up, pass through) |
| 7891 | * @param callback callback to trigger after success or failure |
| 7892 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7893 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7894 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7895 | * |
| 7896 | **/ |
| 7897 | @Override |
| 7898 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7899 | IIntegerConsumer callback) { |
| 7900 | enforceModifyPermission(); |
| 7901 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7902 | |
| 7903 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7904 | |
| 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
| 7907 | if (phone != null) { |
| 7908 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7909 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | } |
| 7911 | } finally { |
| 7912 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7913 | } |
| 7914 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7915 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7916 | private boolean isUssdApiAllowed(int subId) { |
| 7917 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7918 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7919 | if (configManager == null) { |
| 7920 | return false; |
| 7921 | } |
| 7922 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7923 | if (pb == null) { |
| 7924 | return false; |
| 7925 | } |
| 7926 | return pb.getBoolean( |
| 7927 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7928 | } |
| 7929 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7930 | /** |
| 7931 | * Check if phone is in emergency callback mode |
| 7932 | * @return true if phone is in emergency callback mode |
| 7933 | * @param subId sub id |
| 7934 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7935 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7936 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7937 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7938 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7939 | |
| 7940 | final long identity = Binder.clearCallingIdentity(); |
| 7941 | try { |
| 7942 | if (phone != null) { |
| 7943 | return phone.isInEcm(); |
| 7944 | } else { |
| 7945 | return false; |
| 7946 | } |
| 7947 | } finally { |
| 7948 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7949 | } |
| 7950 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7951 | |
| 7952 | /** |
| 7953 | * Get the current signal strength information for the given subscription. |
| 7954 | * Because this information is not updated when the device is in a low power state |
| 7955 | * it should not be relied-upon to be current. |
| 7956 | * @param subId Subscription index |
| 7957 | * @return the most recent cached signal strength info from the modem |
| 7958 | */ |
| 7959 | @Override |
| 7960 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7961 | final long identity = Binder.clearCallingIdentity(); |
| 7962 | try { |
| 7963 | Phone p = getPhone(subId); |
| 7964 | if (p == null) { |
| 7965 | return null; |
| 7966 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7968 | return p.getSignalStrength(); |
| 7969 | } finally { |
| 7970 | Binder.restoreCallingIdentity(identity); |
| 7971 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7972 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7973 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7974 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7975 | * Get the current modem radio state for the given slot. |
| 7976 | * @param slotIndex slot index. |
| 7977 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7978 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7979 | * @return the current radio power state from the modem |
| 7980 | */ |
| 7981 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7982 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7983 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7984 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7986 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7987 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7988 | } |
| 7989 | |
| 7990 | final long identity = Binder.clearCallingIdentity(); |
| 7991 | try { |
| 7992 | return phone.getRadioPowerState(); |
| 7993 | } finally { |
| 7994 | Binder.restoreCallingIdentity(identity); |
| 7995 | } |
| 7996 | } |
| 7997 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7998 | } |
| 7999 | |
| 8000 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8001 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8002 | * |
| 8003 | * <p>Requires one of the following permissions: |
| 8004 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8005 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8006 | * privileges. |
| 8007 | * |
| 8008 | * @param subId subscription id |
| 8009 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8010 | * {@code false}. |
| 8011 | */ |
| 8012 | @Override |
| 8013 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8014 | try { |
| 8015 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8016 | null); |
| 8017 | } catch (Exception e) { |
| 8018 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8019 | mApp, subId, "isDataRoamingEnabled"); |
| 8020 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8021 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8022 | boolean isEnabled = false; |
| 8023 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8024 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8025 | Phone phone = getPhone(subId); |
| 8026 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8027 | } finally { |
| 8028 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8029 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8030 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | |
| 8034 | /** |
| 8035 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8036 | * |
| 8037 | * <p> Requires permission: |
| 8038 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8039 | * privileges. |
| 8040 | * |
| 8041 | * @param subId subscription id |
| 8042 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8043 | */ |
| 8044 | @Override |
| 8045 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8046 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8047 | mApp, subId, "setDataRoamingEnabled"); |
| 8048 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8049 | final long identity = Binder.clearCallingIdentity(); |
| 8050 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8051 | Phone phone = getPhone(subId); |
| 8052 | if (phone != null) { |
| 8053 | phone.setDataRoamingEnabled(isEnabled); |
| 8054 | } |
| 8055 | } finally { |
| 8056 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8057 | } |
| 8058 | } |
| 8059 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8060 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8061 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8062 | TelephonyPermissions |
| 8063 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8064 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8065 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8066 | boolean isAllowed = true; |
| 8067 | final long identity = Binder.clearCallingIdentity(); |
| 8068 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8069 | Phone phone = getPhone(subId); |
| 8070 | if (phone != null) { |
| 8071 | isAllowed = phone.isCspPlmnEnabled(); |
| 8072 | } |
| 8073 | } finally { |
| 8074 | Binder.restoreCallingIdentity(identity); |
| 8075 | } |
| 8076 | return isAllowed; |
| 8077 | } |
| 8078 | |
| 8079 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8080 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8081 | // Verify that tha callingPackage belongs to the calling UID |
| 8082 | mApp.getSystemService(AppOpsManager.class) |
| 8083 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8084 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8085 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8086 | try { |
| 8087 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8088 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8089 | } catch (SecurityException e) { |
| 8090 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8091 | // has carrier privileges on an active UICC |
| 8092 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8093 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8094 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8095 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8096 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8097 | |
| 8098 | final long identity = Binder.clearCallingIdentity(); |
| 8099 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8100 | UiccController uiccController = UiccController.getInstance(); |
| 8101 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8102 | if (hasReadPermission) { |
| 8103 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8104 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8105 | |
| 8106 | // Remove private info if the caller doesn't have access |
| 8107 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8108 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8109 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8110 | // is available |
| 8111 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8112 | if (card == null || card.getUiccProfile() == null) { |
| 8113 | // assume no access if the card or profile is unavailable |
| 8114 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8115 | continue; |
| 8116 | } |
| 8117 | UiccProfile profile = card.getUiccProfile(); |
| 8118 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8119 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8120 | filteredInfos.add(cardInfo); |
| 8121 | } else { |
| 8122 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8123 | } |
| 8124 | } |
| 8125 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8126 | } finally { |
| 8127 | Binder.restoreCallingIdentity(identity); |
| 8128 | } |
| 8129 | } |
| 8130 | |
| 8131 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8132 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8133 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8138 | if (slots == null) { |
| 8139 | Rlog.i(LOG_TAG, "slots is null."); |
| 8140 | return null; |
| 8141 | } |
| 8142 | |
| 8143 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8144 | for (int i = 0; i < slots.length; i++) { |
| 8145 | UiccSlot slot = slots[i]; |
| 8146 | if (slot == null) { |
| 8147 | continue; |
| 8148 | } |
| 8149 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8150 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8151 | UiccCard card = slot.getUiccCard(); |
| 8152 | if (card != null) { |
| 8153 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8154 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8155 | cardId = slot.getEid(); |
| 8156 | if (TextUtils.isEmpty(cardId)) { |
| 8157 | cardId = slot.getIccId(); |
| 8158 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8159 | } |
| 8160 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8161 | if (cardId != null) { |
| 8162 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8163 | // if cardId is an EID, it's all digits so this is fine |
| 8164 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8165 | } |
| 8166 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8167 | int cardState = 0; |
| 8168 | switch (slot.getCardState()) { |
| 8169 | case CARDSTATE_ABSENT: |
| 8170 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8171 | break; |
| 8172 | case CARDSTATE_PRESENT: |
| 8173 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8174 | break; |
| 8175 | case CARDSTATE_ERROR: |
| 8176 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8177 | break; |
| 8178 | case CARDSTATE_RESTRICTED: |
| 8179 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8180 | break; |
| 8181 | default: |
| 8182 | break; |
| 8183 | |
| 8184 | } |
| 8185 | |
| 8186 | infos[i] = new UiccSlotInfo( |
| 8187 | slot.isActive(), |
| 8188 | slot.isEuicc(), |
| 8189 | cardId, |
| 8190 | cardState, |
| 8191 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8192 | slot.isExtendedApduSupported(), |
| 8193 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8194 | } |
| 8195 | return infos; |
| 8196 | } finally { |
| 8197 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8198 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | @Override |
| 8202 | public boolean switchSlots(int[] physicalSlots) { |
| 8203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8204 | |
| 8205 | final long identity = Binder.clearCallingIdentity(); |
| 8206 | try { |
| 8207 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8208 | } finally { |
| 8209 | Binder.restoreCallingIdentity(identity); |
| 8210 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8211 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8212 | |
| 8213 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8214 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8215 | final long identity = Binder.clearCallingIdentity(); |
| 8216 | try { |
| 8217 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8218 | } finally { |
| 8219 | Binder.restoreCallingIdentity(identity); |
| 8220 | } |
| 8221 | } |
| 8222 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8223 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8224 | * A test API to reload the UICC profile. |
| 8225 | * |
| 8226 | * <p>Requires that the calling app has permission |
| 8227 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8228 | * @hide |
| 8229 | */ |
| 8230 | @Override |
| 8231 | public void refreshUiccProfile(int subId) { |
| 8232 | enforceModifyPermission(); |
| 8233 | |
| 8234 | final long identity = Binder.clearCallingIdentity(); |
| 8235 | try { |
| 8236 | Phone phone = getPhone(subId); |
| 8237 | if (phone == null) { |
| 8238 | return; |
| 8239 | } |
| 8240 | UiccCard uiccCard = phone.getUiccCard(); |
| 8241 | if (uiccCard == null) { |
| 8242 | return; |
| 8243 | } |
| 8244 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8245 | if (uiccProfile == null) { |
| 8246 | return; |
| 8247 | } |
| 8248 | uiccProfile.refresh(); |
| 8249 | } finally { |
| 8250 | Binder.restoreCallingIdentity(identity); |
| 8251 | } |
| 8252 | } |
| 8253 | |
| 8254 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8255 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8256 | */ |
| 8257 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8258 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8259 | } |
| 8260 | |
| 8261 | /** |
| 8262 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8263 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8264 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8265 | */ |
| 8266 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8267 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8268 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8269 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8270 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8271 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8272 | return isDataRoamingEnabled; |
| 8273 | } |
| 8274 | |
| 8275 | /** |
| 8276 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8277 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8278 | */ |
| 8279 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8280 | List<Integer> list = TelephonyProperties.default_network(); |
| 8281 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8282 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8283 | return list.get(phoneId); |
| 8284 | } |
| 8285 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8286 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8287 | |
| 8288 | @Override |
| 8289 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8290 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8291 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | |
| 8293 | final long identity = Binder.clearCallingIdentity(); |
| 8294 | try { |
| 8295 | final Phone phone = getPhone(subId); |
| 8296 | if (phone == null) { |
| 8297 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8298 | return; |
| 8299 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8300 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8301 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8302 | if (carrierPrivilegeRules == null) { |
| 8303 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8304 | } else { |
| 8305 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8306 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8307 | } finally { |
| 8308 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8309 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8310 | } |
| 8311 | |
| 8312 | @Override |
| 8313 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8314 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | |
| 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | try { |
| 8318 | final Phone phone = getPhone(subId); |
| 8319 | if (phone == null) { |
| 8320 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8321 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8322 | } |
| 8323 | return phone.getCarrierIdListVersion(); |
| 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8326 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8327 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8328 | |
| 8329 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8330 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8331 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8332 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8333 | mApp, subId, callingPackage, callingFeatureId, |
| 8334 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8335 | return -1; |
| 8336 | } |
| 8337 | |
| 8338 | final long identity = Binder.clearCallingIdentity(); |
| 8339 | try { |
| 8340 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8341 | } finally { |
| 8342 | Binder.restoreCallingIdentity(identity); |
| 8343 | } |
| 8344 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8345 | |
| 8346 | @Override |
| 8347 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8348 | TelephonyPermissions |
| 8349 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8350 | mApp, subId, "getCdmaRoamingMode"); |
| 8351 | |
| 8352 | final long identity = Binder.clearCallingIdentity(); |
| 8353 | try { |
| 8354 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8355 | } finally { |
| 8356 | Binder.restoreCallingIdentity(identity); |
| 8357 | } |
| 8358 | } |
| 8359 | |
| 8360 | @Override |
| 8361 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8363 | mApp, subId, "setCdmaRoamingMode"); |
| 8364 | |
| 8365 | final long identity = Binder.clearCallingIdentity(); |
| 8366 | try { |
| 8367 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
| 8371 | } |
| 8372 | |
| 8373 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8374 | public int getCdmaSubscriptionMode(int subId) { |
| 8375 | TelephonyPermissions |
| 8376 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8377 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8378 | |
| 8379 | final long identity = Binder.clearCallingIdentity(); |
| 8380 | try { |
| 8381 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8388 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8389 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8390 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8391 | |
| 8392 | final long identity = Binder.clearCallingIdentity(); |
| 8393 | try { |
| 8394 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8395 | } finally { |
| 8396 | Binder.restoreCallingIdentity(identity); |
| 8397 | } |
| 8398 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8399 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8400 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8401 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8402 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8403 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8404 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8405 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8406 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8407 | } |
| 8408 | final long identity = Binder.clearCallingIdentity(); |
| 8409 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8410 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8411 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8412 | if (phone.getEmergencyNumberTracker() != null |
| 8413 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8414 | emergencyNumberListInternal.put( |
| 8415 | phone.getSubId(), |
| 8416 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8417 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8418 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8419 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8420 | } finally { |
| 8421 | Binder.restoreCallingIdentity(identity); |
| 8422 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8423 | } |
| 8424 | |
| 8425 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8426 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8427 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8428 | if (!exactMatch) { |
| 8429 | TelephonyPermissions |
| 8430 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8431 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8432 | } |
| 8433 | final long identity = Binder.clearCallingIdentity(); |
| 8434 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8435 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8436 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8437 | && phone.getEmergencyNumberTracker() |
| 8438 | .isEmergencyNumber(number, exactMatch)) { |
| 8439 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8440 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8441 | } |
| 8442 | return false; |
| 8443 | } finally { |
| 8444 | Binder.restoreCallingIdentity(identity); |
| 8445 | } |
| 8446 | } |
| 8447 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8448 | /** |
| 8449 | * Update emergency number list for test mode. |
| 8450 | */ |
| 8451 | @Override |
| 8452 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8453 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8454 | "updateEmergencyNumberListTestMode"); |
| 8455 | |
| 8456 | final long identity = Binder.clearCallingIdentity(); |
| 8457 | try { |
| 8458 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8459 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8460 | if (tracker != null) { |
| 8461 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8462 | } |
| 8463 | } |
| 8464 | } finally { |
| 8465 | Binder.restoreCallingIdentity(identity); |
| 8466 | } |
| 8467 | } |
| 8468 | |
| 8469 | /** |
| 8470 | * Get the full emergency number list for test mode. |
| 8471 | */ |
| 8472 | @Override |
| 8473 | public List<String> getEmergencyNumberListTestMode() { |
| 8474 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8475 | "getEmergencyNumberListTestMode"); |
| 8476 | |
| 8477 | final long identity = Binder.clearCallingIdentity(); |
| 8478 | try { |
| 8479 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8480 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8481 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8482 | if (tracker != null) { |
| 8483 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8484 | emergencyNumbers.add(num.getNumber()); |
| 8485 | } |
| 8486 | } |
| 8487 | } |
| 8488 | return new ArrayList<>(emergencyNumbers); |
| 8489 | } finally { |
| 8490 | Binder.restoreCallingIdentity(identity); |
| 8491 | } |
| 8492 | } |
| 8493 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8494 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8495 | public int getEmergencyNumberDbVersion(int subId) { |
| 8496 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8497 | |
| 8498 | final long identity = Binder.clearCallingIdentity(); |
| 8499 | try { |
| 8500 | final Phone phone = getPhone(subId); |
| 8501 | if (phone == null) { |
| 8502 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8503 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8504 | } |
| 8505 | return phone.getEmergencyNumberDbVersion(); |
| 8506 | } finally { |
| 8507 | Binder.restoreCallingIdentity(identity); |
| 8508 | } |
| 8509 | } |
| 8510 | |
| 8511 | @Override |
| 8512 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8513 | enforceModifyPermission(); |
| 8514 | |
| 8515 | final long identity = Binder.clearCallingIdentity(); |
| 8516 | try { |
| 8517 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8518 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8519 | if (tracker != null) { |
| 8520 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8521 | } |
| 8522 | } |
| 8523 | } finally { |
| 8524 | Binder.restoreCallingIdentity(identity); |
| 8525 | } |
| 8526 | } |
| 8527 | |
| 8528 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8529 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8530 | enforceActiveEmergencySessionPermission(); |
| 8531 | |
| 8532 | final long identity = Binder.clearCallingIdentity(); |
| 8533 | try { |
| 8534 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8535 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8536 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8537 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8538 | } |
| 8539 | } |
| 8540 | } finally { |
| 8541 | Binder.restoreCallingIdentity(identity); |
| 8542 | } |
| 8543 | } |
| 8544 | |
| 8545 | @Override |
| 8546 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8547 | enforceActiveEmergencySessionPermission(); |
| 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | try { |
| 8551 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8552 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8553 | if (tracker != null) { |
| 8554 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8555 | } |
| 8556 | } |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8563 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8564 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8565 | Phone phone = getPhone(subId); |
| 8566 | if (phone == null) { |
| 8567 | return null; |
| 8568 | } |
| 8569 | final long identity = Binder.clearCallingIdentity(); |
| 8570 | try { |
| 8571 | UiccProfile profile = UiccController.getInstance() |
| 8572 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8573 | if (profile != null) { |
| 8574 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8575 | } |
| 8576 | } finally { |
| 8577 | Binder.restoreCallingIdentity(identity); |
| 8578 | } |
| 8579 | return null; |
| 8580 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8581 | |
| 8582 | /** |
| 8583 | * Enable or disable a modem stack. |
| 8584 | */ |
| 8585 | @Override |
| 8586 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8587 | enforceModifyPermission(); |
| 8588 | |
| 8589 | final long identity = Binder.clearCallingIdentity(); |
| 8590 | try { |
| 8591 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8592 | if (phone == null) { |
| 8593 | return false; |
| 8594 | } else { |
| 8595 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8596 | } |
| 8597 | } finally { |
| 8598 | Binder.restoreCallingIdentity(identity); |
| 8599 | } |
| 8600 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8601 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8602 | /** |
| 8603 | * Whether a modem stack is enabled or not. |
| 8604 | */ |
| 8605 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8606 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8607 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8608 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8609 | if (phone == null) return false; |
| 8610 | |
| 8611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8612 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8613 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8614 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8615 | } |
| 8616 | |
| 8617 | final long identity = Binder.clearCallingIdentity(); |
| 8618 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8619 | try { |
| 8620 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8621 | } catch (NoSuchElementException ex) { |
| 8622 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8623 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
| 8627 | } |
| 8628 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8629 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8630 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8631 | enforceModifyPermission(); |
| 8632 | |
| 8633 | final long identity = Binder.clearCallingIdentity(); |
| 8634 | try { |
| 8635 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8636 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8637 | .commit(); |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8644 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8645 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8647 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8648 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8649 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8650 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8651 | |
| 8652 | final long identity = Binder.clearCallingIdentity(); |
| 8653 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8654 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
| 8657 | } |
| 8658 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8659 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8660 | @TelephonyManager.IsMultiSimSupportedResult |
| 8661 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8662 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8663 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8664 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8665 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8666 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8667 | } |
| 8668 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8669 | // supported by the modem, indicate that it is restricted. |
| 8670 | PhoneCapability staticCapability = |
| 8671 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8672 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8673 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8674 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8675 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8676 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8677 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8678 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8679 | } |
| 8680 | // Check if support of multiple SIMs is restricted by carrier |
| 8681 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8682 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8683 | } |
| 8684 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8685 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8686 | } |
| 8687 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8688 | /** |
| 8689 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8690 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8691 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8692 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8693 | * @param numOfSims number of active sims we want to switch to |
| 8694 | */ |
| 8695 | @Override |
| 8696 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8697 | if (numOfSims == 1) { |
| 8698 | enforceModifyPermission(); |
| 8699 | } else { |
| 8700 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8701 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8702 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8703 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8704 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8705 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8706 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8707 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8708 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8709 | return; |
| 8710 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8711 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8712 | } finally { |
| 8713 | Binder.restoreCallingIdentity(identity); |
| 8714 | } |
| 8715 | } |
| 8716 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8717 | @Override |
| 8718 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8719 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8720 | Phone phone = getPhone(subId); |
| 8721 | if (phone == null) { |
| 8722 | return false; |
| 8723 | } |
| 8724 | final long identity = Binder.clearCallingIdentity(); |
| 8725 | try { |
| 8726 | UiccCard uiccCard = phone.getUiccCard(); |
| 8727 | if (uiccCard == null) { |
| 8728 | return false; |
| 8729 | } |
| 8730 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8731 | if (uiccProfile == null) { |
| 8732 | return false; |
| 8733 | } |
| 8734 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8735 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8736 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8737 | } |
| 8738 | return false; |
| 8739 | } finally { |
| 8740 | Binder.restoreCallingIdentity(identity); |
| 8741 | } |
| 8742 | } |
| 8743 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8744 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8745 | * Get whether making changes to modem configurations will trigger reboot. |
| 8746 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8747 | */ |
| 8748 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8749 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8750 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8751 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8752 | mApp, subId, callingPackage, callingFeatureId, |
| 8753 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8754 | return false; |
| 8755 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8756 | final long identity = Binder.clearCallingIdentity(); |
| 8757 | try { |
| 8758 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8759 | } finally { |
| 8760 | Binder.restoreCallingIdentity(identity); |
| 8761 | } |
| 8762 | } |
| 8763 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8764 | private void updateModemStateMetrics() { |
| 8765 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8766 | // TODO: check the state for each modem if the api is ready. |
| 8767 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8768 | } |
| 8769 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8770 | @Override |
| 8771 | public int[] getSlotsMapping() { |
| 8772 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8773 | |
| 8774 | final long identity = Binder.clearCallingIdentity(); |
| 8775 | try { |
| 8776 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8777 | // All logical slots should have a mapping to a physical slot. |
| 8778 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8779 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8780 | for (int i = 0; i < slotInfos.length; i++) { |
| 8781 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8782 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8783 | } |
| 8784 | } |
| 8785 | return logicalSlotsMapping; |
| 8786 | } finally { |
| 8787 | Binder.restoreCallingIdentity(identity); |
| 8788 | } |
| 8789 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8790 | |
| 8791 | /** |
| 8792 | * Get the IRadio HAL Version |
| 8793 | */ |
| 8794 | @Override |
| 8795 | public int getRadioHalVersion() { |
| 8796 | Phone phone = getDefaultPhone(); |
| 8797 | if (phone == null) return -1; |
| 8798 | HalVersion hv = phone.getHalVersion(); |
| 8799 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8800 | return hv.major * 100 + hv.minor; |
| 8801 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8802 | |
| 8803 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8804 | * Get the current calling package name. |
| 8805 | * @return the current calling package name |
| 8806 | */ |
| 8807 | @Override |
| 8808 | public String getCurrentPackageName() { |
| 8809 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8810 | } |
| 8811 | |
| 8812 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8813 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8814 | * corresponding network requests on a subId. |
| 8815 | * |
| 8816 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8817 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8818 | * 2) APN is un-metered for this subscription, or |
| 8819 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8820 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8821 | * |
| 8822 | * @return whether data is allowed for a apn type. |
| 8823 | * |
| 8824 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8825 | */ |
| 8826 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8827 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8828 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8829 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8830 | |
| 8831 | // Now that all security checks passes, perform the operation as ourselves. |
| 8832 | final long identity = Binder.clearCallingIdentity(); |
| 8833 | try { |
| 8834 | Phone phone = getPhone(subId); |
| 8835 | if (phone == null) return false; |
| 8836 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8837 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8838 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8839 | } finally { |
| 8840 | Binder.restoreCallingIdentity(identity); |
| 8841 | } |
| 8842 | } |
| 8843 | |
| 8844 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8845 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8846 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8847 | |
| 8848 | // Now that all security checks passes, perform the operation as ourselves. |
| 8849 | final long identity = Binder.clearCallingIdentity(); |
| 8850 | try { |
| 8851 | Phone phone = getPhone(subId); |
| 8852 | if (phone == null) return true; // By default return true. |
| 8853 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8854 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8855 | } finally { |
| 8856 | Binder.restoreCallingIdentity(identity); |
| 8857 | } |
| 8858 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8859 | |
| 8860 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8861 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8862 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8863 | enforceModifyPermission(); |
| 8864 | long token = Binder.clearCallingIdentity(); |
| 8865 | try { |
| 8866 | Phone phone = getPhone(subscriptionId); |
| 8867 | if (phone == null) { |
| 8868 | try { |
| 8869 | if (resultCallback != null) { |
| 8870 | resultCallback.accept(false); |
| 8871 | } |
| 8872 | } catch (RemoteException e) { |
| 8873 | // ignore |
| 8874 | } |
| 8875 | return; |
| 8876 | } |
| 8877 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8878 | Pair.create(specifiers, (x) -> { |
| 8879 | try { |
| 8880 | if (resultCallback != null) { |
| 8881 | resultCallback.accept(x); |
| 8882 | } |
| 8883 | } catch (RemoteException e) { |
| 8884 | // ignore |
| 8885 | } |
| 8886 | }); |
| 8887 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8888 | } finally { |
| 8889 | Binder.restoreCallingIdentity(token); |
| 8890 | } |
| 8891 | } |
| 8892 | |
| 8893 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8894 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8895 | TelephonyPermissions |
| 8896 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8897 | mApp, subId, "getSystemSelectionChannels"); |
| 8898 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | List<RadioAccessSpecifier> specifiers = |
| 8902 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8903 | null, subId, workSource); |
| 8904 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8905 | return specifiers; |
| 8906 | } finally { |
| 8907 | Binder.restoreCallingIdentity(identity); |
| 8908 | } |
| 8909 | } |
| 8910 | |
| 8911 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8912 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8913 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8914 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8915 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8916 | if (iccRecords == null) { |
| 8917 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8918 | return false; |
| 8919 | } |
| 8920 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8921 | } |
| 8922 | |
| 8923 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8924 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8925 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8926 | if (callingPackage == null) { |
| 8927 | callingPackage = getCurrentPackageName(); |
| 8928 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8929 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8930 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8931 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8932 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8933 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8934 | } |
| 8935 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8936 | Intent intent = new Intent(); |
| 8937 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8938 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8939 | // Bring up choose default SMS subscription dialog right now |
| 8940 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8941 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8942 | mApp.startActivity(intent); |
| 8943 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8944 | |
| 8945 | @Override |
| 8946 | public String getMmsUAProfUrl(int subId) { |
| 8947 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8950 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8951 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8952 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8953 | return carrierUAProfUrl; |
| 8954 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8955 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8956 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8957 | } finally { |
| 8958 | Binder.restoreCallingIdentity(identity); |
| 8959 | } |
| 8960 | } |
| 8961 | |
| 8962 | @Override |
| 8963 | public String getMmsUserAgent(int subId) { |
| 8964 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8965 | final long identity = Binder.clearCallingIdentity(); |
| 8966 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8967 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8968 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8969 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8970 | return carrierUserAgent; |
| 8971 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8972 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8973 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8974 | } finally { |
| 8975 | Binder.restoreCallingIdentity(identity); |
| 8976 | } |
| 8977 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8978 | |
| 8979 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8980 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8981 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8982 | |
| 8983 | final long identity = Binder.clearCallingIdentity(); |
| 8984 | try { |
| 8985 | Phone phone = getPhone(subscriptionId); |
| 8986 | if (phone == null) return false; |
| 8987 | |
| 8988 | switch (policy) { |
| 8989 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8990 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8991 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8992 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8993 | default: |
| 8994 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8995 | } |
| 8996 | } finally { |
| 8997 | Binder.restoreCallingIdentity(identity); |
| 8998 | } |
| 8999 | } |
| 9000 | |
| 9001 | @Override |
| 9002 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9003 | boolean enabled) { |
| 9004 | enforceModifyPermission(); |
| 9005 | |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
| 9008 | Phone phone = getPhone(subscriptionId); |
| 9009 | if (phone == null) return; |
| 9010 | |
| 9011 | switch (policy) { |
| 9012 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9013 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9014 | break; |
| 9015 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9016 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9017 | break; |
| 9018 | default: |
| 9019 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9020 | } |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
| 9024 | } |
| 9025 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9026 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9027 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9028 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9029 | * otherwise. |
| 9030 | */ |
| 9031 | @Override |
| 9032 | public void setCepEnabled(boolean isCepEnabled) { |
| 9033 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9034 | |
| 9035 | final long identity = Binder.clearCallingIdentity(); |
| 9036 | try { |
| 9037 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9038 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9039 | Phone defaultPhone = phone.getImsPhone(); |
| 9040 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9041 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9042 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9043 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9044 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9045 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9046 | + imsPhone.getMsisdn()); |
| 9047 | } |
| 9048 | } |
| 9049 | } finally { |
| 9050 | Binder.restoreCallingIdentity(identity); |
| 9051 | } |
| 9052 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9053 | |
| 9054 | /** |
| 9055 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9056 | * |
| 9057 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9058 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9059 | * before being read. |
| 9060 | */ |
| 9061 | @Override |
| 9062 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9063 | isCompressed) { |
| 9064 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9065 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 9066 | try { |
| 9067 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9068 | if (configBinder == null) { |
| 9069 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 9070 | } else { |
| 9071 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 9072 | } |
| 9073 | } catch (RemoteException e) { |
| 9074 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 9075 | } |
| 9076 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9077 | |
| 9078 | @Override |
| 9079 | public boolean isIccLockEnabled(int subId) { |
| 9080 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9081 | |
| 9082 | // Now that all security checks passes, perform the operation as ourselves. |
| 9083 | final long identity = Binder.clearCallingIdentity(); |
| 9084 | try { |
| 9085 | Phone phone = getPhone(subId); |
| 9086 | if (phone != null && phone.getIccCard() != null) { |
| 9087 | return phone.getIccCard().getIccLockEnabled(); |
| 9088 | } else { |
| 9089 | return false; |
| 9090 | } |
| 9091 | } finally { |
| 9092 | Binder.restoreCallingIdentity(identity); |
| 9093 | } |
| 9094 | } |
| 9095 | |
| 9096 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9097 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9098 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9099 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9100 | * three cases: |
| 9101 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9102 | * successfully. |
| 9103 | * - Positive number and zero for remaining password attempts. |
| 9104 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9105 | * |
| 9106 | */ |
| 9107 | @Override |
| 9108 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9109 | enforceModifyPermission(); |
| 9110 | |
| 9111 | Phone phone = getPhone(subId); |
| 9112 | if (phone == null) { |
| 9113 | return 0; |
| 9114 | } |
| 9115 | // Now that all security checks passes, perform the operation as ourselves. |
| 9116 | final long identity = Binder.clearCallingIdentity(); |
| 9117 | try { |
| 9118 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9119 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9120 | return attemptsRemaining; |
| 9121 | |
| 9122 | } catch (Exception e) { |
| 9123 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9124 | } finally { |
| 9125 | Binder.restoreCallingIdentity(identity); |
| 9126 | } |
| 9127 | return 0; |
| 9128 | } |
| 9129 | |
| 9130 | /** |
| 9131 | * Change the ICC password used in ICC pin lock. |
| 9132 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9133 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9134 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9135 | * - Positive number and zero for remaining password attempts. |
| 9136 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9137 | * |
| 9138 | */ |
| 9139 | @Override |
| 9140 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9141 | enforceModifyPermission(); |
| 9142 | |
| 9143 | Phone phone = getPhone(subId); |
| 9144 | if (phone == null) { |
| 9145 | return 0; |
| 9146 | } |
| 9147 | // Now that all security checks passes, perform the operation as ourselves. |
| 9148 | final long identity = Binder.clearCallingIdentity(); |
| 9149 | try { |
| 9150 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9151 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9152 | return attemptsRemaining; |
| 9153 | |
| 9154 | } catch (Exception e) { |
| 9155 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9156 | } finally { |
| 9157 | Binder.restoreCallingIdentity(identity); |
| 9158 | } |
| 9159 | return 0; |
| 9160 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9161 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9162 | /** |
| 9163 | * Request for receiving user activity notification |
| 9164 | */ |
| 9165 | @Override |
| 9166 | public void requestUserActivityNotification() { |
| 9167 | if (!mNotifyUserActivity.get() |
| 9168 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9169 | mNotifyUserActivity.set(true); |
| 9170 | } |
| 9171 | } |
| 9172 | |
| 9173 | /** |
| 9174 | * Called when userActivity is signalled in the power manager. |
| 9175 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9176 | */ |
| 9177 | @Override |
| 9178 | public void userActivity() { |
| 9179 | // *************************************** |
| 9180 | // * Inherited from PhoneWindowManager * |
| 9181 | // *************************************** |
| 9182 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9183 | // WITH ITS LOCKS HELD. |
| 9184 | // |
| 9185 | // This code must be VERY careful about the locks |
| 9186 | // it acquires. |
| 9187 | // In fact, the current code acquires way too many, |
| 9188 | // and probably has lurking deadlocks. |
| 9189 | |
| 9190 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9191 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9192 | } |
| 9193 | |
| 9194 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9195 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9196 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9197 | } |
| 9198 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9199 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9200 | @Override |
| 9201 | public boolean canConnectTo5GInDsdsMode() { |
| 9202 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9203 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9204 | |
| 9205 | @Override |
| 9206 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9207 | String callingFeatureId) { |
| 9208 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9209 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9210 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9211 | } |
| 9212 | |
| 9213 | Phone phone = getPhone(subId); |
| 9214 | if (phone == null) { |
| 9215 | throw new RuntimeException("phone is not available"); |
| 9216 | } |
| 9217 | // Now that all security checks passes, perform the operation as ourselves. |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
| 9219 | try { |
| 9220 | return phone.getEquivalentHomePlmns(); |
| 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
| 9224 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9225 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9226 | @Override |
| 9227 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9228 | UaSecurityProtocolIdentifier securityProtocol, |
| 9229 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9230 | throws RemoteException { |
| 9231 | enforceModifyPermission(); |
| 9232 | if (DBG) { |
| 9233 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9234 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9235 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9236 | } |
| 9237 | |
| 9238 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9239 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9240 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9241 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9242 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9243 | if (callback != null) { |
| 9244 | try { |
| 9245 | callback.onAuthenticationFailure( |
| 9246 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9247 | } catch (RemoteException exception) { |
| 9248 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9249 | } |
| 9250 | return; |
| 9251 | } |
| 9252 | } |
| 9253 | |
| 9254 | final long token = Binder.clearCallingIdentity(); |
| 9255 | try { |
| 9256 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9257 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9258 | forceBootStrapping, callback)); |
| 9259 | } finally { |
| 9260 | Binder.restoreCallingIdentity(token); |
| 9261 | } |
| 9262 | } |
| 9263 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9264 | /** |
| 9265 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9266 | * requested radio power state will actually be set. See {@link |
| 9267 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9268 | * |
| 9269 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9270 | * @param enable {@code true} if trying to turn radio on. |
| 9271 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9272 | * false}. |
| 9273 | */ |
| 9274 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9275 | Phone phone = getPhone(subId); |
| 9276 | if (phone != null) { |
| 9277 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9278 | return true; |
| 9279 | } |
| 9280 | return false; |
| 9281 | } |
| 9282 | |
| 9283 | private int handleDataThrottlingRequest(int subId, |
| 9284 | DataThrottlingRequest dataThrottlingRequest) { |
| 9285 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9286 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9287 | if (!setRadioPowerForThermal(subId, true)) { |
| 9288 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9289 | } |
| 9290 | |
| 9291 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9292 | |
| 9293 | int thermalMitigationResult = |
| 9294 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9295 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9296 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9297 | } |
| 9298 | return thermalMitigationResult; |
| 9299 | } |
| 9300 | |
| 9301 | /** |
| 9302 | * Thermal mitigation request to control functionalities at modem. |
| 9303 | * |
| 9304 | * @param subId the id of the subscription. |
| 9305 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9306 | * |
| 9307 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9308 | */ |
| 9309 | @Override |
| 9310 | @ThermalMitigationResult |
| 9311 | public int sendThermalMitigationRequest( |
| 9312 | int subId, |
| 9313 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9314 | enforceModifyPermission(); |
| 9315 | |
| 9316 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9317 | final long identity = Binder.clearCallingIdentity(); |
| 9318 | |
| 9319 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9320 | try { |
| 9321 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9322 | switch (thermalMitigationAction) { |
| 9323 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9324 | thermalMitigationResult = |
| 9325 | handleDataThrottlingRequest(subId, |
| 9326 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9327 | break; |
| 9328 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9329 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9330 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9331 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9332 | } |
| 9333 | |
| 9334 | // Ensure that radio is on. If not able to power on due to phone being |
| 9335 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9336 | if (!setRadioPowerForThermal(subId, true)) { |
| 9337 | thermalMitigationResult = |
| 9338 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9339 | break; |
| 9340 | } |
| 9341 | |
| 9342 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9343 | false); |
| 9344 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9345 | break; |
| 9346 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9347 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9348 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9349 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9350 | } |
| 9351 | |
| 9352 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9353 | if (registry != null) { |
| 9354 | TelephonyConnectionService service = |
| 9355 | registry.getTelephonyConnectionService(); |
| 9356 | Phone phone = getPhone(subId); |
| 9357 | if (phone == null) { |
| 9358 | thermalMitigationResult = |
| 9359 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9360 | break; |
| 9361 | } |
| 9362 | |
| 9363 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9364 | != TelephonyManager.CALL_STATE_IDLE |
| 9365 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9366 | || (service != null && service.isEmergencyCallPending())) { |
| 9367 | String errorMessage = "Phone state is not valid. call state = " |
| 9368 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9369 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9370 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9371 | errorMessage += service == null |
| 9372 | ? " TelephonyConnectionService is null" |
| 9373 | : " isEmergencyCallPending = " |
| 9374 | + service.isEmergencyCallPending(); |
| 9375 | Log.e(LOG_TAG, errorMessage); |
| 9376 | thermalMitigationResult = |
| 9377 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9378 | break; |
| 9379 | } |
| 9380 | } else { |
| 9381 | thermalMitigationResult = |
| 9382 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9383 | break; |
| 9384 | } |
| 9385 | |
| 9386 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9387 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9388 | if (!setRadioPowerForThermal(subId, false)) { |
| 9389 | thermalMitigationResult = |
| 9390 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9391 | break; |
| 9392 | } |
| 9393 | thermalMitigationResult = |
| 9394 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9395 | break; |
| 9396 | default: |
| 9397 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9398 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9399 | } |
| 9400 | } catch (IllegalArgumentException e) { |
| 9401 | throw e; |
| 9402 | } catch (Exception e) { |
| 9403 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9404 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9405 | } finally { |
| 9406 | Binder.restoreCallingIdentity(identity); |
| 9407 | } |
| 9408 | |
| 9409 | if (DBG) { |
| 9410 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9411 | + thermalMitigationResult); |
| 9412 | } |
| 9413 | |
| 9414 | return thermalMitigationResult; |
| 9415 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9416 | |
| 9417 | /** |
| 9418 | * Set the GbaService Package Name that Telephony will bind to. |
| 9419 | * |
| 9420 | * @param subId The sim that the GbaService is associated with. |
| 9421 | * @param packageName The name of the package to be replaced with. |
| 9422 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9423 | */ |
| 9424 | @Override |
| 9425 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9426 | enforceModifyPermission(); |
| 9427 | |
| 9428 | final long identity = Binder.clearCallingIdentity(); |
| 9429 | try { |
| 9430 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9431 | } finally { |
| 9432 | Binder.restoreCallingIdentity(identity); |
| 9433 | } |
| 9434 | } |
| 9435 | |
| 9436 | /** |
| 9437 | * Return the package name of the currently bound GbaService. |
| 9438 | * |
| 9439 | * @param subId The sim that the GbaService is associated with. |
| 9440 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9441 | */ |
| 9442 | @Override |
| 9443 | public String getBoundGbaService(int subId) { |
| 9444 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9445 | |
| 9446 | final long identity = Binder.clearCallingIdentity(); |
| 9447 | try { |
| 9448 | return getGbaManager(subId).getServicePackage(); |
| 9449 | } finally { |
| 9450 | Binder.restoreCallingIdentity(identity); |
| 9451 | } |
| 9452 | } |
| 9453 | |
| 9454 | /** |
| 9455 | * Set the release time for telephony to unbind GbaService. |
| 9456 | * |
| 9457 | * @param subId The sim that the GbaService is associated with. |
| 9458 | * @param interval The release time to unbind GbaService by millisecond. |
| 9459 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9460 | */ |
| 9461 | @Override |
| 9462 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9463 | enforceModifyPermission(); |
| 9464 | |
| 9465 | final long identity = Binder.clearCallingIdentity(); |
| 9466 | try { |
| 9467 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9468 | } finally { |
| 9469 | Binder.restoreCallingIdentity(identity); |
| 9470 | } |
| 9471 | } |
| 9472 | |
| 9473 | /** |
| 9474 | * Return the release time for telephony to unbind GbaService. |
| 9475 | * |
| 9476 | * @param subId The sim that the GbaService is associated with. |
| 9477 | * @return The release time to unbind GbaService by millisecond. |
| 9478 | */ |
| 9479 | @Override |
| 9480 | public int getGbaReleaseTime(int subId) { |
| 9481 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9482 | |
| 9483 | final long identity = Binder.clearCallingIdentity(); |
| 9484 | try { |
| 9485 | return getGbaManager(subId).getReleaseTime(); |
| 9486 | } finally { |
| 9487 | Binder.restoreCallingIdentity(identity); |
| 9488 | } |
| 9489 | } |
| 9490 | |
| 9491 | private GbaManager getGbaManager(int subId) { |
| 9492 | GbaManager instance = GbaManager.getInstance(subId); |
| 9493 | if (instance == null) { |
| 9494 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9495 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9496 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9497 | } |
| 9498 | return instance; |
| 9499 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9500 | } |