Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 55 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 56 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 57 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 58 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 59 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 60 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 61 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 62 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 64 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 65 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 66 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 78 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 79 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 80 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 81 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 82 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 83 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 85 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 88 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 91 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrengthUpdateRequest; |
| 93 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 96 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 100 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 101 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 102 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 103 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 104 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 105 | import android.telephony.data.ApnSetting; |
| 106 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 107 | import android.telephony.gba.GbaAuthRequest; |
| 108 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 109 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 110 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 111 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 112 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 119 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 120 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 126 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 128 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 129 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 130 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 131 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 171 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 185 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 187 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 189 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 192 | import com.android.services.telephony.TelecomAccountRegistry; |
| 193 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 194 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 195 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 196 | import java.io.FileDescriptor; |
| 197 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 199 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 200 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 201 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 202 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 203 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 205 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 206 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 207 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 208 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 209 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * Implementation of the ITelephony interface. |
| 213 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 214 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 216 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 217 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 218 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 219 | |
| 220 | // Message codes used with mMainThreadHandler |
| 221 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 222 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 223 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 224 | private static final int CMD_OPEN_CHANNEL = 9; |
| 225 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 226 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 227 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 228 | private static final int CMD_NV_READ_ITEM = 13; |
| 229 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 230 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 231 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 232 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 233 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 234 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 235 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 236 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 237 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 238 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 239 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 240 | private static final int CMD_SEND_ENVELOPE = 25; |
| 241 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 242 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 243 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 244 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 245 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 246 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 247 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 248 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 249 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 250 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 251 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 253 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 254 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 255 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 256 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 257 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 258 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 259 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 260 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 261 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 262 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 263 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 264 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 265 | private static final int CMD_SWITCH_SLOTS = 50; |
| 266 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 268 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 269 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 270 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 271 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 272 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 273 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 274 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 275 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 276 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 277 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 278 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 279 | private static final int CMD_MODEM_REBOOT = 64; |
| 280 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 281 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 282 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 283 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 284 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 285 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 286 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 287 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 288 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 289 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 290 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 291 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 292 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 293 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 294 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 295 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 296 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 297 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 298 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 299 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 300 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 301 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 302 | private static final int CMD_GET_CALL_WAITING = 87; |
| 303 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 304 | private static final int CMD_SET_CALL_WAITING = 89; |
| 305 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 306 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 307 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 308 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 309 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 311 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 312 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 313 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 314 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 315 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 316 | private static final int CMD_SET_SIM_POWER = 101; |
| 317 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 319 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 320 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 321 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 323 | // Parameters of select command. |
| 324 | private static final int SELECT_COMMAND = 0xA4; |
| 325 | private static final int SELECT_P1 = 0x04; |
| 326 | private static final int SELECT_P2 = 0; |
| 327 | private static final int SELECT_P3 = 0x10; |
| 328 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 329 | /** The singleton instance. */ |
| 330 | private static PhoneInterfaceManager sInstance; |
| 331 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 332 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 333 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 334 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 335 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 336 | private AppOpsManager mAppOps; |
| 337 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 338 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 339 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 340 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 341 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 342 | /** User Activity */ |
| 343 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 344 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 345 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 346 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 347 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 348 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 349 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 350 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 351 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 352 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 353 | // String to store multi SIM allowed |
| 354 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 355 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 356 | // The AID of ISD-R. |
| 357 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 358 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 359 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 360 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 361 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 362 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 363 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 364 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 365 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 366 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 367 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 368 | */ |
| 369 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 370 | "reset_network_erase_modem_config_enabled"; |
| 371 | |
| 372 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 373 | * A request object to use for transmitting data to an ICC. |
| 374 | */ |
| 375 | private static final class IccAPDUArgument { |
| 376 | public int channel, cla, command, p1, p2, p3; |
| 377 | public String data; |
| 378 | |
| 379 | public IccAPDUArgument(int channel, int cla, int command, |
| 380 | int p1, int p2, int p3, String data) { |
| 381 | this.channel = channel; |
| 382 | this.cla = cla; |
| 383 | this.command = command; |
| 384 | this.p1 = p1; |
| 385 | this.p2 = p2; |
| 386 | this.p3 = p3; |
| 387 | this.data = data; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 392 | * A request object to use for transmitting data to an ICC. |
| 393 | */ |
| 394 | private static final class ManualNetworkSelectionArgument { |
| 395 | public OperatorInfo operatorInfo; |
| 396 | public boolean persistSelection; |
| 397 | |
| 398 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 399 | this.operatorInfo = operatorInfo; |
| 400 | this.persistSelection = persistSelection; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 406 | * request after sending. The main thread will notify the request when it is complete. |
| 407 | */ |
| 408 | private static final class MainThreadRequest { |
| 409 | /** The argument to use for the request */ |
| 410 | public Object argument; |
| 411 | /** The result of the request that is run on the main thread */ |
| 412 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 413 | // The subscriber id that this request applies to. Defaults to |
| 414 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 415 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 417 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 418 | public Phone phone; |
| 419 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 420 | public WorkSource workSource; |
| 421 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | public MainThreadRequest(Object argument) { |
| 423 | this.argument = argument; |
| 424 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 425 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 426 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 427 | this.argument = argument; |
| 428 | if (phone != null) { |
| 429 | this.phone = phone; |
| 430 | } |
| 431 | this.workSource = workSource; |
| 432 | } |
| 433 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 434 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 435 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 436 | if (subId != null) { |
| 437 | this.subId = subId; |
| 438 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 439 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 440 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 443 | private static final class IncomingThirdPartyCallArgs { |
| 444 | public final ComponentName component; |
| 445 | public final String callId; |
| 446 | public final String callerDisplayName; |
| 447 | |
| 448 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 449 | String callerDisplayName) { |
| 450 | this.component = component; |
| 451 | this.callId = callId; |
| 452 | this.callerDisplayName = callerDisplayName; |
| 453 | } |
| 454 | } |
| 455 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | /** |
| 457 | * A handler that processes messages on the main thread in the phone process. Since many |
| 458 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 459 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 460 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 461 | * on, which will be notified when the operation completes and will contain the result of the |
| 462 | * request. |
| 463 | * |
| 464 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 465 | * note that request.result must be set to something non-null for the calling thread to |
| 466 | * unblock. |
| 467 | */ |
| 468 | private final class MainThreadHandler extends Handler { |
| 469 | @Override |
| 470 | public void handleMessage(Message msg) { |
| 471 | MainThreadRequest request; |
| 472 | Message onCompleted; |
| 473 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 474 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 475 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 476 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 477 | |
| 478 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 479 | case CMD_HANDLE_USSD_REQUEST: { |
| 480 | request = (MainThreadRequest) msg.obj; |
| 481 | final Phone phone = getPhoneFromRequest(request); |
| 482 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 483 | String ussdRequest = ussdObject.first; |
| 484 | ResultReceiver wrappedCallback = ussdObject.second; |
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 | if (!isUssdApiAllowed(request.subId)) { |
| 487 | // Carrier does not support use of this API, return failure. |
| 488 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 489 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 490 | Bundle returnData = new Bundle(); |
| 491 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 492 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 493 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | request.result = true; |
| 495 | notifyRequester(request); |
| 496 | return; |
| 497 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 498 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | try { |
| 500 | request.result = phone != null |
| 501 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 502 | } catch (CallStateException cse) { |
| 503 | request.result = false; |
| 504 | } |
| 505 | // Wake up the requesting thread |
| 506 | notifyRequester(request); |
| 507 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 510 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 512 | final Phone phone = getPhoneFromRequest(request); |
| 513 | request.result = phone != null ? |
| 514 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 515 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 517 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 518 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 521 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 522 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 524 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 525 | if (uiccCard == null) { |
| 526 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 527 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 529 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 531 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 532 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 533 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 534 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 535 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 536 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 537 | break; |
| 538 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | ar = (AsyncResult) msg.obj; |
| 541 | request = (MainThreadRequest) ar.userObj; |
| 542 | if (ar.exception == null && ar.result != null) { |
| 543 | request.result = ar.result; |
| 544 | } else { |
| 545 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 546 | if (ar.result == null) { |
| 547 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 548 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 550 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | } else { |
| 552 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 553 | } |
| 554 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | break; |
| 557 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 559 | request = (MainThreadRequest) msg.obj; |
| 560 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 561 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 562 | if (uiccCard == null) { |
| 563 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 564 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 565 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | } else { |
| 567 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 568 | request); |
| 569 | uiccCard.iccTransmitApduBasicChannel( |
| 570 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 571 | iccArgument.p3, iccArgument.data, onCompleted); |
| 572 | } |
| 573 | break; |
| 574 | |
| 575 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 576 | ar = (AsyncResult) msg.obj; |
| 577 | request = (MainThreadRequest) ar.userObj; |
| 578 | if (ar.exception == null && ar.result != null) { |
| 579 | request.result = ar.result; |
| 580 | } else { |
| 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 582 | if (ar.result == null) { |
| 583 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 584 | } else if (ar.exception instanceof CommandException) { |
| 585 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 586 | ar.exception); |
| 587 | } else { |
| 588 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 589 | } |
| 590 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | break; |
| 593 | |
| 594 | case CMD_EXCHANGE_SIM_IO: |
| 595 | request = (MainThreadRequest) msg.obj; |
| 596 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 597 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | if (uiccCard == null) { |
| 599 | loge("iccExchangeSimIO: No UICC"); |
| 600 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 601 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | } else { |
| 603 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 604 | request); |
| 605 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 606 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 607 | iccArgument.data, onCompleted); |
| 608 | } |
| 609 | break; |
| 610 | |
| 611 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 612 | ar = (AsyncResult) msg.obj; |
| 613 | request = (MainThreadRequest) ar.userObj; |
| 614 | if (ar.exception == null && ar.result != null) { |
| 615 | request.result = ar.result; |
| 616 | } else { |
| 617 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 622 | case CMD_SEND_ENVELOPE: |
| 623 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 624 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 625 | if (uiccCard == null) { |
| 626 | loge("sendEnvelopeWithStatus: No UICC"); |
| 627 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 631 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 632 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case EVENT_SEND_ENVELOPE_DONE: |
| 636 | ar = (AsyncResult) msg.obj; |
| 637 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 638 | if (ar.exception == null && ar.result != null) { |
| 639 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 640 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 641 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 642 | if (ar.result == null) { |
| 643 | loge("sendEnvelopeWithStatus: Empty response"); |
| 644 | } else if (ar.exception instanceof CommandException) { |
| 645 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 646 | ar.exception); |
| 647 | } else { |
| 648 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 649 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 650 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 652 | break; |
| 653 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | case CMD_OPEN_CHANNEL: |
| 655 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 656 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 657 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | if (uiccCard == null) { |
| 659 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 660 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 661 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | } else { |
| 664 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 665 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 666 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EVENT_OPEN_CHANNEL_DONE: |
| 671 | ar = (AsyncResult) msg.obj; |
| 672 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 675 | int[] result = (int[]) ar.result; |
| 676 | int channelId = result[0]; |
| 677 | byte[] selectResponse = null; |
| 678 | if (result.length > 1) { |
| 679 | selectResponse = new byte[result.length - 1]; |
| 680 | for (int i = 1; i < result.length; ++i) { |
| 681 | selectResponse[i - 1] = (byte) result[i]; |
| 682 | } |
| 683 | } |
| 684 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 685 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | if (ar.result == null) { |
| 688 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 690 | if (ar.exception != null) { |
| 691 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 692 | } |
| 693 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 695 | if (ar.exception instanceof CommandException) { |
| 696 | CommandException.Error error = |
| 697 | ((CommandException) (ar.exception)).getCommandError(); |
| 698 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 699 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 700 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 701 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 705 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 707 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | break; |
| 710 | |
| 711 | case CMD_CLOSE_CHANNEL: |
| 712 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 713 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 714 | if (uiccCard == null) { |
| 715 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 716 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 718 | } else { |
| 719 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 720 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 721 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 726 | break; |
| 727 | |
| 728 | case CMD_NV_READ_ITEM: |
| 729 | request = (MainThreadRequest) msg.obj; |
| 730 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 731 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 732 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 736 | ar = (AsyncResult) msg.obj; |
| 737 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | if (ar.exception == null && ar.result != null) { |
| 739 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 741 | request.result = ""; |
| 742 | if (ar.result == null) { |
| 743 | loge("nvReadItem: Empty response"); |
| 744 | } else if (ar.exception instanceof CommandException) { |
| 745 | loge("nvReadItem: CommandException: " + |
| 746 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 747 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 748 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 751 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 752 | break; |
| 753 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | case CMD_NV_WRITE_ITEM: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 757 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 758 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 759 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_NV_WRITE_ITEM_DONE: |
| 763 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 764 | break; |
| 765 | |
| 766 | case CMD_NV_WRITE_CDMA_PRL: |
| 767 | request = (MainThreadRequest) msg.obj; |
| 768 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 769 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 773 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 774 | break; |
| 775 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 776 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 777 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 778 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 779 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 780 | break; |
| 781 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 782 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 783 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 784 | break; |
| 785 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 786 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 787 | request = (MainThreadRequest) msg.obj; |
| 788 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 789 | request); |
| 790 | Phone phone = getPhoneFromRequest(request); |
| 791 | if (phone != null) { |
| 792 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 793 | } else { |
| 794 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 795 | request.result = false; |
| 796 | notifyRequester(request); |
| 797 | } |
| 798 | break; |
| 799 | } |
| 800 | |
| 801 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 802 | ar = (AsyncResult) msg.obj; |
| 803 | request = (MainThreadRequest) ar.userObj; |
| 804 | if (ar.exception == null && ar.result != null) { |
| 805 | request.result = ar.result; |
| 806 | } else { |
| 807 | // request.result must be set to something non-null |
| 808 | // for the calling thread to unblock |
| 809 | if (request.result != null) { |
| 810 | request.result = ar.result; |
| 811 | } else { |
| 812 | request.result = false; |
| 813 | } |
| 814 | if (ar.result == null) { |
| 815 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 816 | } else if (ar.exception instanceof CommandException) { |
| 817 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 818 | + ar.exception); |
| 819 | } else { |
| 820 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 821 | } |
| 822 | } |
| 823 | notifyRequester(request); |
| 824 | break; |
| 825 | |
| 826 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 827 | request = (MainThreadRequest) msg.obj; |
| 828 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 829 | Phone phone = getPhoneFromRequest(request); |
| 830 | if (phone != null) { |
| 831 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 832 | request.workSource); |
| 833 | } else { |
| 834 | loge("enableNrDualConnectivity: No phone object"); |
| 835 | request.result = |
| 836 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 837 | notifyRequester(request); |
| 838 | } |
| 839 | break; |
| 840 | } |
| 841 | |
| 842 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 843 | ar = (AsyncResult) msg.obj; |
| 844 | request = (MainThreadRequest) ar.userObj; |
| 845 | if (ar.exception == null) { |
| 846 | request.result = |
| 847 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 848 | } else { |
| 849 | request.result = |
| 850 | TelephonyManager |
| 851 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 852 | if (ar.exception instanceof CommandException) { |
| 853 | CommandException.Error error = |
| 854 | ((CommandException) (ar.exception)).getCommandError(); |
| 855 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 856 | request.result = |
| 857 | TelephonyManager |
| 858 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 859 | } |
| 860 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 861 | + ar.exception); |
| 862 | } else { |
| 863 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 864 | } |
| 865 | } |
| 866 | notifyRequester(request); |
| 867 | break; |
| 868 | } |
| 869 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 870 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 871 | request = (MainThreadRequest) msg.obj; |
| 872 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 873 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 877 | ar = (AsyncResult) msg.obj; |
| 878 | request = (MainThreadRequest) ar.userObj; |
| 879 | if (ar.exception == null && ar.result != null) { |
| 880 | request.result = ar.result; // Integer |
| 881 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 882 | // request.result must be set to something non-null |
| 883 | // for the calling thread to unblock |
| 884 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 885 | if (ar.result == null) { |
| 886 | loge("getPreferredNetworkType: Empty response"); |
| 887 | } else if (ar.exception instanceof CommandException) { |
| 888 | loge("getPreferredNetworkType: CommandException: " + |
| 889 | ar.exception); |
| 890 | } else { |
| 891 | loge("getPreferredNetworkType: Unknown exception"); |
| 892 | } |
| 893 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 894 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | break; |
| 896 | |
| 897 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 898 | request = (MainThreadRequest) msg.obj; |
| 899 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 900 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 901 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | break; |
| 903 | |
| 904 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 905 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 906 | break; |
| 907 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 908 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 909 | request = (MainThreadRequest)msg.obj; |
| 910 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 911 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 915 | ar = (AsyncResult)msg.obj; |
| 916 | request = (MainThreadRequest)ar.userObj; |
| 917 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 918 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 919 | break; |
| 920 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 921 | case CMD_SET_VOICEMAIL_NUMBER: |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 924 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 925 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 926 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 930 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 931 | break; |
| 932 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 933 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 934 | request = (MainThreadRequest) msg.obj; |
| 935 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 936 | request); |
| 937 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 938 | break; |
| 939 | |
| 940 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 941 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 942 | break; |
| 943 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 944 | case CMD_PERFORM_NETWORK_SCAN: |
| 945 | request = (MainThreadRequest) msg.obj; |
| 946 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 947 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 948 | break; |
| 949 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 950 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 951 | request = (MainThreadRequest) msg.obj; |
| 952 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 953 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 954 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 955 | request.argument; |
| 956 | int callForwardingReason = args.first; |
| 957 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 958 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | } |
| 960 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 961 | ar = (AsyncResult) msg.obj; |
| 962 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 963 | TelephonyManager.CallForwardingInfoCallback callback = |
| 964 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 965 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 966 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 967 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 968 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 969 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 970 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 971 | // any service for voice call. |
| 972 | if ((callForwardInfo.serviceClass |
| 973 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | callForwardingInfo = new CallForwardingInfo(true, |
| 975 | callForwardInfo.reason, |
| 976 | callForwardInfo.number, |
| 977 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 978 | break; |
| 979 | } |
| 980 | } |
| 981 | // Didn't find a call forward info for voice call. |
| 982 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 983 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 984 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 985 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 986 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 987 | } else { |
| 988 | if (ar.result == null) { |
| 989 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 990 | } |
| 991 | if (ar.exception != null) { |
| 992 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 993 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 994 | int errorCode = TelephonyManager |
| 995 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 996 | if (ar.exception instanceof CommandException) { |
| 997 | CommandException.Error error = |
| 998 | ((CommandException) (ar.exception)).getCommandError(); |
| 999 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1000 | errorCode = TelephonyManager |
| 1001 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1003 | errorCode = TelephonyManager |
| 1004 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1005 | } |
| 1006 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1008 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1009 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1011 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1013 | request = (MainThreadRequest) msg.obj; |
| 1014 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1017 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1018 | request.argument).first; |
| 1019 | request.phone.setCallForwardingOption( |
| 1020 | callForwardingInfoToSet.isEnabled() |
| 1021 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1022 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | callForwardingInfoToSet.getReason(), |
| 1024 | callForwardingInfoToSet.getNumber(), |
| 1025 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1026 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1028 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1029 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1030 | ar = (AsyncResult) msg.obj; |
| 1031 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | Consumer<Integer> callback = |
| 1033 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1034 | request.argument).second; |
| 1035 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1036 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1037 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1038 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | if (ar.exception instanceof CommandException) { |
| 1040 | CommandException.Error error = |
| 1041 | ((CommandException) (ar.exception)).getCommandError(); |
| 1042 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1043 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1044 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1045 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1046 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1047 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | callback.accept(errorCode); |
| 1051 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1052 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1053 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1054 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1055 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1056 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | request = (MainThreadRequest) msg.obj; |
| 1059 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1060 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1061 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1062 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1063 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1065 | ar = (AsyncResult) msg.obj; |
| 1066 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1068 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1069 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1070 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1071 | // Service Class is a bit mask per 3gpp 27.007. |
| 1072 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1073 | if (callForwardResults.length > 1 |
| 1074 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1076 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1078 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1079 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } else { |
| 1083 | if (ar.result == null) { |
| 1084 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1085 | } |
| 1086 | if (ar.exception != null) { |
| 1087 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1088 | } |
| 1089 | if (ar.exception instanceof CommandException) { |
| 1090 | CommandException.Error error = |
| 1091 | ((CommandException) (ar.exception)).getCommandError(); |
| 1092 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1093 | callForwardingStatus = |
| 1094 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1095 | } |
| 1096 | } |
| 1097 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | callback.accept(callForwardingStatus); |
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 CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1103 | request = (MainThreadRequest) msg.obj; |
| 1104 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1106 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1107 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1111 | ar = (AsyncResult) msg.obj; |
| 1112 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1114 | Consumer<Integer> callback = |
| 1115 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1116 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1117 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1118 | if (ar.exception instanceof CommandException) { |
| 1119 | CommandException.Error error = |
| 1120 | ((CommandException) (ar.exception)).getCommandError(); |
| 1121 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1122 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1123 | } else { |
| 1124 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1125 | } |
| 1126 | } else { |
| 1127 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1128 | } |
| 1129 | } else { |
| 1130 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1131 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1132 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1133 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1135 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1136 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1137 | ar = (AsyncResult) msg.obj; |
| 1138 | request = (MainThreadRequest) ar.userObj; |
| 1139 | CellNetworkScanResult cellScanResult; |
| 1140 | if (ar.exception == null && ar.result != null) { |
| 1141 | cellScanResult = new CellNetworkScanResult( |
| 1142 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1143 | (List<OperatorInfo>) ar.result); |
| 1144 | } else { |
| 1145 | if (ar.result == null) { |
| 1146 | loge("getCellNetworkScanResults: Empty response"); |
| 1147 | } |
| 1148 | if (ar.exception != null) { |
| 1149 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1150 | } |
| 1151 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1152 | if (ar.exception instanceof CommandException) { |
| 1153 | CommandException.Error error = |
| 1154 | ((CommandException) (ar.exception)).getCommandError(); |
| 1155 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1156 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1157 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1158 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1159 | } |
| 1160 | } |
| 1161 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1162 | } |
| 1163 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1164 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1165 | break; |
| 1166 | |
| 1167 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1168 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1169 | ManualNetworkSelectionArgument selArg = |
| 1170 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1171 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1172 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1173 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1174 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1175 | break; |
| 1176 | |
| 1177 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1178 | ar = (AsyncResult) msg.obj; |
| 1179 | request = (MainThreadRequest) ar.userObj; |
| 1180 | if (ar.exception == null) { |
| 1181 | request.result = true; |
| 1182 | } else { |
| 1183 | request.result = false; |
| 1184 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1185 | } |
| 1186 | notifyRequester(request); |
| 1187 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1188 | break; |
| 1189 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1190 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1191 | request = (MainThreadRequest) msg.obj; |
| 1192 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1193 | if (defaultPhone != null) { |
| 1194 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1195 | } else { |
| 1196 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1197 | Bundle bundle = new Bundle(); |
| 1198 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1199 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1200 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1201 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1205 | ar = (AsyncResult) msg.obj; |
| 1206 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1207 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1208 | |
| 1209 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1210 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1211 | // Update the last modem activity info and the result of the request. |
| 1212 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1213 | if (isModemActivityInfoValid(info)) { |
| 1214 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1215 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1216 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1217 | .getTransmitTimeMillis(); |
| 1218 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1219 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1220 | } |
| 1221 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1222 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1223 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1224 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1225 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1226 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1227 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1228 | info.getReceiveTimeMillis() |
| 1229 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1230 | } |
| 1231 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1232 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1233 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1234 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1235 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1236 | } else { |
| 1237 | if (ar.result == null) { |
| 1238 | loge("queryModemActivityInfo: Empty response"); |
| 1239 | } else if (ar.exception instanceof CommandException) { |
| 1240 | loge("queryModemActivityInfo: CommandException: " + |
| 1241 | ar.exception); |
| 1242 | } else { |
| 1243 | loge("queryModemActivityInfo: Unknown exception"); |
| 1244 | } |
| 1245 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1246 | Bundle bundle = new Bundle(); |
| 1247 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1248 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1249 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1250 | break; |
| 1251 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1252 | case CMD_SET_ALLOWED_CARRIERS: |
| 1253 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1254 | CarrierRestrictionRules argument = |
| 1255 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1256 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1257 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1258 | break; |
| 1259 | |
| 1260 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
| 1263 | if (ar.exception == null && ar.result != null) { |
| 1264 | request.result = ar.result; |
| 1265 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1266 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1267 | if (ar.exception instanceof CommandException) { |
| 1268 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1269 | CommandException.Error error = |
| 1270 | ((CommandException) (ar.exception)).getCommandError(); |
| 1271 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1272 | request.result = |
| 1273 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1274 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1275 | } else { |
| 1276 | loge("setAllowedCarriers: Unknown exception"); |
| 1277 | } |
| 1278 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1279 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1280 | break; |
| 1281 | |
| 1282 | case CMD_GET_ALLOWED_CARRIERS: |
| 1283 | request = (MainThreadRequest) msg.obj; |
| 1284 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1285 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1286 | break; |
| 1287 | |
| 1288 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1289 | ar = (AsyncResult) msg.obj; |
| 1290 | request = (MainThreadRequest) ar.userObj; |
| 1291 | if (ar.exception == null && ar.result != null) { |
| 1292 | request.result = ar.result; |
| 1293 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1294 | request.result = new IllegalStateException( |
| 1295 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1296 | if (ar.result == null) { |
| 1297 | loge("getAllowedCarriers: Empty response"); |
| 1298 | } else if (ar.exception instanceof CommandException) { |
| 1299 | loge("getAllowedCarriers: CommandException: " + |
| 1300 | ar.exception); |
| 1301 | } else { |
| 1302 | loge("getAllowedCarriers: Unknown exception"); |
| 1303 | } |
| 1304 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1305 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1308 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1309 | ar = (AsyncResult) msg.obj; |
| 1310 | request = (MainThreadRequest) ar.userObj; |
| 1311 | if (ar.exception == null && ar.result != null) { |
| 1312 | request.result = ar.result; |
| 1313 | } else { |
| 1314 | request.result = new IllegalArgumentException( |
| 1315 | "Failed to retrieve Forbidden Plmns"); |
| 1316 | if (ar.result == null) { |
| 1317 | loge("getForbiddenPlmns: Empty response"); |
| 1318 | } else { |
| 1319 | loge("getForbiddenPlmns: Unknown exception"); |
| 1320 | } |
| 1321 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1322 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1323 | break; |
| 1324 | |
| 1325 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1326 | request = (MainThreadRequest) msg.obj; |
| 1327 | uiccCard = getUiccCardFromRequest(request); |
| 1328 | if (uiccCard == null) { |
| 1329 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1330 | request.result = new IllegalArgumentException( |
| 1331 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1332 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1333 | break; |
| 1334 | } |
| 1335 | Integer appType = (Integer) request.argument; |
| 1336 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1337 | if (uiccApp == null) { |
| 1338 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1339 | + appType); |
| 1340 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1341 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1342 | break; |
| 1343 | } else { |
| 1344 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1345 | + " specified type -- " + appType); |
| 1346 | } |
| 1347 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1348 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1349 | onCompleted); |
| 1350 | break; |
| 1351 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1352 | case CMD_SWITCH_SLOTS: |
| 1353 | request = (MainThreadRequest) msg.obj; |
| 1354 | int[] physicalSlots = (int[]) request.argument; |
| 1355 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1356 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1357 | break; |
| 1358 | |
| 1359 | case EVENT_SWITCH_SLOTS_DONE: |
| 1360 | ar = (AsyncResult) msg.obj; |
| 1361 | request = (MainThreadRequest) ar.userObj; |
| 1362 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1363 | notifyRequester(request); |
| 1364 | break; |
| 1365 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1366 | request = (MainThreadRequest) msg.obj; |
| 1367 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1368 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1369 | break; |
| 1370 | |
| 1371 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1372 | ar = (AsyncResult) msg.obj; |
| 1373 | request = (MainThreadRequest) ar.userObj; |
| 1374 | if (ar.exception != null) { |
| 1375 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1376 | } else { |
| 1377 | int mode = ((int[]) ar.result)[0]; |
| 1378 | if (mode == 0) { |
| 1379 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1380 | } else { |
| 1381 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1382 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1383 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1384 | notifyRequester(request); |
| 1385 | break; |
| 1386 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1387 | request = (MainThreadRequest) msg.obj; |
| 1388 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1389 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1390 | break; |
| 1391 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | if (ar.exception != null) { |
| 1395 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1396 | } else { |
| 1397 | request.result = ((int[]) ar.result)[0]; |
| 1398 | } |
| 1399 | notifyRequester(request); |
| 1400 | break; |
| 1401 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1402 | request = (MainThreadRequest) msg.obj; |
| 1403 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1404 | int mode = (int) request.argument; |
| 1405 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1406 | break; |
| 1407 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1408 | ar = (AsyncResult) msg.obj; |
| 1409 | request = (MainThreadRequest) ar.userObj; |
| 1410 | request.result = ar.exception == null; |
| 1411 | notifyRequester(request); |
| 1412 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1413 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1414 | request = (MainThreadRequest) msg.obj; |
| 1415 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1416 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1417 | break; |
| 1418 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | if (ar.exception != null) { |
| 1422 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1423 | } else { |
| 1424 | request.result = ((int[]) ar.result)[0]; |
| 1425 | } |
| 1426 | notifyRequester(request); |
| 1427 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1428 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1429 | request = (MainThreadRequest) msg.obj; |
| 1430 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1431 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1432 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1433 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1436 | ar = (AsyncResult) msg.obj; |
| 1437 | request = (MainThreadRequest) ar.userObj; |
| 1438 | request.result = ar.exception == null; |
| 1439 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1440 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1441 | case CMD_GET_ALL_CELL_INFO: |
| 1442 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1443 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1444 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1445 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1446 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1449 | // If a timeout occurs, the response will be null |
| 1450 | request.result = (ar.exception == null && ar.result != null) |
| 1451 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1452 | synchronized (request) { |
| 1453 | request.notifyAll(); |
| 1454 | } |
| 1455 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1456 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1457 | request = (MainThreadRequest) msg.obj; |
| 1458 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1459 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1460 | break; |
| 1461 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1462 | ar = (AsyncResult) msg.obj; |
| 1463 | request = (MainThreadRequest) ar.userObj; |
| 1464 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1465 | try { |
| 1466 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1467 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1468 | cb.onError( |
| 1469 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1470 | ar.exception.getClass().getName(), |
| 1471 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1472 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1473 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1474 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1475 | } else { |
| 1476 | // use the result as returned |
| 1477 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1478 | } |
| 1479 | } catch (RemoteException re) { |
| 1480 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1481 | } |
| 1482 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1483 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | request = (MainThreadRequest) msg.obj; |
| 1485 | WorkSource ws = (WorkSource) request.argument; |
| 1486 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1487 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1488 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1489 | } |
| 1490 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1491 | ar = (AsyncResult) msg.obj; |
| 1492 | request = (MainThreadRequest) ar.userObj; |
| 1493 | if (ar.exception == null) { |
| 1494 | request.result = ar.result; |
| 1495 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1496 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1497 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1498 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | synchronized (request) { |
| 1502 | request.notifyAll(); |
| 1503 | } |
| 1504 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1505 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1506 | case CMD_MODEM_REBOOT: |
| 1507 | request = (MainThreadRequest) msg.obj; |
| 1508 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1509 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1510 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1511 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1512 | handleNullReturnEvent(msg, "rebootModem"); |
| 1513 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1514 | case CMD_REQUEST_ENABLE_MODEM: |
| 1515 | request = (MainThreadRequest) msg.obj; |
| 1516 | boolean enable = (boolean) request.argument; |
| 1517 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1518 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1519 | PhoneConfigurationManager.getInstance() |
| 1520 | .enablePhone(request.phone, enable, onCompleted); |
| 1521 | break; |
| 1522 | case EVENT_ENABLE_MODEM_DONE: |
| 1523 | ar = (AsyncResult) msg.obj; |
| 1524 | request = (MainThreadRequest) ar.userObj; |
| 1525 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1526 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1527 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1528 | if ((boolean) request.result) { |
| 1529 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1530 | updateModemStateMetrics(); |
| 1531 | } else { |
| 1532 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1533 | + ar.exception); |
| 1534 | } |
| 1535 | notifyRequester(request); |
| 1536 | break; |
| 1537 | case CMD_GET_MODEM_STATUS: |
| 1538 | request = (MainThreadRequest) msg.obj; |
| 1539 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1540 | PhoneConfigurationManager.getInstance() |
| 1541 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1542 | break; |
| 1543 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1544 | ar = (AsyncResult) msg.obj; |
| 1545 | request = (MainThreadRequest) ar.userObj; |
| 1546 | int id = request.phone.getPhoneId(); |
| 1547 | if (ar.exception == null && ar.result != null) { |
| 1548 | request.result = ar.result; |
| 1549 | //update the cache as modem status has changed |
| 1550 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1551 | (boolean) request.result); |
| 1552 | } else { |
| 1553 | // Return true if modem status cannot be retrieved. For most cases, |
| 1554 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1555 | // and disable modem are not supported. Modem is always on. |
| 1556 | // TODO: this should be fixed in R to support a third |
| 1557 | // status UNKNOWN b/131631629 |
| 1558 | request.result = true; |
| 1559 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1560 | + ar.exception); |
| 1561 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1562 | notifyRequester(request); |
| 1563 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1564 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1565 | request = (MainThreadRequest) msg.obj; |
| 1566 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1567 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1568 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1569 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1570 | break; |
| 1571 | } |
| 1572 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1576 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1577 | args.second.accept(ar.exception == null); |
| 1578 | notifyRequester(request); |
| 1579 | break; |
| 1580 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1581 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1582 | request = (MainThreadRequest) msg.obj; |
| 1583 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1584 | Phone phone = getPhoneFromRequest(request); |
| 1585 | if (phone != null) { |
| 1586 | phone.getSystemSelectionChannels(onCompleted); |
| 1587 | } else { |
| 1588 | loge("getSystemSelectionChannels: No phone object"); |
| 1589 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1590 | notifyRequester(request); |
| 1591 | } |
| 1592 | break; |
| 1593 | } |
| 1594 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1595 | ar = (AsyncResult) msg.obj; |
| 1596 | request = (MainThreadRequest) ar.userObj; |
| 1597 | if (ar.exception == null && ar.result != null) { |
| 1598 | request.result = ar.result; |
| 1599 | } else { |
| 1600 | request.result = new IllegalArgumentException( |
| 1601 | "Failed to retrieve system selection channels"); |
| 1602 | if (ar.result == null) { |
| 1603 | loge("getSystemSelectionChannels: Empty response"); |
| 1604 | } else { |
| 1605 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1606 | } |
| 1607 | } |
| 1608 | notifyRequester(request); |
| 1609 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1610 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | if (ar.exception == null && ar.result != null) { |
| 1614 | request.result = ar.result; |
| 1615 | } else { |
| 1616 | request.result = -1; |
| 1617 | loge("Failed to set Forbidden Plmns"); |
| 1618 | if (ar.result == null) { |
| 1619 | loge("setForbidenPlmns: Empty response"); |
| 1620 | } else if (ar.exception != null) { |
| 1621 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1622 | request.result = -1; |
| 1623 | } else { |
| 1624 | loge("setForbiddenPlmns: Unknown exception"); |
| 1625 | } |
| 1626 | } |
| 1627 | notifyRequester(request); |
| 1628 | break; |
| 1629 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1630 | request = (MainThreadRequest) msg.obj; |
| 1631 | uiccCard = getUiccCardFromRequest(request); |
| 1632 | if (uiccCard == null) { |
| 1633 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1634 | request.result = -1; |
| 1635 | notifyRequester(request); |
| 1636 | break; |
| 1637 | } |
| 1638 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1639 | (Pair<Integer, List<String>>) request.argument; |
| 1640 | appType = setFplmnsArgs.first; |
| 1641 | List<String> fplmns = setFplmnsArgs.second; |
| 1642 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1643 | if (uiccApp == null) { |
| 1644 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1645 | request.result = -1; |
| 1646 | loge("Failed to get UICC App"); |
| 1647 | notifyRequester(request); |
| 1648 | } else { |
| 1649 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1650 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1651 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1652 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1653 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1654 | case CMD_ERASE_MODEM_CONFIG: |
| 1655 | request = (MainThreadRequest) msg.obj; |
| 1656 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1657 | defaultPhone.eraseModemConfig(onCompleted); |
| 1658 | break; |
| 1659 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1660 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1661 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1662 | |
| 1663 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1664 | request = (MainThreadRequest) msg.obj; |
| 1665 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1666 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1667 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1668 | changed.first, changed.second, onCompleted); |
| 1669 | break; |
| 1670 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1671 | ar = (AsyncResult) msg.obj; |
| 1672 | request = (MainThreadRequest) ar.userObj; |
| 1673 | if (ar.exception == null) { |
| 1674 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1675 | } else { |
| 1676 | request.result = msg.arg1; |
| 1677 | } |
| 1678 | notifyRequester(request); |
| 1679 | break; |
| 1680 | |
| 1681 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1682 | request = (MainThreadRequest) msg.obj; |
| 1683 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1684 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1685 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1686 | enabled.first, enabled.second, onCompleted); |
| 1687 | break; |
| 1688 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1689 | ar = (AsyncResult) msg.obj; |
| 1690 | request = (MainThreadRequest) ar.userObj; |
| 1691 | if (ar.exception == null) { |
| 1692 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1693 | } else { |
| 1694 | request.result = msg.arg1; |
| 1695 | } |
| 1696 | notifyRequester(request); |
| 1697 | break; |
| 1698 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1699 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1700 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1701 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1702 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1703 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1704 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1705 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1706 | |
| 1707 | case CMD_SET_DATA_THROTTLING: { |
| 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1710 | DataThrottlingRequest dataThrottlingRequest = |
| 1711 | (DataThrottlingRequest) request.argument; |
| 1712 | Phone phone = getPhoneFromRequest(request); |
| 1713 | if (phone != null) { |
| 1714 | phone.setDataThrottling(onCompleted, |
| 1715 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1716 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1717 | } else { |
| 1718 | loge("setDataThrottling: No phone object"); |
| 1719 | request.result = |
| 1720 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1721 | notifyRequester(request); |
| 1722 | } |
| 1723 | |
| 1724 | break; |
| 1725 | } |
| 1726 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1727 | ar = (AsyncResult) msg.obj; |
| 1728 | request = (MainThreadRequest) ar.userObj; |
| 1729 | |
| 1730 | if (ar.exception == null) { |
| 1731 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1732 | } else if (ar.exception instanceof CommandException) { |
| 1733 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1734 | CommandException.Error error = |
| 1735 | ((CommandException) (ar.exception)).getCommandError(); |
| 1736 | |
| 1737 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1738 | request.result = TelephonyManager |
| 1739 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1740 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1741 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1742 | } else { |
| 1743 | request.result = |
| 1744 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1745 | } |
| 1746 | } else { |
| 1747 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1748 | } |
| 1749 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1750 | notifyRequester(request); |
| 1751 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1752 | |
| 1753 | case CMD_SET_SIM_POWER: { |
| 1754 | request = (MainThreadRequest) msg.obj; |
| 1755 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | int stateToSet = |
| 1758 | ((Pair<Integer, IIntegerConsumer>) |
| 1759 | request.argument).first; |
| 1760 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1761 | break; |
| 1762 | } |
| 1763 | case EVENT_SET_SIM_POWER_DONE: { |
| 1764 | ar = (AsyncResult) msg.obj; |
| 1765 | request = (MainThreadRequest) ar.userObj; |
| 1766 | IIntegerConsumer callback = |
| 1767 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1768 | if (ar.exception != null) { |
| 1769 | loge("setSimPower exception: " + ar.exception); |
| 1770 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1771 | .RESULT_ERROR_UNKNOWN; |
| 1772 | if (ar.exception instanceof CommandException) { |
| 1773 | CommandException.Error error = |
| 1774 | ((CommandException) (ar.exception)).getCommandError(); |
| 1775 | if (error == CommandException.Error.SIM_ERR) { |
| 1776 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1777 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1778 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1779 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1780 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1781 | } else { |
| 1782 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1783 | } |
| 1784 | } |
| 1785 | try { |
| 1786 | callback.accept(errorCode); |
| 1787 | } catch (RemoteException e) { |
| 1788 | // Ignore if the remote process is no longer available to call back. |
| 1789 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1790 | } |
| 1791 | } else { |
| 1792 | try { |
| 1793 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1794 | } catch (RemoteException e) { |
| 1795 | // Ignore if the remote process is no longer available to call back. |
| 1796 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1797 | } |
| 1798 | } |
| 1799 | break; |
| 1800 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1801 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | |
| 1804 | final Phone phone = getPhoneFromRequest(request); |
| 1805 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1806 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1807 | notifyRequester(request); |
| 1808 | break; |
| 1809 | } |
| 1810 | |
| 1811 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1812 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1813 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1814 | request); |
| 1815 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1816 | request.subId, pair.first /*callingUid*/, |
| 1817 | pair.second /*request*/, onCompleted); |
| 1818 | break; |
| 1819 | } |
| 1820 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1821 | ar = (AsyncResult) msg.obj; |
| 1822 | request = (MainThreadRequest) ar.userObj; |
| 1823 | // request.result will be the exception of ar if present, true otherwise. |
| 1824 | // Be cautious not to leave result null which will wait() forever |
| 1825 | request.result = ar.exception != null ? ar.exception : true; |
| 1826 | notifyRequester(request); |
| 1827 | break; |
| 1828 | } |
| 1829 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | |
| 1832 | Phone phone = getPhoneFromRequest(request); |
| 1833 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1834 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1835 | notifyRequester(request); |
| 1836 | break; |
| 1837 | } |
| 1838 | |
| 1839 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1840 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1841 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1842 | request); |
| 1843 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1844 | request.subId, pair.first /*callingUid*/, |
| 1845 | pair.second /*request*/, onCompleted); |
| 1846 | break; |
| 1847 | } |
| 1848 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1849 | ar = (AsyncResult) msg.obj; |
| 1850 | request = (MainThreadRequest) ar.userObj; |
| 1851 | request.result = ar.exception != null ? ar.exception : true; |
| 1852 | notifyRequester(request); |
| 1853 | break; |
| 1854 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1855 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1856 | default: |
| 1857 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1858 | break; |
| 1859 | } |
| 1860 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1861 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1862 | private void notifyRequester(MainThreadRequest request) { |
| 1863 | synchronized (request) { |
| 1864 | request.notifyAll(); |
| 1865 | } |
| 1866 | } |
| 1867 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1868 | private void handleNullReturnEvent(Message msg, String command) { |
| 1869 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1870 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1871 | if (ar.exception == null) { |
| 1872 | request.result = true; |
| 1873 | } else { |
| 1874 | request.result = false; |
| 1875 | if (ar.exception instanceof CommandException) { |
| 1876 | loge(command + ": CommandException: " + ar.exception); |
| 1877 | } else { |
| 1878 | loge(command + ": Unknown exception"); |
| 1879 | } |
| 1880 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1881 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * Posts the specified command to be executed on the main thread, |
| 1887 | * waits for the request to complete, and returns the result. |
| 1888 | * @see #sendRequestAsync |
| 1889 | */ |
| 1890 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1891 | return sendRequest( |
| 1892 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * Posts the specified command to be executed on the main thread, |
| 1897 | * waits for the request to complete, and returns the result. |
| 1898 | * @see #sendRequestAsync |
| 1899 | */ |
| 1900 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1901 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1902 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
| 1905 | /** |
| 1906 | * Posts the specified command to be executed on the main thread, |
| 1907 | * waits for the request to complete, and returns the result. |
| 1908 | * @see #sendRequestAsync |
| 1909 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1910 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1911 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | /** |
| 1915 | * Posts the specified command to be executed on the main thread, |
| 1916 | * waits for the request to complete, and returns the result. |
| 1917 | * @see #sendRequestAsync |
| 1918 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1919 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1920 | return sendRequest(command, argument, subId, null, workSource); |
| 1921 | } |
| 1922 | |
| 1923 | /** |
| 1924 | * Posts the specified command to be executed on the main thread, |
| 1925 | * waits for the request to complete, and returns the result. |
| 1926 | * @see #sendRequestAsync |
| 1927 | */ |
| 1928 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1929 | return sendRequest( |
| 1930 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1931 | } |
| 1932 | |
| 1933 | /** |
| 1934 | * Posts the specified command to be executed on the main thread, |
| 1935 | * waits for the request to complete, and returns the result. |
| 1936 | * @see #sendRequestAsync |
| 1937 | */ |
| 1938 | private Object sendRequest( |
| 1939 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1940 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1941 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1942 | } |
| 1943 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1944 | MainThreadRequest request = null; |
| 1945 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1946 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1947 | } else if (phone != null) { |
| 1948 | request = new MainThreadRequest(argument, phone, workSource); |
| 1949 | } else { |
| 1950 | request = new MainThreadRequest(argument, subId, workSource); |
| 1951 | } |
| 1952 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1954 | msg.sendToTarget(); |
| 1955 | |
| 1956 | // Wait for the request to complete |
| 1957 | synchronized (request) { |
| 1958 | while (request.result == null) { |
| 1959 | try { |
| 1960 | request.wait(); |
| 1961 | } catch (InterruptedException e) { |
| 1962 | // Do nothing, go back and wait until the request is complete |
| 1963 | } |
| 1964 | } |
| 1965 | } |
| 1966 | return request.result; |
| 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1971 | * Posts the specified command to be executed on the main thread, and |
| 1972 | * returns immediately. |
| 1973 | * @see #sendRequest |
| 1974 | */ |
| 1975 | private void sendRequestAsync(int command) { |
| 1976 | mMainThreadHandler.sendEmptyMessage(command); |
| 1977 | } |
| 1978 | |
| 1979 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1980 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1981 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1982 | */ |
| 1983 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1984 | sendRequestAsync(command, argument, null, null); |
| 1985 | } |
| 1986 | |
| 1987 | /** |
| 1988 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1989 | * @see {@link #sendRequest(int,Object)} |
| 1990 | */ |
| 1991 | private void sendRequestAsync( |
| 1992 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1993 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1994 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1995 | msg.sendToTarget(); |
| 1996 | } |
| 1997 | |
| 1998 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2000 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2001 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2002 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2003 | synchronized (PhoneInterfaceManager.class) { |
| 2004 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2005 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2006 | } else { |
| 2007 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2008 | } |
| 2009 | return sInstance; |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2014 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2017 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2018 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2019 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2020 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2021 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2022 | mTelephonySharedPreferences = |
| 2023 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2024 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2025 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2026 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2027 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2028 | publish(); |
| 2029 | } |
| 2030 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2031 | private Phone getDefaultPhone() { |
| 2032 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2033 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2034 | } |
| 2035 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2036 | private void publish() { |
| 2037 | if (DBG) log("publish: " + this); |
| 2038 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2039 | TelephonyFrameworkInitializer |
| 2040 | .getTelephonyServiceManager() |
| 2041 | .getTelephonyServiceRegisterer() |
| 2042 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2045 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2046 | if (request.phone != null) { |
| 2047 | return request.phone; |
| 2048 | } else { |
| 2049 | return getPhoneFromSubId(request.subId); |
| 2050 | } |
| 2051 | } |
| 2052 | |
| 2053 | private Phone getPhoneFromSubId(int subId) { |
| 2054 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2055 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2056 | } |
| 2057 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2058 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2059 | Phone phone = getPhoneFromRequest(request); |
| 2060 | return phone == null ? null : |
| 2061 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2062 | } |
| 2063 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2064 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2065 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2066 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2067 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2068 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2069 | private void sendEraseModemConfig(Phone phone) { |
| 2070 | if (phone != null) { |
| 2071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2072 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2073 | final long identity = Binder.clearCallingIdentity(); |
| 2074 | try { |
| 2075 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2076 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2077 | } finally { |
| 2078 | Binder.restoreCallingIdentity(identity); |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2083 | private boolean isImsAvailableOnDevice() { |
| 2084 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2085 | if (pm == null) { |
| 2086 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2087 | // so do not throw error and allow. |
| 2088 | return true; |
| 2089 | } |
| 2090 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2091 | } |
| 2092 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2094 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2097 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | if (DBG) log("dial: " + number); |
| 2099 | // No permission check needed here: This is just a wrapper around the |
| 2100 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2101 | // the UI before it does anything. |
| 2102 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2103 | final long identity = Binder.clearCallingIdentity(); |
| 2104 | try { |
| 2105 | String url = createTelUrl(number); |
| 2106 | if (url == null) { |
| 2107 | return; |
| 2108 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2109 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2110 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2111 | PhoneConstants.State state = mCM.getState(subId); |
| 2112 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2113 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2114 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2115 | mApp.startActivity(intent); |
| 2116 | } |
| 2117 | } finally { |
| 2118 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2123 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2126 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2127 | if (DBG) log("call: " + number); |
| 2128 | |
| 2129 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2130 | // need to do a permission check since we're calling startActivity() |
| 2131 | // from the context of the phone app. |
| 2132 | enforceCallPermission(); |
| 2133 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2134 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | != AppOpsManager.MODE_ALLOWED) { |
| 2136 | return; |
| 2137 | } |
| 2138 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | final long identity = Binder.clearCallingIdentity(); |
| 2140 | try { |
| 2141 | String url = createTelUrl(number); |
| 2142 | if (url == null) { |
| 2143 | return; |
| 2144 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2145 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2146 | boolean isValid = false; |
| 2147 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2148 | if (slist != null) { |
| 2149 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2150 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2151 | isValid = true; |
| 2152 | break; |
| 2153 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2154 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | if (!isValid) { |
| 2157 | return; |
| 2158 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2159 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2160 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2161 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2162 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2163 | mApp.startActivity(intent); |
| 2164 | } finally { |
| 2165 | Binder.restoreCallingIdentity(identity); |
| 2166 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2169 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2170 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2171 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2172 | } |
| 2173 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2174 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2175 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2176 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2177 | } |
| 2178 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2179 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2180 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2181 | |
| 2182 | final long identity = Binder.clearCallingIdentity(); |
| 2183 | try { |
| 2184 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2185 | checkSimPin.start(); |
| 2186 | return checkSimPin.unlockSim(null, pin); |
| 2187 | } finally { |
| 2188 | Binder.restoreCallingIdentity(identity); |
| 2189 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2192 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2193 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | |
| 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2198 | checkSimPuk.start(); |
| 2199 | return checkSimPuk.unlockSim(puk, pin); |
| 2200 | } finally { |
| 2201 | Binder.restoreCallingIdentity(identity); |
| 2202 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2206 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | * a synchronous one. |
| 2208 | */ |
| 2209 | private static class UnlockSim extends Thread { |
| 2210 | |
| 2211 | private final IccCard mSimCard; |
| 2212 | |
| 2213 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2214 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2215 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | |
| 2217 | // For replies from SimCard interface |
| 2218 | private Handler mHandler; |
| 2219 | |
| 2220 | // For async handler to identify request type |
| 2221 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2222 | |
| 2223 | public UnlockSim(IccCard simCard) { |
| 2224 | mSimCard = simCard; |
| 2225 | } |
| 2226 | |
| 2227 | @Override |
| 2228 | public void run() { |
| 2229 | Looper.prepare(); |
| 2230 | synchronized (UnlockSim.this) { |
| 2231 | mHandler = new Handler() { |
| 2232 | @Override |
| 2233 | public void handleMessage(Message msg) { |
| 2234 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2235 | switch (msg.what) { |
| 2236 | case SUPPLY_PIN_COMPLETE: |
| 2237 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2238 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2239 | mRetryCount = msg.arg1; |
| 2240 | if (ar.exception != null) { |
| 2241 | if (ar.exception instanceof CommandException && |
| 2242 | ((CommandException)(ar.exception)).getCommandError() |
| 2243 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2244 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2245 | } //When UiccCardApp dispose,handle message and return exception |
| 2246 | else if (ar.exception instanceof CommandException && |
| 2247 | ((CommandException) (ar.exception)).getCommandError() |
| 2248 | == CommandException.Error.ABORTED) { |
| 2249 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2250 | } else { |
| 2251 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2252 | } |
| 2253 | } else { |
| 2254 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | mDone = true; |
| 2257 | UnlockSim.this.notifyAll(); |
| 2258 | } |
| 2259 | break; |
| 2260 | } |
| 2261 | } |
| 2262 | }; |
| 2263 | UnlockSim.this.notifyAll(); |
| 2264 | } |
| 2265 | Looper.loop(); |
| 2266 | } |
| 2267 | |
| 2268 | /* |
| 2269 | * Use PIN or PUK to unlock SIM card |
| 2270 | * |
| 2271 | * If PUK is null, unlock SIM card with PIN |
| 2272 | * |
| 2273 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2274 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2275 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | |
| 2277 | while (mHandler == null) { |
| 2278 | try { |
| 2279 | wait(); |
| 2280 | } catch (InterruptedException e) { |
| 2281 | Thread.currentThread().interrupt(); |
| 2282 | } |
| 2283 | } |
| 2284 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2285 | |
| 2286 | if (puk == null) { |
| 2287 | mSimCard.supplyPin(pin, callback); |
| 2288 | } else { |
| 2289 | mSimCard.supplyPuk(puk, pin, callback); |
| 2290 | } |
| 2291 | |
| 2292 | while (!mDone) { |
| 2293 | try { |
| 2294 | Log.d(LOG_TAG, "wait for done"); |
| 2295 | wait(); |
| 2296 | } catch (InterruptedException e) { |
| 2297 | // Restore the interrupted status |
| 2298 | Thread.currentThread().interrupt(); |
| 2299 | } |
| 2300 | } |
| 2301 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2302 | int[] resultArray = new int[2]; |
| 2303 | resultArray[0] = mResult; |
| 2304 | resultArray[1] = mRetryCount; |
| 2305 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | } |
| 2307 | } |
| 2308 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2309 | /** |
| 2310 | * This method has been removed due to privacy and stability concerns. |
| 2311 | */ |
| 2312 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2314 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2315 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2318 | @Override |
| 2319 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2320 | mApp.getSystemService(AppOpsManager.class) |
| 2321 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2322 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2323 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2324 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2325 | // Callers targeting S have no business invoking this method. |
| 2326 | return; |
| 2327 | } |
| 2328 | |
| 2329 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2330 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2331 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2332 | .setCallingPackage(callingPackage) |
| 2333 | .setCallingFeatureId(null) |
| 2334 | .setCallingPid(Binder.getCallingPid()) |
| 2335 | .setCallingUid(Binder.getCallingUid()) |
| 2336 | .setMethod("updateServiceLocation") |
| 2337 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2338 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2339 | .build()); |
| 2340 | // Apps that lack location permission have no business calling this method; |
| 2341 | // however, because no permission was declared in the public API, denials must |
| 2342 | // all be "soft". |
| 2343 | switch (locationResult) { |
| 2344 | case DENIED_HARD: /* fall through */ |
| 2345 | case DENIED_SOFT: |
| 2346 | return; |
| 2347 | } |
| 2348 | |
| 2349 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | final long identity = Binder.clearCallingIdentity(); |
| 2351 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2352 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2353 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2354 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2355 | } |
| 2356 | } finally { |
| 2357 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2361 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2362 | @Override |
| 2363 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2364 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2367 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2368 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2369 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2370 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2371 | callingFeatureId); |
| 2372 | } |
| 2373 | |
| 2374 | @Deprecated |
| 2375 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2376 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2377 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2378 | } |
| 2379 | |
| 2380 | @Override |
| 2381 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2382 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2384 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2385 | return false; |
| 2386 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2387 | |
| 2388 | final long identity = Binder.clearCallingIdentity(); |
| 2389 | try { |
| 2390 | return isRadioOnForSubscriber(subId); |
| 2391 | } finally { |
| 2392 | Binder.restoreCallingIdentity(identity); |
| 2393 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2397 | final long identity = Binder.clearCallingIdentity(); |
| 2398 | try { |
| 2399 | final Phone phone = getPhone(subId); |
| 2400 | if (phone != null) { |
| 2401 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2402 | } else { |
| 2403 | return false; |
| 2404 | } |
| 2405 | } finally { |
| 2406 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2411 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2413 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2414 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2415 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | |
| 2417 | final long identity = Binder.clearCallingIdentity(); |
| 2418 | try { |
| 2419 | final Phone phone = getPhone(subId); |
| 2420 | if (phone != null) { |
| 2421 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2422 | } |
| 2423 | } finally { |
| 2424 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2425 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2429 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2432 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2433 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2434 | |
| 2435 | final long identity = Binder.clearCallingIdentity(); |
| 2436 | try { |
| 2437 | final Phone phone = getPhone(subId); |
| 2438 | if (phone == null) { |
| 2439 | return false; |
| 2440 | } |
| 2441 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2442 | toggleRadioOnOffForSubscriber(subId); |
| 2443 | } |
| 2444 | return true; |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2449 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2450 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2451 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2452 | /* |
| 2453 | * If any of the Radios are available, it will need to be |
| 2454 | * shutdown. So return true if any Radio is available. |
| 2455 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2456 | final long identity = Binder.clearCallingIdentity(); |
| 2457 | try { |
| 2458 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2459 | Phone phone = PhoneFactory.getPhone(i); |
| 2460 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2461 | } |
| 2462 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2463 | return false; |
| 2464 | } finally { |
| 2465 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2466 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2470 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2471 | enforceModifyPermission(); |
| 2472 | |
| 2473 | final long identity = Binder.clearCallingIdentity(); |
| 2474 | try { |
| 2475 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2476 | logv("Shutting down Phone " + i); |
| 2477 | shutdownRadioUsingPhoneId(i); |
| 2478 | } |
| 2479 | } finally { |
| 2480 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2485 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2486 | if (phone != null && phone.isRadioAvailable()) { |
| 2487 | phone.shutdownRadio(); |
| 2488 | } |
| 2489 | } |
| 2490 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2492 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | |
| 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
| 2496 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2497 | if (defaultPhone != null) { |
| 2498 | defaultPhone.setRadioPower(turnOn); |
| 2499 | return true; |
| 2500 | } else { |
| 2501 | loge("There's no default phone."); |
| 2502 | return false; |
| 2503 | } |
| 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2506 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2509 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | final Phone phone = getPhone(subId); |
| 2515 | if (phone != null) { |
| 2516 | phone.setRadioPower(turnOn); |
| 2517 | return true; |
| 2518 | } else { |
| 2519 | return false; |
| 2520 | } |
| 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2526 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2527 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | public boolean enableDataConnectivity() { |
| 2529 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | |
| 2531 | final long identity = Binder.clearCallingIdentity(); |
| 2532 | try { |
| 2533 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2534 | final Phone phone = getPhone(subId); |
| 2535 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2536 | phone.getDataEnabledSettings().setDataEnabled( |
| 2537 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2538 | return true; |
| 2539 | } else { |
| 2540 | return false; |
| 2541 | } |
| 2542 | } finally { |
| 2543 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2547 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2548 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2549 | public boolean disableDataConnectivity() { |
| 2550 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 | |
| 2552 | final long identity = Binder.clearCallingIdentity(); |
| 2553 | try { |
| 2554 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2555 | final Phone phone = getPhone(subId); |
| 2556 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2557 | phone.getDataEnabledSettings().setDataEnabled( |
| 2558 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | return true; |
| 2560 | } else { |
| 2561 | return false; |
| 2562 | } |
| 2563 | } finally { |
| 2564 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2565 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2568 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2569 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | final Phone phone = getPhone(subId); |
| 2573 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2574 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2575 | } else { |
| 2576 | return false; |
| 2577 | } |
| 2578 | } finally { |
| 2579 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2580 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2584 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2587 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | enforceCallPermission(); |
| 2589 | |
| 2590 | final long identity = Binder.clearCallingIdentity(); |
| 2591 | try { |
| 2592 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2593 | return; |
| 2594 | } |
| 2595 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2596 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2597 | } finally { |
| 2598 | Binder.restoreCallingIdentity(identity); |
| 2599 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2600 | }; |
| 2601 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2602 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2604 | |
| 2605 | final long identity = Binder.clearCallingIdentity(); |
| 2606 | try { |
| 2607 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2608 | return false; |
| 2609 | } |
| 2610 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2611 | } finally { |
| 2612 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2613 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | } |
| 2615 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2617 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2620 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | final long identity = Binder.clearCallingIdentity(); |
| 2622 | try { |
| 2623 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2624 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2625 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2626 | } finally { |
| 2627 | Binder.restoreCallingIdentity(identity); |
| 2628 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | } |
| 2630 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2631 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2632 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2633 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2634 | } |
| 2635 | |
| 2636 | @Override |
| 2637 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2638 | final long identity = Binder.clearCallingIdentity(); |
| 2639 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2640 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | if (phone != null) { |
| 2642 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2643 | } else { |
| 2644 | return PhoneConstantConversions.convertDataState( |
| 2645 | PhoneConstants.DataState.DISCONNECTED); |
| 2646 | } |
| 2647 | } finally { |
| 2648 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2652 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2653 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2654 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2655 | } |
| 2656 | |
| 2657 | @Override |
| 2658 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2661 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | if (phone != null) { |
| 2663 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2664 | } else { |
| 2665 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2666 | } |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2673 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2674 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2675 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2676 | |
| 2677 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2678 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2679 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2680 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2681 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2682 | .setCallingPid(Binder.getCallingPid()) |
| 2683 | .setCallingUid(Binder.getCallingUid()) |
| 2684 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2685 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2686 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2687 | .build()); |
| 2688 | switch (locationResult) { |
| 2689 | case DENIED_HARD: |
| 2690 | throw new SecurityException("Not allowed to access cell location"); |
| 2691 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2692 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2693 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2696 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2700 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2701 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2702 | } finally { |
| 2703 | Binder.restoreCallingIdentity(identity); |
| 2704 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2707 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2708 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2709 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2710 | // registered cell info, so return a NULL country instead. |
| 2711 | final long identity = Binder.clearCallingIdentity(); |
| 2712 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2713 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2714 | // Get default phone in this case. |
| 2715 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2716 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2717 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2719 | if (phone == null) return ""; |
| 2720 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2721 | if (sst == null) return ""; |
| 2722 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2723 | if (lt == null) return ""; |
| 2724 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2725 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2726 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(identity); |
| 2729 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2732 | /** |
| 2733 | * This method was removed due to potential issues caused by performing partial |
| 2734 | * updates of service state, and lack of a credible use case. |
| 2735 | * |
| 2736 | * This has the ability to break the telephony implementation by disabling notification of |
| 2737 | * changes in device connectivity. DO NOT USE THIS! |
| 2738 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2739 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | public void enableLocationUpdates() { |
| 2741 | mApp.enforceCallingOrSelfPermission( |
| 2742 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2745 | /** |
| 2746 | * This method was removed due to potential issues caused by performing partial |
| 2747 | * updates of service state, and lack of a credible use case. |
| 2748 | * |
| 2749 | * This has the ability to break the telephony implementation by disabling notification of |
| 2750 | * changes in device connectivity. DO NOT USE THIS! |
| 2751 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2752 | @Override |
| 2753 | public void disableLocationUpdates() { |
| 2754 | mApp.enforceCallingOrSelfPermission( |
| 2755 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | @Override |
| 2759 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2760 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2761 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2762 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2763 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2764 | throw new SecurityException( |
| 2765 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2766 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2767 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2768 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2770 | return null; |
| 2771 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2772 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2773 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2774 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2775 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2776 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2778 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2779 | for (CellInfo ci : info) { |
| 2780 | if (ci instanceof CellInfoGsm) { |
| 2781 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2782 | } else if (ci instanceof CellInfoWcdma) { |
| 2783 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2784 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2785 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2786 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2787 | } |
| 2788 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2789 | private List<CellInfo> getCachedCellInfo() { |
| 2790 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2791 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2792 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2793 | if (info != null) cellInfos.addAll(info); |
| 2794 | } |
| 2795 | return cellInfos; |
| 2796 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2797 | |
| 2798 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2799 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2800 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2801 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2802 | |
| 2803 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2804 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2805 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2806 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2807 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2808 | .setCallingPid(Binder.getCallingPid()) |
| 2809 | .setCallingUid(Binder.getCallingUid()) |
| 2810 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2811 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2812 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2813 | .build()); |
| 2814 | switch (locationResult) { |
| 2815 | case DENIED_HARD: |
| 2816 | throw new SecurityException("Not allowed to access cell info"); |
| 2817 | case DENIED_SOFT: |
| 2818 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2821 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2822 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2823 | return getCachedCellInfo(); |
| 2824 | } |
| 2825 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2826 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2827 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2831 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2832 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2833 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | if (info != null) cellInfos.addAll(info); |
| 2835 | } |
| 2836 | return cellInfos; |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2839 | } |
| 2840 | } |
| 2841 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2842 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2843 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2844 | String callingFeatureId) { |
| 2845 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2846 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2847 | } |
| 2848 | |
| 2849 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2850 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2851 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2852 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2853 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2856 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2857 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2858 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2859 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2860 | |
| 2861 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2862 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2863 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2864 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2865 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2866 | .setCallingPid(Binder.getCallingPid()) |
| 2867 | .setCallingUid(Binder.getCallingUid()) |
| 2868 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2869 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2870 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2871 | .build()); |
| 2872 | switch (locationResult) { |
| 2873 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2874 | if (TelephonyPermissions |
| 2875 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2876 | // Safetynet logging for b/154934934 |
| 2877 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2878 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2879 | throw new SecurityException("Not allowed to access cell info"); |
| 2880 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2881 | if (TelephonyPermissions |
| 2882 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2883 | // Safetynet logging for b/154934934 |
| 2884 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2885 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2886 | try { |
| 2887 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2888 | } catch (RemoteException re) { |
| 2889 | // Drop without consequences |
| 2890 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2891 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2894 | |
| 2895 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2896 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2897 | |
| 2898 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2899 | } |
| 2900 | |
| 2901 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2902 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2903 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2904 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2905 | |
| 2906 | final long identity = Binder.clearCallingIdentity(); |
| 2907 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2908 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
| 2911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2914 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2915 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2916 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2917 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2918 | return null; |
| 2919 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2920 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2921 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2922 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2923 | return null; |
| 2924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2925 | |
| 2926 | final long identity = Binder.clearCallingIdentity(); |
| 2927 | try { |
| 2928 | return phone.getImei(); |
| 2929 | } finally { |
| 2930 | Binder.restoreCallingIdentity(identity); |
| 2931 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2935 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2936 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2937 | String tac = null; |
| 2938 | if (phone != null) { |
| 2939 | String imei = phone.getImei(); |
| 2940 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2941 | } |
| 2942 | return tac; |
| 2943 | } |
| 2944 | |
| 2945 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2946 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2947 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2948 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2949 | return null; |
| 2950 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2951 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2952 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2953 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2954 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2955 | return null; |
| 2956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | |
| 2958 | final long identity = Binder.clearCallingIdentity(); |
| 2959 | try { |
| 2960 | return phone.getMeid(); |
| 2961 | } finally { |
| 2962 | Binder.restoreCallingIdentity(identity); |
| 2963 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2967 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2968 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2969 | String manufacturerCode = null; |
| 2970 | if (phone != null) { |
| 2971 | String meid = phone.getMeid(); |
| 2972 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2973 | } |
| 2974 | return manufacturerCode; |
| 2975 | } |
| 2976 | |
| 2977 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2978 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2979 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2980 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2981 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2982 | return null; |
| 2983 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2984 | int subId = phone.getSubId(); |
| 2985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2986 | mApp, subId, callingPackage, callingFeatureId, |
| 2987 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2988 | return null; |
| 2989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | |
| 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | return phone.getDeviceSvn(); |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
| 2996 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2999 | @Override |
| 3000 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | final long identity = Binder.clearCallingIdentity(); |
| 3002 | try { |
| 3003 | final Phone phone = getPhone(subId); |
| 3004 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | @Override |
| 3011 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
| 3014 | final Phone phone = getPhone(subId); |
| 3015 | return phone == null ? null : phone.getCarrierName(); |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3019 | } |
| 3020 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3021 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3022 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3023 | final long identity = Binder.clearCallingIdentity(); |
| 3024 | try { |
| 3025 | final Phone phone = getPhone(subId); |
| 3026 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3027 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
| 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3034 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3035 | final long identity = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3038 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3039 | } finally { |
| 3040 | Binder.restoreCallingIdentity(identity); |
| 3041 | } |
| 3042 | } |
| 3043 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3044 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3045 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3046 | if (!isSubscriptionMccMnc) { |
| 3047 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3048 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3049 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3050 | if (phone == null) { |
| 3051 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3052 | } |
| 3053 | final long identity = Binder.clearCallingIdentity(); |
| 3054 | try { |
| 3055 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
| 3059 | } |
| 3060 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | // |
| 3062 | // Internal helper methods. |
| 3063 | // |
| 3064 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3065 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3066 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3067 | * |
| 3068 | * @throws SecurityException if the caller does not have the required permission |
| 3069 | */ |
| 3070 | private void enforceModifyPermission() { |
| 3071 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3072 | } |
| 3073 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3074 | /** |
| 3075 | * Make sure the caller is system. |
| 3076 | * |
| 3077 | * @throws SecurityException if the caller is not system. |
| 3078 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3079 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3080 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3081 | throw new SecurityException("Caller must be system"); |
| 3082 | } |
| 3083 | } |
| 3084 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3085 | private void enforceActiveEmergencySessionPermission() { |
| 3086 | mApp.enforceCallingOrSelfPermission( |
| 3087 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3088 | } |
| 3089 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3090 | /** |
| 3091 | * Make sure the caller has the CALL_PHONE permission. |
| 3092 | * |
| 3093 | * @throws SecurityException if the caller does not have the required permission |
| 3094 | */ |
| 3095 | private void enforceCallPermission() { |
| 3096 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3097 | } |
| 3098 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3099 | private void enforceSettingsPermission() { |
| 3100 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3103 | private String createTelUrl(String number) { |
| 3104 | if (TextUtils.isEmpty(number)) { |
| 3105 | return null; |
| 3106 | } |
| 3107 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3108 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3109 | } |
| 3110 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3111 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3112 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3113 | } |
| 3114 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3115 | private static void logv(String msg) { |
| 3116 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3117 | } |
| 3118 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3119 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3120 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3121 | } |
| 3122 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3123 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3124 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3125 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3128 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3129 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
| 3132 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3133 | if (phone == null) { |
| 3134 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3135 | } else { |
| 3136 | return phone.getPhoneType(); |
| 3137 | } |
| 3138 | } finally { |
| 3139 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3140 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | /** |
| 3144 | * Returns the CDMA ERI icon index to display |
| 3145 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3146 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3147 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3148 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3149 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3152 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3153 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3154 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3155 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3156 | mApp, subId, callingPackage, callingFeatureId, |
| 3157 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3158 | return -1; |
| 3159 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3160 | |
| 3161 | final long identity = Binder.clearCallingIdentity(); |
| 3162 | try { |
| 3163 | final Phone phone = getPhone(subId); |
| 3164 | if (phone != null) { |
| 3165 | return phone.getCdmaEriIconIndex(); |
| 3166 | } else { |
| 3167 | return -1; |
| 3168 | } |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | /** |
| 3175 | * Returns the CDMA ERI icon mode, |
| 3176 | * 0 - ON |
| 3177 | * 1 - FLASHING |
| 3178 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3179 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3180 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3181 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3182 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3183 | } |
| 3184 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3185 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3186 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3187 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3189 | mApp, subId, callingPackage, callingFeatureId, |
| 3190 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3191 | return -1; |
| 3192 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3193 | |
| 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | final Phone phone = getPhone(subId); |
| 3197 | if (phone != null) { |
| 3198 | return phone.getCdmaEriIconMode(); |
| 3199 | } else { |
| 3200 | return -1; |
| 3201 | } |
| 3202 | } finally { |
| 3203 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3204 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | /** |
| 3208 | * Returns the CDMA ERI text, |
| 3209 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3210 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3211 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3212 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3213 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3216 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3217 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3218 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3219 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3220 | mApp, subId, callingPackage, callingFeatureId, |
| 3221 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3222 | return null; |
| 3223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3224 | |
| 3225 | final long identity = Binder.clearCallingIdentity(); |
| 3226 | try { |
| 3227 | final Phone phone = getPhone(subId); |
| 3228 | if (phone != null) { |
| 3229 | return phone.getCdmaEriText(); |
| 3230 | } else { |
| 3231 | return null; |
| 3232 | } |
| 3233 | } finally { |
| 3234 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3235 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | } |
| 3237 | |
| 3238 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3239 | * Returns the CDMA MDN. |
| 3240 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3241 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3242 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3243 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3244 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3245 | |
| 3246 | final long identity = Binder.clearCallingIdentity(); |
| 3247 | try { |
| 3248 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3249 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | return phone.getLine1Number(); |
| 3251 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3252 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | return null; |
| 3254 | } |
| 3255 | } finally { |
| 3256 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3257 | } |
| 3258 | } |
| 3259 | |
| 3260 | /** |
| 3261 | * Returns the CDMA MIN. |
| 3262 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3263 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3264 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3266 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | |
| 3268 | final long identity = Binder.clearCallingIdentity(); |
| 3269 | try { |
| 3270 | final Phone phone = getPhone(subId); |
| 3271 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3272 | return phone.getCdmaMin(); |
| 3273 | } else { |
| 3274 | return null; |
| 3275 | } |
| 3276 | } finally { |
| 3277 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3278 | } |
| 3279 | } |
| 3280 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3281 | @Override |
| 3282 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3283 | INumberVerificationCallback callback, String callingPackage) { |
| 3284 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3285 | != PERMISSION_GRANTED) { |
| 3286 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3287 | } |
| 3288 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3289 | |
| 3290 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3291 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3292 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3293 | + "calling package: " + callingPackage |
| 3294 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | if (range == null) { |
| 3298 | throw new NullPointerException("Range must be non-null"); |
| 3299 | } |
| 3300 | |
| 3301 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3302 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3303 | |
| 3304 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3305 | } |
| 3306 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3307 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | * Returns true if CDMA provisioning needs to run. |
| 3309 | */ |
| 3310 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | final long identity = Binder.clearCallingIdentity(); |
| 3312 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3313 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
| 3316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3320 | * Sets the voice mail number of a given subId. |
| 3321 | */ |
| 3322 | @Override |
| 3323 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3324 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3325 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | |
| 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3330 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3331 | return success; |
| 3332 | } finally { |
| 3333 | Binder.restoreCallingIdentity(identity); |
| 3334 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3335 | } |
| 3336 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3337 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3338 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3339 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3340 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3341 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3342 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3343 | throw new SecurityException("caller must be system dialer"); |
| 3344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3345 | |
| 3346 | final long identity = Binder.clearCallingIdentity(); |
| 3347 | try { |
| 3348 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3349 | if (phoneAccountHandle == null) { |
| 3350 | return null; |
| 3351 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3352 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3353 | } finally { |
| 3354 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3355 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3359 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3360 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3361 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3362 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3363 | mApp, subId, callingPackage, callingFeatureId, |
| 3364 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3365 | return null; |
| 3366 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3368 | final long identity = Binder.clearCallingIdentity(); |
| 3369 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3370 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
| 3373 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3377 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3378 | VisualVoicemailSmsFilterSettings settings) { |
| 3379 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | |
| 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3384 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3385 | } finally { |
| 3386 | Binder.restoreCallingIdentity(identity); |
| 3387 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3391 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3393 | |
| 3394 | final long identity = Binder.clearCallingIdentity(); |
| 3395 | try { |
| 3396 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3397 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3404 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3405 | String callingPackage, int subId) { |
| 3406 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3411 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(identity); |
| 3414 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3418 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3419 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3424 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | } finally { |
| 3426 | Binder.restoreCallingIdentity(identity); |
| 3427 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3431 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3432 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3433 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3434 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3435 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3436 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3437 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3438 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3439 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3440 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3441 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3442 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3443 | * Sets the voice activation state of a given subId. |
| 3444 | */ |
| 3445 | @Override |
| 3446 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3448 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3449 | |
| 3450 | final long identity = Binder.clearCallingIdentity(); |
| 3451 | try { |
| 3452 | final Phone phone = getPhone(subId); |
| 3453 | if (phone != null) { |
| 3454 | phone.setVoiceActivationState(activationState); |
| 3455 | } else { |
| 3456 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3457 | } |
| 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | /** |
| 3464 | * Sets the data activation state of a given subId. |
| 3465 | */ |
| 3466 | @Override |
| 3467 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3469 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | |
| 3471 | final long identity = Binder.clearCallingIdentity(); |
| 3472 | try { |
| 3473 | final Phone phone = getPhone(subId); |
| 3474 | if (phone != null) { |
| 3475 | phone.setDataActivationState(activationState); |
| 3476 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3477 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | } |
| 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | /** |
| 3485 | * Returns the voice activation state of a given subId. |
| 3486 | */ |
| 3487 | @Override |
| 3488 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3489 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3491 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | final long identity = Binder.clearCallingIdentity(); |
| 3493 | try { |
| 3494 | if (phone != null) { |
| 3495 | return phone.getVoiceActivationState(); |
| 3496 | } else { |
| 3497 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3498 | } |
| 3499 | } finally { |
| 3500 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3501 | } |
| 3502 | } |
| 3503 | |
| 3504 | /** |
| 3505 | * Returns the data activation state of a given subId. |
| 3506 | */ |
| 3507 | @Override |
| 3508 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3509 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3510 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3511 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3512 | final long identity = Binder.clearCallingIdentity(); |
| 3513 | try { |
| 3514 | if (phone != null) { |
| 3515 | return phone.getDataActivationState(); |
| 3516 | } else { |
| 3517 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3518 | } |
| 3519 | } finally { |
| 3520 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3521 | } |
| 3522 | } |
| 3523 | |
| 3524 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3525 | * Returns the unread count of voicemails for a subId |
| 3526 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3527 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3528 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3529 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3530 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3531 | mApp, subId, callingPackage, callingFeatureId, |
| 3532 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3533 | return 0; |
| 3534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | final Phone phone = getPhone(subId); |
| 3538 | if (phone != null) { |
| 3539 | return phone.getVoiceMessageCount(); |
| 3540 | } else { |
| 3541 | return 0; |
| 3542 | } |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3549 | * returns true, if the device is in a state where both voice and data |
| 3550 | * are supported simultaneously. This can change based on location or network condition. |
| 3551 | */ |
| 3552 | @Override |
| 3553 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | final long identity = Binder.clearCallingIdentity(); |
| 3555 | try { |
| 3556 | final Phone phone = getPhone(subId); |
| 3557 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3558 | } finally { |
| 3559 | Binder.restoreCallingIdentity(identity); |
| 3560 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3561 | } |
| 3562 | |
| 3563 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3564 | * Send the dialer code if called from the current default dialer or the caller has |
| 3565 | * carrier privilege. |
| 3566 | * @param inputCode The dialer code to send |
| 3567 | */ |
| 3568 | @Override |
| 3569 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3570 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3571 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3572 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3573 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3574 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3575 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3576 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | |
| 3579 | final long identity = Binder.clearCallingIdentity(); |
| 3580 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3581 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3582 | } finally { |
| 3583 | Binder.restoreCallingIdentity(identity); |
| 3584 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3585 | } |
| 3586 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3587 | @Override |
| 3588 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3589 | TelephonyPermissions |
| 3590 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3591 | mApp, subId, "getNetworkSelectionMode"); |
| 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | if (!isActiveSubscription(subId)) { |
| 3595 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3596 | } |
| 3597 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3600 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3601 | } |
| 3602 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3604 | public boolean isInEmergencySmsMode() { |
| 3605 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3606 | final long identity = Binder.clearCallingIdentity(); |
| 3607 | try { |
| 3608 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3609 | if (phone.isInEmergencySmsMode()) { |
| 3610 | return true; |
| 3611 | } |
| 3612 | } |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
| 3615 | } |
| 3616 | return false; |
| 3617 | } |
| 3618 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3619 | /** |
| 3620 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3621 | * @param subId The subscription to use to check the configuration. |
| 3622 | * @param c The callback that will be used to send the result. |
| 3623 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3624 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3625 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3626 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3627 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3628 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3629 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3630 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3631 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3632 | "IMS not available on device."); |
| 3633 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3634 | final long token = Binder.clearCallingIdentity(); |
| 3635 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3636 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3637 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3638 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3639 | } catch (ImsException e) { |
| 3640 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | } finally { |
| 3642 | Binder.restoreCallingIdentity(token); |
| 3643 | } |
| 3644 | } |
| 3645 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3646 | /** |
| 3647 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3648 | * @param subId The subscription to use to check the configuration. |
| 3649 | * @param c The callback that will be used to send the result. |
| 3650 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3651 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3652 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3653 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3654 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3655 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3656 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3657 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3658 | final long token = Binder.clearCallingIdentity(); |
| 3659 | try { |
| 3660 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3661 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3662 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3663 | } catch (ImsException e) { |
| 3664 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3665 | + "is inactive, ignoring unregister."); |
| 3666 | // If the subscription is no longer active, just return, since the callback |
| 3667 | // will already have been removed internally. |
| 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(token); |
| 3670 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3671 | } |
| 3672 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3673 | /** |
| 3674 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3675 | */ |
| 3676 | @Override |
| 3677 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3678 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3679 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3681 | "IMS not available on device."); |
| 3682 | } |
| 3683 | final long token = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | Phone phone = getPhone(subId); |
| 3686 | if (phone == null) { |
| 3687 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3688 | + subId + "'"); |
| 3689 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3690 | } |
| 3691 | phone.getImsRegistrationState(regState -> { |
| 3692 | try { |
| 3693 | consumer.accept((regState == null) |
| 3694 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3695 | } catch (RemoteException e) { |
| 3696 | // Ignore if the remote process is no longer available to call back. |
| 3697 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3698 | } |
| 3699 | }); |
| 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(token); |
| 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | /** |
| 3706 | * Get the transport type for the IMS service registration state. |
| 3707 | */ |
| 3708 | @Override |
| 3709 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3710 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3711 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3712 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3713 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3714 | "IMS not available on device."); |
| 3715 | } |
| 3716 | final long token = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | Phone phone = getPhone(subId); |
| 3719 | if (phone == null) { |
| 3720 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3721 | + subId + "'"); |
| 3722 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3723 | } |
| 3724 | phone.getImsRegistrationTech(regTech -> { |
| 3725 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3726 | int regTechConverted = (regTech == null) |
| 3727 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3728 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3729 | regTechConverted); |
| 3730 | try { |
| 3731 | consumer.accept(regTechConverted); |
| 3732 | } catch (RemoteException e) { |
| 3733 | // Ignore if the remote process is no longer available to call back. |
| 3734 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3735 | } |
| 3736 | }); |
| 3737 | } finally { |
| 3738 | Binder.restoreCallingIdentity(token); |
| 3739 | } |
| 3740 | } |
| 3741 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3742 | /** |
| 3743 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3744 | * @param subId The subscription to use to check the configuration. |
| 3745 | * @param c The callback that will be used to send the result. |
| 3746 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3748 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3749 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3750 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3751 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3752 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3753 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3754 | "IMS not available on device."); |
| 3755 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3757 | final long token = Binder.clearCallingIdentity(); |
| 3758 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3759 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3760 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3761 | } catch (ImsException e) { |
| 3762 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(token); |
| 3765 | } |
| 3766 | } |
| 3767 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3768 | /** |
| 3769 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3770 | * @param subId The subscription to use to check the configuration. |
| 3771 | * @param c The callback that will be used to send the result. |
| 3772 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3773 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3774 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3775 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3776 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3777 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3778 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3779 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3780 | |
| 3781 | final long token = Binder.clearCallingIdentity(); |
| 3782 | try { |
| 3783 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3784 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3785 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3786 | } catch (ImsException e) { |
| 3787 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3788 | + "is inactive, ignoring unregister."); |
| 3789 | // If the subscription is no longer active, just return, since the callback |
| 3790 | // will already have been removed internally. |
| 3791 | } finally { |
| 3792 | Binder.restoreCallingIdentity(token); |
| 3793 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
| 3796 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3797 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3798 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3799 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3800 | final long token = Binder.clearCallingIdentity(); |
| 3801 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3802 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3803 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3804 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3805 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3806 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3807 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3808 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3809 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3810 | } finally { |
| 3811 | Binder.restoreCallingIdentity(token); |
| 3812 | } |
| 3813 | } |
| 3814 | |
| 3815 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3816 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3817 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3818 | final long token = Binder.clearCallingIdentity(); |
| 3819 | try { |
| 3820 | Phone phone = getPhone(subId); |
| 3821 | if (phone == null) return false; |
| 3822 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3823 | } catch (com.android.ims.ImsException e) { |
| 3824 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3825 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(token); |
| 3828 | } |
| 3829 | } |
| 3830 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3831 | /** |
| 3832 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3833 | * subscription. |
| 3834 | * @param subId The subscription to use to check the configuration. |
| 3835 | * @param callback The callback that will be used to send the result. |
| 3836 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3837 | * @param transportType The transport type of the MmTelFeature capability. |
| 3838 | */ |
| 3839 | @Override |
| 3840 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3841 | int transportType) { |
| 3842 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3843 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3845 | "IMS not available on device."); |
| 3846 | } |
| 3847 | final long token = Binder.clearCallingIdentity(); |
| 3848 | try { |
| 3849 | int slotId = getSlotIndex(subId); |
| 3850 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3851 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3852 | + subId + "'"); |
| 3853 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3854 | } |
| 3855 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3856 | transportType, aBoolean -> { |
| 3857 | try { |
| 3858 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3859 | } catch (RemoteException e) { |
| 3860 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3861 | + "running. Ignore"); |
| 3862 | } |
| 3863 | }); |
| 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(token); |
| 3866 | } |
| 3867 | } |
| 3868 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3869 | /** |
| 3870 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3871 | * @param subId The subscription to use to check the configuration. |
| 3872 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3873 | @Override |
| 3874 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3875 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3876 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3877 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3879 | final long token = Binder.clearCallingIdentity(); |
| 3880 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3881 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3882 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3883 | } catch (ImsException e) { |
| 3884 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | } finally { |
| 3886 | Binder.restoreCallingIdentity(token); |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3891 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3893 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | final long identity = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3897 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3898 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3899 | } catch (ImsException e) { |
| 3900 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | } finally { |
| 3902 | Binder.restoreCallingIdentity(identity); |
| 3903 | } |
| 3904 | } |
| 3905 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3906 | /** |
| 3907 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3908 | * @param subId The subscription to use to check the configuration. |
| 3909 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3911 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3912 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3913 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3914 | final long identity = Binder.clearCallingIdentity(); |
| 3915 | try { |
| 3916 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3917 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3918 | } catch (ImsException e) { |
| 3919 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | } finally { |
| 3921 | Binder.restoreCallingIdentity(identity); |
| 3922 | } |
| 3923 | } |
| 3924 | |
| 3925 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3926 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3927 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3928 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3929 | final long identity = Binder.clearCallingIdentity(); |
| 3930 | try { |
| 3931 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3932 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3933 | } catch (ImsException e) { |
| 3934 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(identity); |
| 3937 | } |
| 3938 | } |
| 3939 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3940 | /** |
| 3941 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3942 | * @param subId The subscription to use to check the configuration. |
| 3943 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3944 | @Override |
| 3945 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3946 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3947 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | final long identity = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3951 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3952 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3953 | } catch (ImsException e) { |
| 3954 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3961 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3963 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3964 | final long identity = Binder.clearCallingIdentity(); |
| 3965 | try { |
| 3966 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3967 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3968 | } catch (ImsException e) { |
| 3969 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3970 | } finally { |
| 3971 | Binder.restoreCallingIdentity(identity); |
| 3972 | } |
| 3973 | } |
| 3974 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3975 | /** |
| 3976 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3977 | * @param subId The subscription to use to check the configuration. |
| 3978 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | @Override |
| 3980 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3981 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3982 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
| 3985 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3986 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3987 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3988 | } catch (ImsException e) { |
| 3989 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | } finally { |
| 3991 | Binder.restoreCallingIdentity(identity); |
| 3992 | } |
| 3993 | } |
| 3994 | |
| 3995 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3996 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3998 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3999 | final long identity = Binder.clearCallingIdentity(); |
| 4000 | try { |
| 4001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4002 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4003 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4004 | } catch (ImsException e) { |
| 4005 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4006 | } finally { |
| 4007 | Binder.restoreCallingIdentity(identity); |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | @Override |
| 4012 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4013 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4014 | "setVoWiFiNonPersistent"); |
| 4015 | final long identity = Binder.clearCallingIdentity(); |
| 4016 | try { |
| 4017 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4018 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4019 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4020 | } catch (ImsException e) { |
| 4021 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4022 | } finally { |
| 4023 | Binder.restoreCallingIdentity(identity); |
| 4024 | } |
| 4025 | } |
| 4026 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4027 | /** |
| 4028 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4029 | * @param subId The subscription to use to check the configuration. |
| 4030 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4031 | @Override |
| 4032 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4033 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4034 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 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 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | getSlotIndexOrException(subId)).getWfcMode(false /*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 setVoWiFiModeSetting(int subId, int mode) { |
| 4049 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4050 | "setVoWiFiModeSetting"); |
| 4051 | final long identity = Binder.clearCallingIdentity(); |
| 4052 | try { |
| 4053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4054 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4056 | } catch (ImsException e) { |
| 4057 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | @Override |
| 4064 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4065 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4066 | final long identity = Binder.clearCallingIdentity(); |
| 4067 | try { |
| 4068 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4069 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4071 | } catch (ImsException e) { |
| 4072 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4073 | } finally { |
| 4074 | Binder.restoreCallingIdentity(identity); |
| 4075 | } |
| 4076 | } |
| 4077 | |
| 4078 | @Override |
| 4079 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4081 | "setVoWiFiRoamingModeSetting"); |
| 4082 | final long identity = Binder.clearCallingIdentity(); |
| 4083 | try { |
| 4084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4085 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4086 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4087 | } catch (ImsException e) { |
| 4088 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
| 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | @Override |
| 4095 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4096 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4097 | "setRttCapabilityEnabled"); |
| 4098 | final long identity = Binder.clearCallingIdentity(); |
| 4099 | try { |
| 4100 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4101 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4102 | } catch (ImsException e) { |
| 4103 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
| 4107 | } |
| 4108 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4109 | /** |
| 4110 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4111 | * @param subId The subscription to use to check the configuration. |
| 4112 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | @Override |
| 4114 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4115 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4116 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4117 | final long identity = Binder.clearCallingIdentity(); |
| 4118 | try { |
| 4119 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4120 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4121 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4122 | } catch (ImsException e) { |
| 4123 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4124 | } finally { |
| 4125 | Binder.restoreCallingIdentity(identity); |
| 4126 | } |
| 4127 | } |
| 4128 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4129 | @Override |
| 4130 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4131 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4132 | final long identity = Binder.clearCallingIdentity(); |
| 4133 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4134 | if (!isImsAvailableOnDevice()) { |
| 4135 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4136 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4137 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4139 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4140 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4141 | } catch (ImsException e) { |
| 4142 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(identity); |
| 4145 | } |
| 4146 | } |
| 4147 | |
| 4148 | @Override |
| 4149 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4150 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4151 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4152 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4153 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4154 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4155 | try { |
| 4156 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4157 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4158 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4160 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4161 | + "is inactive, ignoring unregister."); |
| 4162 | // If the subscription is no longer active, just return, since the callback will already |
| 4163 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
| 4167 | } |
| 4168 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4169 | |
| 4170 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4172 | message); |
| 4173 | } |
| 4174 | |
| 4175 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4176 | boolean isMmtelCapability) { |
| 4177 | Phone phone = getPhone(subId); |
| 4178 | if (phone == null) { |
| 4179 | loge("phone instance null for subid " + subId); |
| 4180 | return false; |
| 4181 | } |
| 4182 | if (isMmtelCapability) { |
| 4183 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4184 | return false; |
| 4185 | } |
| 4186 | } else { |
| 4187 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4188 | return false; |
| 4189 | } |
| 4190 | } |
| 4191 | return true; |
| 4192 | } |
| 4193 | |
| 4194 | @Override |
| 4195 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4196 | boolean isProvisioned) { |
| 4197 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4198 | |
| 4199 | final long identity = Binder.clearCallingIdentity(); |
| 4200 | try { |
| 4201 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4202 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4203 | return; |
| 4204 | } |
| 4205 | |
| 4206 | // this capability requires provisioning, route to the correct API. |
| 4207 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4208 | switch (capability) { |
| 4209 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4210 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4211 | ims.setEabProvisioned(isProvisioned); |
| 4212 | break; |
| 4213 | default: { |
| 4214 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4215 | + "rcs capability '" + capability + "', which does not require " |
| 4216 | + "provisioning."); |
| 4217 | } |
| 4218 | } |
| 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
| 4222 | |
| 4223 | } |
| 4224 | |
| 4225 | |
| 4226 | @Override |
| 4227 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4228 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
| 4231 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4232 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4233 | return true; |
| 4234 | } |
| 4235 | |
| 4236 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4237 | switch (capability) { |
| 4238 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4239 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4240 | return ims.isEabProvisionedOnDevice(); |
| 4241 | |
| 4242 | default: { |
| 4243 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4244 | + "capability '" + capability + "', which does not require " |
| 4245 | + "provisioning."); |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
| 4251 | } |
| 4252 | } |
| 4253 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4254 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4255 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4256 | boolean isProvisioned) { |
| 4257 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4258 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4259 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4260 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4261 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4262 | final long identity = Binder.clearCallingIdentity(); |
| 4263 | try { |
| 4264 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4265 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4266 | return; |
| 4267 | } |
| 4268 | |
| 4269 | // this capability requires provisioning, route to the correct API. |
| 4270 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4271 | switch (capability) { |
| 4272 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4273 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4274 | ims.setVolteProvisioned(isProvisioned); |
| 4275 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4276 | ims.setWfcProvisioned(isProvisioned); |
| 4277 | } |
| 4278 | break; |
| 4279 | } |
| 4280 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4281 | // There is currently no difference in VT provisioning type. |
| 4282 | ims.setVtProvisioned(isProvisioned); |
| 4283 | break; |
| 4284 | } |
| 4285 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4286 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4287 | // change the capability of the feature instead if needed. |
| 4288 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4289 | == isProvisioned) { |
| 4290 | // No change in provisioning. |
| 4291 | return; |
| 4292 | } |
| 4293 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4294 | try { |
| 4295 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4296 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4297 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4298 | + ", Exception" + e.getMessage()); |
| 4299 | } |
| 4300 | break; |
| 4301 | } |
| 4302 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4303 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4304 | + "MmTel capability '" + capability + "', which does not require " |
| 4305 | + "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 getImsProvisioningStatusForCapability(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("getProvisioningStatusForCapability"); |
| 4321 | final long identity = Binder.clearCallingIdentity(); |
| 4322 | try { |
| 4323 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4324 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4325 | return true; |
| 4326 | } |
| 4327 | |
| 4328 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4329 | switch (capability) { |
| 4330 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4331 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4332 | return ims.isVolteProvisionedOnDevice(); |
| 4333 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4334 | return ims.isWfcProvisionedOnDevice(); |
| 4335 | } |
| 4336 | // This should never happen, since we are checking tech above to make sure it |
| 4337 | // is either LTE or IWLAN. |
| 4338 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4339 | + "capability."); |
| 4340 | } |
| 4341 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4342 | // There is currently no difference in VT provisioning type. |
| 4343 | return ims.isVtProvisionedOnDevice(); |
| 4344 | } |
| 4345 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4346 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4347 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4348 | } |
| 4349 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4350 | throw new IllegalArgumentException( |
| 4351 | "Tried to get provisioning for MmTel capability '" + capability |
| 4352 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | } finally { |
| 4357 | Binder.restoreCallingIdentity(identity); |
| 4358 | } |
| 4359 | } |
| 4360 | |
| 4361 | @Override |
| 4362 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4363 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4364 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4365 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4366 | } |
| 4367 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4368 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4369 | return (provisionedBits & capability) > 0; |
| 4370 | } |
| 4371 | |
| 4372 | @Override |
| 4373 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4374 | boolean isProvisioned) { |
| 4375 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4376 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4377 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4378 | } |
| 4379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4380 | "setProvisioningStatusForCapability"); |
| 4381 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4382 | // If the current provisioning status for capability already matches isProvisioned, |
| 4383 | // do nothing. |
| 4384 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4385 | return; |
| 4386 | } |
| 4387 | if (isProvisioned) { |
| 4388 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4389 | } else { |
| 4390 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | /** |
| 4395 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4396 | * technology. The bitfield should mirror the bitfield defined by |
| 4397 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4398 | */ |
| 4399 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4400 | String key = getMmTelProvisioningKey(subId, tech); |
| 4401 | // Default is no capabilities are provisioned. |
| 4402 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4403 | } |
| 4404 | |
| 4405 | /** |
| 4406 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4407 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4408 | * technology specified. |
| 4409 | * |
| 4410 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4411 | */ |
| 4412 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4413 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4414 | String key = getMmTelProvisioningKey(subId, tech); |
| 4415 | editor.putInt(key, newField); |
| 4416 | editor.commit(); |
| 4417 | } |
| 4418 | |
| 4419 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4420 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4421 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4422 | } |
| 4423 | |
| 4424 | /** |
| 4425 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4426 | * carrier associated with the subscription id. |
| 4427 | */ |
| 4428 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4429 | int capability) { |
| 4430 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4431 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4432 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4433 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4434 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4435 | false); |
| 4436 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4437 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4438 | |
| 4439 | // First check to make sure that the capability requires provisioning. |
| 4440 | switch (capability) { |
| 4441 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4442 | // intentional fallthrough |
| 4443 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4444 | if (requireVoiceVtProvisioning) { |
| 4445 | // Voice and Video requires provisioning |
| 4446 | return true; |
| 4447 | } |
| 4448 | break; |
| 4449 | } |
| 4450 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4451 | if (requireUtProvisioning) { |
| 4452 | // UT requires provisioning |
| 4453 | return true; |
| 4454 | } |
| 4455 | break; |
| 4456 | } |
| 4457 | } |
| 4458 | return false; |
| 4459 | } |
| 4460 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4461 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4462 | int capability) { |
| 4463 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4464 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4465 | |
| 4466 | boolean requireRcsProvisioning = c.getBoolean( |
| 4467 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4468 | |
| 4469 | // First check to make sure that the capability requires provisioning. |
| 4470 | switch (capability) { |
| 4471 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4472 | // intentional fallthrough |
| 4473 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4474 | if (requireRcsProvisioning) { |
| 4475 | // OPTION or PRESENCE requires provisioning |
| 4476 | return true; |
| 4477 | } |
| 4478 | break; |
| 4479 | } |
| 4480 | } |
| 4481 | return false; |
| 4482 | } |
| 4483 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4484 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4485 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4486 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4487 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4488 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4489 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4490 | final long identity = Binder.clearCallingIdentity(); |
| 4491 | try { |
| 4492 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4493 | int slotId = getSlotIndex(subId); |
| 4494 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4495 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4496 | + subId + "' for key:" + key); |
| 4497 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4498 | } |
| 4499 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4500 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4501 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4502 | + subId + "' for key:" + key); |
| 4503 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4504 | } finally { |
| 4505 | Binder.restoreCallingIdentity(identity); |
| 4506 | } |
| 4507 | } |
| 4508 | |
| 4509 | @Override |
| 4510 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4511 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4512 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4513 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4514 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
| 4517 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4518 | int slotId = getSlotIndex(subId); |
| 4519 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4520 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4521 | + subId + "' for key:" + key); |
| 4522 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4523 | } |
| 4524 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4525 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4526 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4527 | + subId + "' for key:" + key); |
| 4528 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4529 | } finally { |
| 4530 | Binder.restoreCallingIdentity(identity); |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | @Override |
| 4535 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4536 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4537 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4538 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4540 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4541 | final long identity = Binder.clearCallingIdentity(); |
| 4542 | try { |
| 4543 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4544 | int slotId = getSlotIndex(subId); |
| 4545 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4546 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4547 | + subId + "' for key:" + key); |
| 4548 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4549 | } |
| 4550 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4551 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4552 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4553 | + "' for key:" + key); |
| 4554 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
| 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | @Override |
| 4561 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4562 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4563 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4564 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4565 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4566 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4567 | final long identity = Binder.clearCallingIdentity(); |
| 4568 | try { |
| 4569 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4570 | int slotId = getSlotIndex(subId); |
| 4571 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4572 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4573 | + subId + "' for key:" + key); |
| 4574 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4575 | } |
| 4576 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4577 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4578 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4579 | + "' for key:" + key); |
| 4580 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4586 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4587 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4588 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4589 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4590 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4591 | } |
| 4592 | return slotId; |
| 4593 | } |
| 4594 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4595 | private int getSlotIndex(int subId) { |
| 4596 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4597 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4598 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4599 | } |
| 4600 | return slotId; |
| 4601 | } |
| 4602 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4603 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4604 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4605 | */ |
| 4606 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4607 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4608 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4609 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4610 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4611 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4612 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4613 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4614 | mApp, subId, callingPackage, callingFeatureId, |
| 4615 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4616 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4617 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4619 | final long identity = Binder.clearCallingIdentity(); |
| 4620 | try { |
| 4621 | final Phone phone = getPhone(subId); |
| 4622 | if (phone != null) { |
| 4623 | return phone.getServiceState().getDataNetworkType(); |
| 4624 | } else { |
| 4625 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4626 | } |
| 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * Returns the data network type |
| 4634 | */ |
| 4635 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4636 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4637 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4638 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4639 | } |
| 4640 | |
| 4641 | /** |
| 4642 | * Returns the data network type for a subId |
| 4643 | */ |
| 4644 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4645 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4646 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4647 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4648 | mApp, subId, callingPackage, callingFeatureId, |
| 4649 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4650 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4651 | } |
| 4652 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4653 | final long identity = Binder.clearCallingIdentity(); |
| 4654 | try { |
| 4655 | final Phone phone = getPhone(subId); |
| 4656 | if (phone != null) { |
| 4657 | return phone.getServiceState().getDataNetworkType(); |
| 4658 | } else { |
| 4659 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4660 | } |
| 4661 | } finally { |
| 4662 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4663 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4667 | * Returns the Voice network type for a subId |
| 4668 | */ |
| 4669 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4670 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4671 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4672 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4673 | mApp, subId, callingPackage, callingFeatureId, |
| 4674 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4675 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4676 | } |
| 4677 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4678 | final long identity = Binder.clearCallingIdentity(); |
| 4679 | try { |
| 4680 | final Phone phone = getPhone(subId); |
| 4681 | if (phone != null) { |
| 4682 | return phone.getServiceState().getVoiceNetworkType(); |
| 4683 | } else { |
| 4684 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4685 | } |
| 4686 | } finally { |
| 4687 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4688 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
| 4691 | /** |
| 4692 | * @return true if a ICC card is present |
| 4693 | */ |
| 4694 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4695 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4696 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4697 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4701 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4702 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4703 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4704 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
| 4707 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4708 | if (phone != null) { |
| 4709 | return phone.getIccCard().hasIccCard(); |
| 4710 | } else { |
| 4711 | return false; |
| 4712 | } |
| 4713 | } finally { |
| 4714 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | /** |
| 4719 | * Return if the current radio is LTE on CDMA. This |
| 4720 | * is a tri-state return value as for a period of time |
| 4721 | * the mode may be unknown. |
| 4722 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4723 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4724 | * @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] | 4725 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4726 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4727 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4728 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4729 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4730 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4731 | } |
| 4732 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4733 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4734 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4735 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4736 | try { |
| 4737 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4738 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4739 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4740 | } |
| 4741 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4742 | final long identity = Binder.clearCallingIdentity(); |
| 4743 | try { |
| 4744 | final Phone phone = getPhone(subId); |
| 4745 | if (phone == null) { |
| 4746 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4747 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4748 | return TelephonyProperties.lte_on_cdma_device() |
| 4749 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4750 | } |
| 4751 | } finally { |
| 4752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4753 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4754 | } |
| 4755 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4756 | /** |
| 4757 | * {@hide} |
| 4758 | * Returns Default subId, 0 in the case of single standby. |
| 4759 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4760 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4761 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4762 | } |
| 4763 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4764 | private int getSlotForDefaultSubscription() { |
| 4765 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4766 | } |
| 4767 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4768 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4769 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4770 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4771 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4772 | private boolean isActiveSubscription(int subId) { |
| 4773 | return mSubscriptionController.isActiveSubId(subId); |
| 4774 | } |
| 4775 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4778 | */ |
| 4779 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4780 | final long identity = Binder.clearCallingIdentity(); |
| 4781 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4782 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4784 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
| 4787 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | /** |
| 4791 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4792 | */ |
| 4793 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4794 | final long identity = Binder.clearCallingIdentity(); |
| 4795 | try { |
| 4796 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4797 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4798 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4799 | } finally { |
| 4800 | Binder.restoreCallingIdentity(identity); |
| 4801 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4802 | } |
| 4803 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4804 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4805 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4806 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4807 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4808 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4809 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4810 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4811 | if (phoneId == -1) { |
| 4812 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4813 | + " does not correspond to an active phone"); |
| 4814 | } |
| 4815 | return PhoneFactory.getPhone(phoneId); |
| 4816 | } |
| 4817 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4818 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4819 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4820 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4822 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4823 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4824 | if (DBG) { |
| 4825 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4826 | } |
| 4827 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4828 | p2); |
| 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 | |
| 4832 | @Override |
| 4833 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4834 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4835 | enforceModifyPermission(); |
| 4836 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4837 | if (DBG) { |
| 4838 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4839 | } |
| 4840 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4841 | callingPackage, aid, p2); |
| 4842 | } |
| 4843 | |
| 4844 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4845 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4846 | final long identity = Binder.clearCallingIdentity(); |
| 4847 | try { |
| 4848 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4849 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4850 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4851 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | if (bestComponent == null |
| 4853 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4854 | loge("The calling package is not allowed to access ISD-R."); |
| 4855 | throw new SecurityException( |
| 4856 | "The calling package is not allowed to access ISD-R."); |
| 4857 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4858 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4861 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4862 | null /* workSource */); |
| 4863 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | return response; |
| 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
| 4867 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4871 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4873 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4874 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4875 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4876 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4877 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4878 | @Override |
| 4879 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4880 | enforceModifyPermission(); |
| 4881 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4882 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4883 | channel); |
| 4884 | } |
| 4885 | |
| 4886 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4887 | final long identity = Binder.clearCallingIdentity(); |
| 4888 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | if (channel < 0) { |
| 4890 | return false; |
| 4891 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4892 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4893 | null /* workSource */); |
| 4894 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | return success; |
| 4896 | } finally { |
| 4897 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4898 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
| 4901 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4902 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4903 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4904 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4905 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4906 | if (DBG) { |
| 4907 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4908 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4909 | + p3 + " data=" + data); |
| 4910 | } |
| 4911 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4912 | command, p1, p2, p3, data); |
| 4913 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4914 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4915 | @Override |
| 4916 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4917 | int command, int p1, int p2, int p3, String data) { |
| 4918 | enforceModifyPermission(); |
| 4919 | if (DBG) { |
| 4920 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4921 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4922 | + p3 + " data=" + data); |
| 4923 | } |
| 4924 | return iccTransmitApduLogicalChannelWithPermission( |
| 4925 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4926 | data); |
| 4927 | } |
| 4928 | |
| 4929 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4930 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | final long identity = Binder.clearCallingIdentity(); |
| 4932 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4933 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | return ""; |
| 4935 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4938 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4939 | null /* workSource */); |
| 4940 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4941 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4942 | // Append the returned status code to the end of the response payload. |
| 4943 | String s = Integer.toHexString( |
| 4944 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4945 | if (response.payload != null) { |
| 4946 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4947 | } |
| 4948 | return s; |
| 4949 | } finally { |
| 4950 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4951 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4952 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4953 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4954 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4955 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4956 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4958 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4960 | if (DBG) { |
| 4961 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4962 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4963 | } |
| 4964 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4965 | cla, command, p1, p2, p3, data); |
| 4966 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4967 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4968 | @Override |
| 4969 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4970 | int command, int p1, int p2, int p3, String data) { |
| 4971 | enforceModifyPermission(); |
| 4972 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4973 | if (DBG) { |
| 4974 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4975 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4976 | + " data=" + data); |
| 4977 | } |
| 4978 | |
| 4979 | return iccTransmitApduBasicChannelWithPermission( |
| 4980 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4981 | p2, p3, data); |
| 4982 | } |
| 4983 | |
| 4984 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4985 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4986 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4987 | final long identity = Binder.clearCallingIdentity(); |
| 4988 | try { |
| 4989 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4990 | && TextUtils.equals(ISDR_AID, data)) { |
| 4991 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4992 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4993 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | if (bestComponent == null |
| 4995 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4996 | loge("The calling package is not allowed to select ISD-R."); |
| 4997 | throw new SecurityException( |
| 4998 | "The calling package is not allowed to select ISD-R."); |
| 4999 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5000 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5003 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5004 | null /* workSource */); |
| 5005 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5006 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5007 | // Append the returned status code to the end of the response payload. |
| 5008 | String s = Integer.toHexString( |
| 5009 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5010 | if (response.payload != null) { |
| 5011 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5012 | } |
| 5013 | return s; |
| 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5016 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5020 | 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] | 5021 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5023 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5025 | final long identity = Binder.clearCallingIdentity(); |
| 5026 | try { |
| 5027 | if (DBG) { |
| 5028 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5029 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5030 | } |
| 5031 | |
| 5032 | IccIoResult response = |
| 5033 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5034 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5035 | subId); |
| 5036 | |
| 5037 | if (DBG) { |
| 5038 | log("Exchange SIM_IO [R]" + response); |
| 5039 | } |
| 5040 | |
| 5041 | byte[] result = null; |
| 5042 | int length = 2; |
| 5043 | if (response.payload != null) { |
| 5044 | length = 2 + response.payload.length; |
| 5045 | result = new byte[length]; |
| 5046 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5047 | } else { |
| 5048 | result = new byte[length]; |
| 5049 | } |
| 5050 | |
| 5051 | result[length - 1] = (byte) response.sw2; |
| 5052 | result[length - 2] = (byte) response.sw1; |
| 5053 | return result; |
| 5054 | } finally { |
| 5055 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5056 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5059 | /** |
| 5060 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5061 | * on a particular subscription |
| 5062 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5063 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5064 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5066 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5067 | return null; |
| 5068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | |
| 5070 | final long identity = Binder.clearCallingIdentity(); |
| 5071 | try { |
| 5072 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5073 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5074 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5075 | return null; |
| 5076 | } |
| 5077 | Object response = sendRequest( |
| 5078 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5079 | if (response instanceof String[]) { |
| 5080 | return (String[]) response; |
| 5081 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5082 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5084 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5087 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5088 | } |
| 5089 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5090 | /** |
| 5091 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5092 | * subscription. |
| 5093 | * |
| 5094 | * @param subId the id of the subscription. |
| 5095 | * @param appType the uicc app type, must be USIM or SIM. |
| 5096 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5097 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5098 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5099 | * @return number of fplmns that is successfully written to the SIM. |
| 5100 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5101 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5102 | String callingFeatureId) { |
| 5103 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5104 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5105 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5106 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5107 | } |
| 5108 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5109 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5110 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5111 | } |
| 5112 | if (fplmns == null) { |
| 5113 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5114 | } |
| 5115 | for (String fplmn : fplmns) { |
| 5116 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5117 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5118 | } |
| 5119 | } |
| 5120 | final long identity = Binder.clearCallingIdentity(); |
| 5121 | try { |
| 5122 | Object response = sendRequest( |
| 5123 | CMD_SET_FORBIDDEN_PLMNS, |
| 5124 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5125 | subId); |
| 5126 | return (int) response; |
| 5127 | } finally { |
| 5128 | Binder.restoreCallingIdentity(identity); |
| 5129 | } |
| 5130 | } |
| 5131 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5132 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5133 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5135 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
| 5139 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5140 | if (response.payload == null) { |
| 5141 | return ""; |
| 5142 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5143 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | // Append the returned status code to the end of the response payload. |
| 5145 | String s = Integer.toHexString( |
| 5146 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5147 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5148 | return s; |
| 5149 | } finally { |
| 5150 | Binder.restoreCallingIdentity(identity); |
| 5151 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5154 | /** |
| 5155 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5156 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5157 | * |
| 5158 | * @param itemID the ID of the item to read |
| 5159 | * @return the NV item as a String, or null on error. |
| 5160 | */ |
| 5161 | @Override |
| 5162 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5163 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5165 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | |
| 5167 | final long identity = Binder.clearCallingIdentity(); |
| 5168 | try { |
| 5169 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5170 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5171 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5172 | return value; |
| 5173 | } finally { |
| 5174 | Binder.restoreCallingIdentity(identity); |
| 5175 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /** |
| 5179 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5180 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5181 | * |
| 5182 | * @param itemID the ID of the item to read |
| 5183 | * @param itemValue the value to write, as a String |
| 5184 | * @return true on success; false on any failure |
| 5185 | */ |
| 5186 | @Override |
| 5187 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5188 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5189 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5190 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5191 | |
| 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
| 5194 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5195 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5196 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5198 | return success; |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | /** |
| 5205 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5206 | * Used for device configuration by some CDMA operators. |
| 5207 | * |
| 5208 | * @param preferredRoamingList byte array containing the new PRL |
| 5209 | * @return true on success; false on any failure |
| 5210 | */ |
| 5211 | @Override |
| 5212 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5213 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5214 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5215 | |
| 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5219 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5220 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5221 | return success; |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
| 5224 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5228 | * 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] | 5229 | * Used for device configuration by some CDMA operators. |
| 5230 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5231 | * @param slotIndex - device slot. |
| 5232 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5233 | * @return true on success; false on any failure |
| 5234 | */ |
| 5235 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5236 | public boolean resetModemConfig(int slotIndex) { |
| 5237 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5238 | if (phone != null) { |
| 5239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5240 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5242 | final long identity = Binder.clearCallingIdentity(); |
| 5243 | try { |
| 5244 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5245 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5246 | return success; |
| 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
| 5249 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5251 | return false; |
| 5252 | } |
| 5253 | |
| 5254 | /** |
| 5255 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5256 | * |
| 5257 | * @param slotIndex - device slot. |
| 5258 | * |
| 5259 | * @return true on success; false on any failure |
| 5260 | */ |
| 5261 | @Override |
| 5262 | public boolean rebootModem(int slotIndex) { |
| 5263 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5264 | if (phone != null) { |
| 5265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5266 | mApp, phone.getSubId(), "rebootModem"); |
| 5267 | |
| 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
| 5270 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5271 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5272 | return success; |
| 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
| 5276 | } |
| 5277 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5278 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5279 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5280 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5281 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5282 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5283 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5284 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5285 | return new String[0]; |
| 5286 | } |
| 5287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | final long identity = Binder.clearCallingIdentity(); |
| 5289 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5290 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | } finally { |
| 5292 | Binder.restoreCallingIdentity(identity); |
| 5293 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5296 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5297 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5298 | * {@link #disableIms(int)}. |
| 5299 | * @param slotIndex device slot. |
| 5300 | */ |
| 5301 | public void resetIms(int slotIndex) { |
| 5302 | enforceModifyPermission(); |
| 5303 | |
| 5304 | final long identity = Binder.clearCallingIdentity(); |
| 5305 | try { |
| 5306 | if (mImsResolver == null) { |
| 5307 | // may happen if the does not support IMS. |
| 5308 | return; |
| 5309 | } |
| 5310 | mImsResolver.disableIms(slotIndex); |
| 5311 | mImsResolver.enableIms(slotIndex); |
| 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5318 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5319 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5320 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5321 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5322 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | |
| 5324 | final long identity = Binder.clearCallingIdentity(); |
| 5325 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5326 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5327 | // may happen if the device does not support IMS. |
| 5328 | return; |
| 5329 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5330 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | } finally { |
| 5332 | Binder.restoreCallingIdentity(identity); |
| 5333 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5334 | } |
| 5335 | |
| 5336 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5337 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5338 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5339 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5340 | public void disableIms(int slotId) { |
| 5341 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | |
| 5343 | final long identity = Binder.clearCallingIdentity(); |
| 5344 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5345 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5346 | // may happen if the device does not support IMS. |
| 5347 | return; |
| 5348 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5349 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5350 | } finally { |
| 5351 | Binder.restoreCallingIdentity(identity); |
| 5352 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5353 | } |
| 5354 | |
| 5355 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5356 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5357 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5358 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5359 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5360 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5361 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | |
| 5363 | final long identity = Binder.clearCallingIdentity(); |
| 5364 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5365 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5366 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5367 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5368 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5369 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | } finally { |
| 5371 | Binder.restoreCallingIdentity(identity); |
| 5372 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5373 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5374 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5375 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5376 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5377 | @Override |
| 5378 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5379 | enforceModifyPermission(); |
| 5380 | |
| 5381 | final long identity = Binder.clearCallingIdentity(); |
| 5382 | try { |
| 5383 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5384 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5385 | } finally { |
| 5386 | Binder.restoreCallingIdentity(identity); |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5391 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5392 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5393 | */ |
| 5394 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5395 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | |
| 5397 | final long identity = Binder.clearCallingIdentity(); |
| 5398 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5399 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5400 | // may happen if the device does not support IMS. |
| 5401 | return null; |
| 5402 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5403 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | } finally { |
| 5405 | Binder.restoreCallingIdentity(identity); |
| 5406 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5407 | } |
| 5408 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5409 | /** |
| 5410 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5411 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5412 | */ |
| 5413 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5414 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5415 | |
| 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5418 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5419 | // may happen if the device does not support IMS. |
| 5420 | return null; |
| 5421 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5422 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5423 | } finally { |
| 5424 | Binder.restoreCallingIdentity(identity); |
| 5425 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5426 | } |
| 5427 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5428 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5429 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5430 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5431 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5432 | * @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] | 5433 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5434 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5435 | * @param packageName The name of the package that the current configuration will be replaced |
| 5436 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5437 | * @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] | 5438 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5439 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5440 | int[] featureTypes, String packageName) { |
| 5441 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5442 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5444 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5445 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5446 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | final long identity = Binder.clearCallingIdentity(); |
| 5448 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5449 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5450 | // may happen if the device does not support IMS. |
| 5451 | return false; |
| 5452 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5453 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5454 | for (int featureType : featureTypes) { |
| 5455 | featureConfig.put(featureType, packageName); |
| 5456 | } |
| 5457 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5458 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5459 | } finally { |
| 5460 | Binder.restoreCallingIdentity(identity); |
| 5461 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5465 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5466 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5467 | * |
| 5468 | * This should only be used for testing. |
| 5469 | * |
| 5470 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5471 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5472 | */ |
| 5473 | @Override |
| 5474 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5475 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5476 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5477 | "clearCarrierImsServiceOverride"); |
| 5478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5479 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5480 | "clearCarrierImsServiceOverride"); |
| 5481 | |
| 5482 | final long identity = Binder.clearCallingIdentity(); |
| 5483 | try { |
| 5484 | if (mImsResolver == null) { |
| 5485 | // may happen if the device does not support IMS. |
| 5486 | return false; |
| 5487 | } |
| 5488 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5495 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5496 | * |
| 5497 | * @param slotId The slot that the ImsService is associated with. |
| 5498 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5499 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5500 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5501 | * @return the package name of the ImsService configuration. |
| 5502 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5503 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5504 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5505 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5506 | TelephonyPermissions |
| 5507 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5508 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5509 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5510 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | final long identity = Binder.clearCallingIdentity(); |
| 5512 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5513 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5514 | // may happen if the device does not support IMS. |
| 5515 | return ""; |
| 5516 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5517 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5518 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5519 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5520 | } finally { |
| 5521 | Binder.restoreCallingIdentity(identity); |
| 5522 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5523 | } |
| 5524 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5525 | /** |
| 5526 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5527 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5528 | * @param callback A callback with an integer containing the |
| 5529 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5530 | */ |
| 5531 | @Override |
| 5532 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5533 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5534 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5535 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5536 | "IMS not available on device."); |
| 5537 | } |
| 5538 | final long token = Binder.clearCallingIdentity(); |
| 5539 | try { |
| 5540 | int slotId = getSlotIndex(subId); |
| 5541 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5542 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5543 | + subId + "'"); |
| 5544 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5545 | } |
| 5546 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5547 | try { |
| 5548 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5549 | } catch (RemoteException e) { |
| 5550 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5551 | + "Ignore"); |
| 5552 | } |
| 5553 | }); |
| 5554 | } finally { |
| 5555 | Binder.restoreCallingIdentity(token); |
| 5556 | } |
| 5557 | } |
| 5558 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5559 | /** |
| 5560 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5561 | */ |
| 5562 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | |
| 5565 | final long identity = Binder.clearCallingIdentity(); |
| 5566 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5567 | // NOTE: Before S, this method only set the default phone. |
| 5568 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5569 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5570 | phone.setImsRegistrationState(registered); |
| 5571 | } |
| 5572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | } finally { |
| 5574 | Binder.restoreCallingIdentity(identity); |
| 5575 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5579 | * Set the network selection mode to automatic. |
| 5580 | * |
| 5581 | */ |
| 5582 | @Override |
| 5583 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5585 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | |
| 5587 | final long identity = Binder.clearCallingIdentity(); |
| 5588 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5589 | if (!isActiveSubscription(subId)) { |
| 5590 | return; |
| 5591 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5593 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5594 | } finally { |
| 5595 | Binder.restoreCallingIdentity(identity); |
| 5596 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5599 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5600 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5601 | * |
| 5602 | * @param subId the id of the subscription. |
| 5603 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5604 | * the operator to attach to. |
| 5605 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5606 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5607 | * normal network selection next time. |
| 5608 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5609 | */ |
| 5610 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5611 | public boolean setNetworkSelectionModeManual( |
| 5612 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5614 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5615 | |
| 5616 | if (!isActiveSubscription(subId)) { |
| 5617 | return false; |
| 5618 | } |
| 5619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | final long identity = Binder.clearCallingIdentity(); |
| 5621 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5622 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5624 | if (DBG) { |
| 5625 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5626 | + " operator: " + operatorInfo); |
| 5627 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5628 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5629 | } finally { |
| 5630 | Binder.restoreCallingIdentity(identity); |
| 5631 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5632 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5633 | /** |
| 5634 | * Get the manual network selection |
| 5635 | * |
| 5636 | * @param subId the id of the subscription. |
| 5637 | * |
| 5638 | * @return the previously saved user selected PLMN |
| 5639 | */ |
| 5640 | @Override |
| 5641 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5642 | TelephonyPermissions |
| 5643 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5644 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5645 | |
| 5646 | final long identity = Binder.clearCallingIdentity(); |
| 5647 | try { |
| 5648 | if (!isActiveSubscription(subId)) { |
| 5649 | return ""; |
| 5650 | } |
| 5651 | |
| 5652 | final Phone phone = getPhone(subId); |
| 5653 | if (phone == null) { |
| 5654 | return ""; |
| 5655 | } |
| 5656 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5657 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5658 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5659 | } finally { |
| 5660 | Binder.restoreCallingIdentity(identity); |
| 5661 | } |
| 5662 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5663 | |
| 5664 | /** |
| 5665 | * Scans for available networks. |
| 5666 | */ |
| 5667 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5668 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5669 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5671 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5672 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5673 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5674 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5675 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5676 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5677 | .setCallingPid(Binder.getCallingPid()) |
| 5678 | .setCallingUid(Binder.getCallingUid()) |
| 5679 | .setMethod("getCellNetworkScanResults") |
| 5680 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5681 | .build()); |
| 5682 | switch (locationResult) { |
| 5683 | case DENIED_HARD: |
| 5684 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5685 | case DENIED_SOFT: |
| 5686 | return null; |
| 5687 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5689 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | try { |
| 5691 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5692 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5693 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | } finally { |
| 5695 | Binder.restoreCallingIdentity(identity); |
| 5696 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5700 | * Get the call forwarding info, given the call forwarding reason. |
| 5701 | */ |
| 5702 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5703 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5704 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5705 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5706 | long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
| 5708 | if (DBG) { |
| 5709 | log("getCallForwarding: subId " + subId |
| 5710 | + " callForwardingReason" + callForwardingReason); |
| 5711 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5712 | |
| 5713 | Phone phone = getPhone(subId); |
| 5714 | if (phone == null) { |
| 5715 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5716 | callback.onError( |
| 5717 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5718 | } catch (RemoteException e) { |
| 5719 | // ignore |
| 5720 | } |
| 5721 | return; |
| 5722 | } |
| 5723 | |
| 5724 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5725 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5726 | @Override |
| 5727 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5728 | try { |
| 5729 | callback.onCallForwardingInfoAvailable(info); |
| 5730 | } catch (RemoteException e) { |
| 5731 | // ignore |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | @Override |
| 5736 | public void onError(int error) { |
| 5737 | try { |
| 5738 | callback.onError(error); |
| 5739 | } catch (RemoteException e) { |
| 5740 | // ignore |
| 5741 | } |
| 5742 | } |
| 5743 | }); |
| 5744 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5745 | } finally { |
| 5746 | Binder.restoreCallingIdentity(identity); |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | /** |
| 5751 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5752 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5753 | */ |
| 5754 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5755 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5756 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5757 | enforceModifyPermission(); |
| 5758 | long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
| 5760 | if (DBG) { |
| 5761 | log("setCallForwarding: subId " + subId |
| 5762 | + " callForwardingInfo" + callForwardingInfo); |
| 5763 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5764 | |
| 5765 | Phone phone = getPhone(subId); |
| 5766 | if (phone == null) { |
| 5767 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5768 | callback.accept( |
| 5769 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5770 | } catch (RemoteException e) { |
| 5771 | // ignore |
| 5772 | } |
| 5773 | return; |
| 5774 | } |
| 5775 | |
| 5776 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5777 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5778 | |
| 5779 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5780 | } finally { |
| 5781 | Binder.restoreCallingIdentity(identity); |
| 5782 | } |
| 5783 | } |
| 5784 | |
| 5785 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5786 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5787 | */ |
| 5788 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5789 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5790 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5791 | long identity = Binder.clearCallingIdentity(); |
| 5792 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5793 | |
| 5794 | Phone phone = getPhone(subId); |
| 5795 | if (phone == null) { |
| 5796 | try { |
| 5797 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5798 | } catch (RemoteException e) { |
| 5799 | // ignore |
| 5800 | } |
| 5801 | return; |
| 5802 | } |
| 5803 | |
| 5804 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5805 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5806 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5807 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5808 | } finally { |
| 5809 | Binder.restoreCallingIdentity(identity); |
| 5810 | } |
| 5811 | } |
| 5812 | |
| 5813 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5814 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5815 | */ |
| 5816 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5817 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5818 | enforceModifyPermission(); |
| 5819 | long identity = Binder.clearCallingIdentity(); |
| 5820 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5821 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5822 | |
| 5823 | Phone phone = getPhone(subId); |
| 5824 | if (phone == null) { |
| 5825 | try { |
| 5826 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5827 | } catch (RemoteException e) { |
| 5828 | // ignore |
| 5829 | } |
| 5830 | return; |
| 5831 | } |
| 5832 | |
| 5833 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5834 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5835 | |
| 5836 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5843 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5844 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5845 | * @param subId id of the subscription |
| 5846 | * @param request contains the radio access networks with bands/channels to scan |
| 5847 | * @param messenger callback messenger for scan results or errors |
| 5848 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5849 | * @return the id of the requested scan which can be used to stop the scan. |
| 5850 | */ |
| 5851 | @Override |
| 5852 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5853 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5855 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5856 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5857 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5858 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5859 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5860 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5861 | .setCallingPid(Binder.getCallingPid()) |
| 5862 | .setCallingUid(Binder.getCallingUid()) |
| 5863 | .setMethod("requestNetworkScan") |
| 5864 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5865 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5866 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5867 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5868 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5869 | if (e != null) { |
| 5870 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5871 | throw e; |
| 5872 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5873 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5874 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5875 | } |
| 5876 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5877 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5878 | int callingUid = Binder.getCallingUid(); |
| 5879 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5880 | final long identity = Binder.clearCallingIdentity(); |
| 5881 | try { |
| 5882 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5883 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5884 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5885 | } finally { |
| 5886 | Binder.restoreCallingIdentity(identity); |
| 5887 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5888 | } |
| 5889 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5890 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5891 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5892 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5893 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5894 | boolean hasNetworkScanPermission = |
| 5895 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5896 | == PERMISSION_GRANTED; |
| 5897 | |
| 5898 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5899 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5900 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5904 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5905 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5906 | return new SecurityException("Specific channels must not be" |
| 5907 | + " scanned without location access."); |
| 5908 | } |
| 5909 | } |
| 5910 | } |
| 5911 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5912 | return null; |
| 5913 | } |
| 5914 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5915 | /** |
| 5916 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5917 | * |
| 5918 | * @param subId id of the subscription |
| 5919 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5920 | */ |
| 5921 | @Override |
| 5922 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5924 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5926 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5927 | final long identity = Binder.clearCallingIdentity(); |
| 5928 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5929 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | } finally { |
| 5931 | Binder.restoreCallingIdentity(identity); |
| 5932 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5933 | } |
| 5934 | |
| 5935 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5936 | * Get the calculated preferred network type. |
| 5937 | * Used for debugging incorrect network type. |
| 5938 | * |
| 5939 | * @return the preferred network type, defined in RILConstants.java. |
| 5940 | */ |
| 5941 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5942 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5943 | final Phone defaultPhone = getDefaultPhone(); |
| 5944 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5945 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5946 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5947 | } |
| 5948 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
| 5951 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5952 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | } finally { |
| 5954 | Binder.restoreCallingIdentity(identity); |
| 5955 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5956 | } |
| 5957 | |
| 5958 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5959 | * Get the preferred network type. |
| 5960 | * Used for device configuration by some CDMA operators. |
| 5961 | * |
| 5962 | * @return the preferred network type, defined in RILConstants.java. |
| 5963 | */ |
| 5964 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5965 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5966 | TelephonyPermissions |
| 5967 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5968 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | |
| 5970 | final long identity = Binder.clearCallingIdentity(); |
| 5971 | try { |
| 5972 | if (DBG) log("getPreferredNetworkType"); |
| 5973 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5974 | int networkType = (result != null ? result[0] : -1); |
| 5975 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5976 | return networkType; |
| 5977 | } finally { |
| 5978 | Binder.restoreCallingIdentity(identity); |
| 5979 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5980 | } |
| 5981 | |
| 5982 | /** |
| 5983 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5984 | * |
| 5985 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5986 | * @return true on success; false on any failure. |
| 5987 | */ |
| 5988 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5989 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5990 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5991 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | |
| 5993 | final long identity = Binder.clearCallingIdentity(); |
| 5994 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5995 | Boolean success = (Boolean) sendRequest( |
| 5996 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5997 | |
| 5998 | if (success) { |
| 5999 | Settings.Global.putInt(mApp.getContentResolver(), |
| 6000 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 6001 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6002 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 6003 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6004 | } finally { |
| 6005 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 6006 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6007 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6008 | |
| 6009 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6010 | * Get the allowed network types that store in the telephony provider. |
| 6011 | * |
| 6012 | * @param subId the id of the subscription. |
| 6013 | * @return allowedNetworkTypes the allowed network types. |
| 6014 | */ |
| 6015 | @Override |
| 6016 | public long getAllowedNetworkTypes(int subId) { |
| 6017 | TelephonyPermissions |
| 6018 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6019 | mApp, subId, "getAllowedNetworkTypes"); |
| 6020 | |
| 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
| 6023 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6024 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6025 | } finally { |
| 6026 | Binder.restoreCallingIdentity(identity); |
| 6027 | } |
| 6028 | } |
| 6029 | |
| 6030 | /** |
| 6031 | * Set the allowed network types. |
| 6032 | * |
| 6033 | * @param subId the id of the subscription. |
| 6034 | * @param allowedNetworkTypes the allowed network types. |
| 6035 | * @return true on success; false on any failure. |
| 6036 | */ |
| 6037 | @Override |
| 6038 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6040 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6041 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6042 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6043 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6044 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6045 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6046 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6047 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6048 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6049 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6050 | } |
| 6051 | |
| 6052 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6053 | * Get the allowed network types for certain reason. |
| 6054 | * |
| 6055 | * @param subId the id of the subscription. |
| 6056 | * @param reason the reason the allowed network type change is taking place |
| 6057 | * @return the allowed network types. |
| 6058 | */ |
| 6059 | @Override |
| 6060 | public long getAllowedNetworkTypesForReason(int subId, |
| 6061 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6062 | TelephonyPermissions |
| 6063 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6064 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6065 | final long identity = Binder.clearCallingIdentity(); |
| 6066 | try { |
| 6067 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6068 | } finally { |
| 6069 | Binder.restoreCallingIdentity(identity); |
| 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6074 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6075 | * @param subId subscription id of the sim card |
| 6076 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6077 | * This can be passed following states |
| 6078 | * <ol> |
| 6079 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6080 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6081 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6082 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6083 | * </ol> |
| 6084 | * @return operation result. |
| 6085 | */ |
| 6086 | @Override |
| 6087 | public int setNrDualConnectivityState(int subId, |
| 6088 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6090 | mApp, subId, "enableNRDualConnectivity"); |
| 6091 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6092 | final long identity = Binder.clearCallingIdentity(); |
| 6093 | try { |
| 6094 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6095 | nrDualConnectivityState, subId, |
| 6096 | workSource); |
| 6097 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6098 | return result; |
| 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
| 6101 | } |
| 6102 | } |
| 6103 | |
| 6104 | /** |
| 6105 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6106 | * @return true if dual connectivity is enabled else false |
| 6107 | */ |
| 6108 | @Override |
| 6109 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6110 | TelephonyPermissions |
| 6111 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6112 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6113 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6114 | final long identity = Binder.clearCallingIdentity(); |
| 6115 | try { |
| 6116 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6117 | null, subId, workSource); |
| 6118 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6119 | return isEnabled; |
| 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6126 | * get carrier bandwidth per primary and secondary carrier |
| 6127 | * @param subId subscription id of the sim card |
| 6128 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6129 | */ |
| 6130 | @Override |
| 6131 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6132 | TelephonyPermissions |
| 6133 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6134 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6135 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6136 | final long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
| 6138 | CarrierBandwidth carrierBandwidth = |
| 6139 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6140 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6141 | return carrierBandwidth; |
| 6142 | } finally { |
| 6143 | Binder.restoreCallingIdentity(identity); |
| 6144 | } |
| 6145 | } |
| 6146 | |
| 6147 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6148 | * Get the effective allowed network types on the device. |
| 6149 | * This API will return an intersection of allowed network types for all reasons, |
| 6150 | * including the configuration done through setAllowedNetworkTypes |
| 6151 | * |
| 6152 | * @param subId the id of the subscription. |
| 6153 | * @return the allowed network types |
| 6154 | */ |
| 6155 | @Override |
| 6156 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6157 | TelephonyPermissions |
| 6158 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6159 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | try { |
| 6162 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6163 | } finally { |
| 6164 | Binder.restoreCallingIdentity(identity); |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | /** |
| 6169 | * Set the allowed network types of the device and |
| 6170 | * provide the reason triggering the allowed network change. |
| 6171 | * |
| 6172 | * @param subId the id of the subscription. |
| 6173 | * @param reason the reason the allowed network type change is taking place |
| 6174 | * @param allowedNetworkTypes the allowed network types. |
| 6175 | * @return true on success; false on any failure. |
| 6176 | */ |
| 6177 | @Override |
| 6178 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6179 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6181 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | try { |
| 6184 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6185 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6186 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6187 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6188 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6189 | } finally { |
| 6190 | Binder.restoreCallingIdentity(identity); |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6195 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6196 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6197 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6198 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6199 | * @hide |
| 6200 | */ |
| 6201 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6202 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6204 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6205 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6207 | if (phone != null) { |
| 6208 | return phone.hasMatchedTetherApnSetting(); |
| 6209 | } else { |
| 6210 | return false; |
| 6211 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6212 | } finally { |
| 6213 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6214 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6215 | } |
| 6216 | |
| 6217 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6218 | * Enable or disable always reporting signal strength changes from radio. |
| 6219 | * |
| 6220 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6221 | */ |
| 6222 | @Override |
| 6223 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6224 | enforceModifyPermission(); |
| 6225 | enforceSystemCaller(); |
| 6226 | |
| 6227 | final long identity = Binder.clearCallingIdentity(); |
| 6228 | final Phone phone = getPhone(subId); |
| 6229 | try { |
| 6230 | if (phone != null) { |
| 6231 | if (DBG) { |
| 6232 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6233 | + " isEnable=" + isEnable); |
| 6234 | } |
| 6235 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6236 | } else { |
| 6237 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6238 | + subId); |
| 6239 | } |
| 6240 | } finally { |
| 6241 | Binder.restoreCallingIdentity(identity); |
| 6242 | } |
| 6243 | } |
| 6244 | |
| 6245 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6246 | * Get the user enabled state of Mobile Data. |
| 6247 | * |
| 6248 | * TODO: remove and use isUserDataEnabled. |
| 6249 | * This can't be removed now because some vendor codes |
| 6250 | * calls through ITelephony directly while they should |
| 6251 | * use TelephonyManager. |
| 6252 | * |
| 6253 | * @return true on enabled |
| 6254 | */ |
| 6255 | @Override |
| 6256 | public boolean getDataEnabled(int subId) { |
| 6257 | return isUserDataEnabled(subId); |
| 6258 | } |
| 6259 | |
| 6260 | /** |
| 6261 | * Get whether mobile data is enabled per user setting. |
| 6262 | * |
| 6263 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6264 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6265 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6266 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6267 | * |
| 6268 | * @return {@code true} if data is enabled else {@code false} |
| 6269 | */ |
| 6270 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6271 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6272 | try { |
| 6273 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6274 | null); |
| 6275 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6277 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6278 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6279 | |
| 6280 | final long identity = Binder.clearCallingIdentity(); |
| 6281 | try { |
| 6282 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6283 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6284 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6285 | if (phone != null) { |
| 6286 | boolean retVal = phone.isUserDataEnabled(); |
| 6287 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6288 | return retVal; |
| 6289 | } else { |
| 6290 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6291 | return false; |
| 6292 | } |
| 6293 | } finally { |
| 6294 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6299 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6300 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6301 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6302 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6303 | * @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] | 6304 | */ |
| 6305 | @Override |
| 6306 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6307 | try { |
| 6308 | try { |
| 6309 | mApp.enforceCallingOrSelfPermission( |
| 6310 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6311 | null); |
| 6312 | } catch (Exception e) { |
| 6313 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6314 | "isDataEnabled"); |
| 6315 | } |
| 6316 | } catch (Exception e) { |
| 6317 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6318 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | |
| 6320 | final long identity = Binder.clearCallingIdentity(); |
| 6321 | try { |
| 6322 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6323 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6324 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6325 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6326 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6328 | return retVal; |
| 6329 | } else { |
| 6330 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6331 | return false; |
| 6332 | } |
| 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6335 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6336 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6337 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6338 | /** |
| 6339 | * Check if data is enabled for a specific reason |
| 6340 | * @param subId Subscription index |
| 6341 | * @param reason the reason the data enable change is taking place |
| 6342 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6343 | */ |
| 6344 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6345 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6346 | @TelephonyManager.DataEnabledReason int reason) { |
| 6347 | try { |
| 6348 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6349 | null); |
| 6350 | } catch (Exception e) { |
| 6351 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6352 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | |
| 6356 | final long identity = Binder.clearCallingIdentity(); |
| 6357 | try { |
| 6358 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6359 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6360 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6361 | + " reason=" + reason); |
| 6362 | } |
| 6363 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6364 | if (phone != null) { |
| 6365 | boolean retVal; |
| 6366 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6367 | retVal = phone.isUserDataEnabled(); |
| 6368 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6369 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6370 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6371 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6372 | return retVal; |
| 6373 | } else { |
| 6374 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6375 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6376 | + subId + " retVal=false"); |
| 6377 | } |
| 6378 | return false; |
| 6379 | } |
| 6380 | } finally { |
| 6381 | Binder.restoreCallingIdentity(identity); |
| 6382 | } |
| 6383 | } |
| 6384 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6385 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6386 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6387 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6388 | // Skip the check if it's one of these special uids |
| 6389 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6390 | } |
| 6391 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6392 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6393 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6394 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6395 | || subController == null) return privilegeFromSim; |
| 6396 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6397 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6398 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6399 | |
| 6400 | final long identity = Binder.clearCallingIdentity(); |
| 6401 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6402 | int subId = phone.getSubId(); |
| 6403 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6404 | // A test override is in place for the privileges for this subId, so don't try to |
| 6405 | // read the subscription privileges. |
| 6406 | return privilegeFromSim; |
| 6407 | } |
| 6408 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6409 | SubscriptionManager subManager = (SubscriptionManager) |
| 6410 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6411 | for (String pkg : packages) { |
| 6412 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6413 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6414 | } |
| 6415 | } |
| 6416 | return privilegeFromSim; |
| 6417 | } finally { |
| 6418 | Binder.restoreCallingIdentity(identity); |
| 6419 | } |
| 6420 | } |
| 6421 | |
| 6422 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6423 | String pkgName) { |
| 6424 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6425 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6426 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6427 | || subController == null) return privilegeFromSim; |
| 6428 | |
| 6429 | final long identity = Binder.clearCallingIdentity(); |
| 6430 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6431 | int subId = phone.getSubId(); |
| 6432 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6433 | // A test override is in place for the privileges for this subId, so don't try to |
| 6434 | // read the subscription privileges. |
| 6435 | return privilegeFromSim; |
| 6436 | } |
| 6437 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6438 | SubscriptionManager subManager = (SubscriptionManager) |
| 6439 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6440 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6441 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6442 | } finally { |
| 6443 | Binder.restoreCallingIdentity(identity); |
| 6444 | } |
| 6445 | } |
| 6446 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6447 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6448 | public int getCarrierPrivilegeStatus(int subId) { |
| 6449 | final Phone phone = getPhone(subId); |
| 6450 | if (phone == null) { |
| 6451 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6452 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6453 | } |
| 6454 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6455 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6456 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6457 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6458 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6459 | |
| 6460 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6461 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6462 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6463 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6464 | |
| 6465 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6466 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6467 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6468 | final Phone phone = getPhone(subId); |
| 6469 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6470 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6471 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6472 | } |
| 6473 | UiccProfile profile = |
| 6474 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6475 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6476 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6477 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6478 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6479 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6480 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6481 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6485 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6486 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6487 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6491 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6492 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6493 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6494 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6495 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6496 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6497 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6498 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | @Override |
| 6502 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6503 | if (TextUtils.isEmpty(pkgName)) |
| 6504 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6505 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6506 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6507 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6508 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6509 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6510 | continue; |
| 6511 | } |
| 6512 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6513 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6514 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6515 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6516 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6517 | break; |
| 6518 | } |
| 6519 | } |
| 6520 | |
| 6521 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6522 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6523 | |
| 6524 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6525 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6526 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6527 | loge("phoneId " + phoneId + " is not valid."); |
| 6528 | return null; |
| 6529 | } |
| 6530 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6531 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6532 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6533 | return null ; |
| 6534 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6535 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6536 | } |
| 6537 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6538 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6539 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6540 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6541 | List<String> privilegedPackages = new ArrayList<>(); |
| 6542 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6543 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6544 | // has UICC in that slot. |
| 6545 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6546 | if (card.hasCarrierPrivilegeRules()) { |
| 6547 | if (packages == null) { |
| 6548 | // Only check packages in user 0 for now |
| 6549 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6550 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6551 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6552 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6553 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6554 | } |
| 6555 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6556 | PackageInfo pkgInfo = packages.get(p); |
| 6557 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6558 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6559 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6560 | privilegedPackages.add(pkgInfo.packageName); |
| 6561 | } |
| 6562 | } |
| 6563 | } |
| 6564 | } |
| 6565 | return privilegedPackages; |
| 6566 | } |
| 6567 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6568 | @Override |
| 6569 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6570 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6571 | |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6574 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6575 | try { |
| 6576 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6577 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6578 | } |
| 6579 | } finally { |
| 6580 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6581 | } |
| 6582 | return privilegedPackages; |
| 6583 | } |
| 6584 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6585 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6586 | final Phone phone = getPhone(subId); |
| 6587 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6588 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6589 | return null; |
| 6590 | } |
| 6591 | String iccId = card.getIccId(); |
| 6592 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6593 | return null; |
| 6594 | } |
| 6595 | return iccId; |
| 6596 | } |
| 6597 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6598 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6599 | public void setCallComposerStatus(int subId, int status) { |
| 6600 | enforceModifyPermission(); |
| 6601 | |
| 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | Phone phone = getPhone(subId); |
| 6605 | if (phone != null) { |
| 6606 | Phone defaultPhone = phone.getImsPhone(); |
| 6607 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6608 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6609 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6610 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6611 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6612 | } |
| 6613 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6614 | } catch (ImsException e) { |
| 6615 | throw new ServiceSpecificException(e.getCode()); |
| 6616 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6617 | Binder.restoreCallingIdentity(identity); |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | @Override |
| 6622 | public int getCallComposerStatus(int subId) { |
| 6623 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6624 | |
| 6625 | final long identity = Binder.clearCallingIdentity(); |
| 6626 | try { |
| 6627 | Phone phone = getPhone(subId); |
| 6628 | if (phone != null) { |
| 6629 | Phone defaultPhone = phone.getImsPhone(); |
| 6630 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6631 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6632 | return imsPhone.getCallComposerStatus(); |
| 6633 | } |
| 6634 | } |
| 6635 | } finally { |
| 6636 | Binder.restoreCallingIdentity(identity); |
| 6637 | } |
| 6638 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6639 | } |
| 6640 | |
| 6641 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6642 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6643 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6644 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6645 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6646 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6647 | final long identity = Binder.clearCallingIdentity(); |
| 6648 | try { |
| 6649 | final String iccId = getIccId(subId); |
| 6650 | final Phone phone = getPhone(subId); |
| 6651 | if (phone == null) { |
| 6652 | return false; |
| 6653 | } |
| 6654 | final String subscriberId = phone.getSubscriberId(); |
| 6655 | |
| 6656 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6657 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | + subscriberId + " to " + number); |
| 6659 | } |
| 6660 | |
| 6661 | if (TextUtils.isEmpty(iccId)) { |
| 6662 | return false; |
| 6663 | } |
| 6664 | |
| 6665 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6666 | |
| 6667 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6668 | if (alphaTag == null) { |
| 6669 | editor.remove(alphaTagPrefKey); |
| 6670 | } else { |
| 6671 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6672 | } |
| 6673 | |
| 6674 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6675 | // track all merged IMSIs based on line number |
| 6676 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6677 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6678 | if (number == null) { |
| 6679 | editor.remove(numberPrefKey); |
| 6680 | editor.remove(subscriberPrefKey); |
| 6681 | } else { |
| 6682 | editor.putString(numberPrefKey, number); |
| 6683 | editor.putString(subscriberPrefKey, subscriberId); |
| 6684 | } |
| 6685 | |
| 6686 | editor.commit(); |
| 6687 | return true; |
| 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6690 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6694 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6695 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6696 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6697 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6698 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6699 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6700 | return null; |
| 6701 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6702 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6703 | final long identity = Binder.clearCallingIdentity(); |
| 6704 | try { |
| 6705 | String iccId = getIccId(subId); |
| 6706 | if (iccId != null) { |
| 6707 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6708 | if (DBG_MERGE) { |
| 6709 | log("getLine1NumberForDisplay returning " |
| 6710 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6711 | } |
| 6712 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6713 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6715 | return null; |
| 6716 | } finally { |
| 6717 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6718 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6722 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6723 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6724 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6725 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6726 | return null; |
| 6727 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6729 | final long identity = Binder.clearCallingIdentity(); |
| 6730 | try { |
| 6731 | String iccId = getIccId(subId); |
| 6732 | if (iccId != null) { |
| 6733 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6734 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6735 | } |
| 6736 | return null; |
| 6737 | } finally { |
| 6738 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6739 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6740 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6741 | |
| 6742 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6743 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6744 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6745 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6746 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6747 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6748 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6749 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6750 | return null; |
| 6751 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6752 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6753 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6754 | // the process, where TelephonyManager was instantiated. |
| 6755 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6756 | final long identity = Binder.clearCallingIdentity(); |
| 6757 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6758 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6760 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6761 | |
| 6762 | // Figure out what subscribers are currently active |
| 6763 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6764 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6765 | // Only consider subs which match the current subId |
| 6766 | // This logic can be simplified. See b/131189269 for progress. |
| 6767 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6768 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6769 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | |
| 6771 | // First pass, find a number override for an active subscriber |
| 6772 | String mergeNumber = null; |
| 6773 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6774 | for (String key : prefs.keySet()) { |
| 6775 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6776 | final String subscriberId = (String) prefs.get(key); |
| 6777 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6778 | final String iccId = key.substring( |
| 6779 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6780 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6781 | mergeNumber = (String) prefs.get(numberKey); |
| 6782 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6783 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | + " for active subscriber " + subscriberId); |
| 6785 | } |
| 6786 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6787 | break; |
| 6788 | } |
| 6789 | } |
| 6790 | } |
| 6791 | } |
| 6792 | |
| 6793 | // Shortcut when no active merged subscribers |
| 6794 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6795 | return null; |
| 6796 | } |
| 6797 | |
| 6798 | // Second pass, find all subscribers under that line override |
| 6799 | final ArraySet<String> result = new ArraySet<>(); |
| 6800 | for (String key : prefs.keySet()) { |
| 6801 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6802 | final String number = (String) prefs.get(key); |
| 6803 | if (mergeNumber.equals(number)) { |
| 6804 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6805 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6806 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6807 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6808 | result.add(subscriberId); |
| 6809 | } |
| 6810 | } |
| 6811 | } |
| 6812 | } |
| 6813 | |
| 6814 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6815 | Arrays.sort(resultArray); |
| 6816 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6817 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6819 | } |
| 6820 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6821 | } finally { |
| 6822 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6823 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6827 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6828 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6829 | |
| 6830 | final long identity = Binder.clearCallingIdentity(); |
| 6831 | try { |
| 6832 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6833 | TelephonyManager.class); |
| 6834 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6835 | if (subscriberId == null) { |
| 6836 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6837 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6838 | + subId); |
| 6839 | } |
| 6840 | return null; |
| 6841 | } |
| 6842 | |
| 6843 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6844 | .getSubscriptionInfo(subId); |
| 6845 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6846 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6847 | if (groupUuid == null) { |
| 6848 | return new String[]{subscriberId}; |
| 6849 | } |
| 6850 | |
| 6851 | // Get all subscriberIds from the group. |
| 6852 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6853 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6854 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6855 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6856 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6857 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6858 | if (subscriberId != null) { |
| 6859 | mergedSubscriberIds.add(subscriberId); |
| 6860 | } |
| 6861 | } |
| 6862 | |
| 6863 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6864 | } finally { |
| 6865 | Binder.restoreCallingIdentity(identity); |
| 6866 | |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6871 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6872 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6873 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | |
| 6875 | final long identity = Binder.clearCallingIdentity(); |
| 6876 | try { |
| 6877 | final Phone phone = getPhone(subId); |
| 6878 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6882 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6883 | |
| 6884 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6885 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6886 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6887 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6888 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6889 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6890 | |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | try { |
| 6893 | final Phone phone = getPhone(subId); |
| 6894 | if (phone == null) { |
| 6895 | return false; |
| 6896 | } |
| 6897 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6898 | cdmaNonRoamingList); |
| 6899 | } finally { |
| 6900 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6901 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6905 | @Deprecated |
| 6906 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6907 | enforceModifyPermission(); |
| 6908 | |
| 6909 | int returnValue = 0; |
| 6910 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6911 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6912 | if(result.exception == null) { |
| 6913 | if (result.result != null) { |
| 6914 | byte[] responseData = (byte[])(result.result); |
| 6915 | if(responseData.length > oemResp.length) { |
| 6916 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6917 | responseData.length + "bytes. Buffer Size is " + |
| 6918 | oemResp.length + "bytes."); |
| 6919 | } |
| 6920 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6921 | returnValue = responseData.length; |
| 6922 | } |
| 6923 | } else { |
| 6924 | CommandException ex = (CommandException) result.exception; |
| 6925 | returnValue = ex.getCommandError().ordinal(); |
| 6926 | if(returnValue > 0) returnValue *= -1; |
| 6927 | } |
| 6928 | } catch (RuntimeException e) { |
| 6929 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6930 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6931 | if(returnValue > 0) returnValue *= -1; |
| 6932 | } |
| 6933 | |
| 6934 | return returnValue; |
| 6935 | } |
| 6936 | |
| 6937 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6938 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6939 | try { |
| 6940 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6941 | } catch (RuntimeException e) { |
| 6942 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6943 | } |
| 6944 | } |
| 6945 | |
| 6946 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6947 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6948 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6949 | try { |
| 6950 | TelephonyPermissions |
| 6951 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6952 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6953 | } catch (SecurityException e) { |
| 6954 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6955 | throw e; |
| 6956 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6957 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6958 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6959 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6960 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6961 | final long identity = Binder.clearCallingIdentity(); |
| 6962 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6963 | TelephonyPermissions |
| 6964 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6965 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6966 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | } finally { |
| 6968 | Binder.restoreCallingIdentity(identity); |
| 6969 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6970 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6971 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6972 | |
| 6973 | @Override |
| 6974 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6975 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6976 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | |
| 6978 | final long identity = Binder.clearCallingIdentity(); |
| 6979 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6980 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6981 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | } finally { |
| 6983 | Binder.restoreCallingIdentity(identity); |
| 6984 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6985 | } |
| 6986 | |
| 6987 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6988 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6989 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6990 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6991 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6992 | return false; |
| 6993 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | final long identity = Binder.clearCallingIdentity(); |
| 6996 | try { |
| 6997 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6998 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6999 | // In the long run, we may instead need to check if there exists a connection service |
| 7000 | // which can support video calling. |
| 7001 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7002 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | return imsManager.isVtEnabledByPlatform() |
| 7004 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7005 | && imsManager.isVtEnabledByUser(); |
| 7006 | } finally { |
| 7007 | Binder.restoreCallingIdentity(identity); |
| 7008 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7009 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7010 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7011 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7012 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7013 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7014 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7015 | mApp, subId, callingPackage, callingFeatureId, |
| 7016 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7017 | return false; |
| 7018 | } |
| 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | CarrierConfigManager configManager = |
| 7023 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7024 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7025 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7026 | } finally { |
| 7027 | Binder.restoreCallingIdentity(identity); |
| 7028 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7029 | } |
| 7030 | |
| 7031 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7032 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7033 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7034 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | return false; |
| 7036 | } |
| 7037 | |
| 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
| 7040 | CarrierConfigManager configManager = |
| 7041 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7042 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7044 | } finally { |
| 7045 | Binder.restoreCallingIdentity(identity); |
| 7046 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7047 | } |
| 7048 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7049 | @Override |
| 7050 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7051 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7052 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
| 7055 | @Override |
| 7056 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | final long identity = Binder.clearCallingIdentity(); |
| 7058 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7059 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7060 | } finally { |
| 7061 | Binder.restoreCallingIdentity(identity); |
| 7062 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7065 | /** |
| 7066 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7067 | * support for the feature and device firmware support. |
| 7068 | * |
| 7069 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7070 | */ |
| 7071 | @Override |
| 7072 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7074 | final Phone phone = getPhone(subscriptionId); |
| 7075 | if (phone == null) { |
| 7076 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7077 | return false; |
| 7078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7080 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7082 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7083 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7084 | return isCarrierSupported && isDeviceSupported; |
| 7085 | } finally { |
| 7086 | Binder.restoreCallingIdentity(identity); |
| 7087 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7088 | } |
| 7089 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7090 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7091 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7092 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7093 | * 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] | 7094 | */ |
| 7095 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7096 | final long identity = Binder.clearCallingIdentity(); |
| 7097 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7098 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7099 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7100 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7101 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7102 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7103 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7104 | } finally { |
| 7105 | Binder.restoreCallingIdentity(identity); |
| 7106 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7107 | } |
| 7108 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7109 | @Deprecated |
| 7110 | @Override |
| 7111 | public String getDeviceId(String callingPackage) { |
| 7112 | return getDeviceIdWithFeature(callingPackage, null); |
| 7113 | } |
| 7114 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7115 | /** |
| 7116 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7117 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7118 | * |
| 7119 | * <p>Requires Permission: |
| 7120 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7121 | */ |
| 7122 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7123 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7124 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7125 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7126 | return null; |
| 7127 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7128 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7129 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7130 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7131 | return null; |
| 7132 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7133 | |
| 7134 | final long identity = Binder.clearCallingIdentity(); |
| 7135 | try { |
| 7136 | return phone.getDeviceId(); |
| 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
| 7139 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7140 | } |
| 7141 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7142 | /** |
| 7143 | * {@hide} |
| 7144 | * Returns the IMS Registration Status on a particular subid |
| 7145 | * |
| 7146 | * @param subId |
| 7147 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7148 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7149 | Phone phone = getPhone(subId); |
| 7150 | if (phone != null) { |
| 7151 | return phone.isImsRegistered(); |
| 7152 | } else { |
| 7153 | return false; |
| 7154 | } |
| 7155 | } |
| 7156 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7157 | @Override |
| 7158 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | final long identity = Binder.clearCallingIdentity(); |
| 7160 | try { |
| 7161 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7162 | } finally { |
| 7163 | Binder.restoreCallingIdentity(identity); |
| 7164 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7165 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7166 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7167 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7168 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7169 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7170 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7171 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7172 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7173 | } |
| 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7177 | } finally { |
| 7178 | Binder.restoreCallingIdentity(identity); |
| 7179 | } |
| 7180 | } |
| 7181 | |
| 7182 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7183 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7184 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7185 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7186 | final long identity = Binder.clearCallingIdentity(); |
| 7187 | try { |
| 7188 | Phone phone = getPhone(subscriptionId); |
| 7189 | if (phone == null) { |
| 7190 | return null; |
| 7191 | } |
| 7192 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7193 | } finally { |
| 7194 | Binder.restoreCallingIdentity(identity); |
| 7195 | } |
| 7196 | } |
| 7197 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7198 | /** |
| 7199 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7200 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7201 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7202 | final long identity = Binder.clearCallingIdentity(); |
| 7203 | try { |
| 7204 | Phone phone = getPhone(subId); |
| 7205 | if (phone != null) { |
| 7206 | return phone.isWifiCallingEnabled(); |
| 7207 | } else { |
| 7208 | return false; |
| 7209 | } |
| 7210 | } finally { |
| 7211 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7212 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7213 | } |
| 7214 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7215 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7216 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7217 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7218 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | final long identity = Binder.clearCallingIdentity(); |
| 7220 | try { |
| 7221 | Phone phone = getPhone(subId); |
| 7222 | if (phone != null) { |
| 7223 | return phone.isVideoEnabled(); |
| 7224 | } else { |
| 7225 | return false; |
| 7226 | } |
| 7227 | } finally { |
| 7228 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7229 | } |
| 7230 | } |
| 7231 | |
| 7232 | /** |
| 7233 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7234 | * defined in {@link ImsRegistrationImplBase}. |
| 7235 | */ |
| 7236 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
| 7239 | Phone phone = getPhone(subId); |
| 7240 | if (phone != null) { |
| 7241 | return phone.getImsRegistrationTech(); |
| 7242 | } else { |
| 7243 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7244 | } |
| 7245 | } finally { |
| 7246 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7247 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7248 | } |
| 7249 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7250 | @Override |
| 7251 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7252 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7253 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7254 | return; |
| 7255 | } |
| 7256 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7257 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7258 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7259 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7260 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7261 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7262 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7263 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7264 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7265 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7266 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7267 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7268 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7269 | // There has been issues when Sms raw table somehow stores orphan |
| 7270 | // fragments. They lead to garbled message when new fragments come |
| 7271 | // in and combined with those stale ones. In case this happens again, |
| 7272 | // user can reset all network settings which will clean up this table. |
| 7273 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7274 | // Clean up IMS settings as well here. |
| 7275 | int slotId = getSlotIndex(subId); |
| 7276 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7277 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7278 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7279 | |
| 7280 | // Erase modem config if erase modem on network setting is enabled. |
| 7281 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7282 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7283 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7284 | sendEraseModemConfig(getDefaultPhone()); |
| 7285 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7286 | } finally { |
| 7287 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7288 | } |
| 7289 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7290 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7291 | private void cleanUpSmsRawTable(Context context) { |
| 7292 | ContentResolver resolver = context.getContentResolver(); |
| 7293 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7294 | resolver.delete(uri, null, null); |
| 7295 | } |
| 7296 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7297 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7298 | public String getSimLocaleForSubscriber(int subId) { |
| 7299 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7300 | final Phone phone = getPhone(subId); |
| 7301 | if (phone == null) { |
| 7302 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7303 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7307 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7308 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7309 | if (info == null) { |
| 7310 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7311 | return null; |
| 7312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7314 | // preferences (EF-PL and EF-LI)... |
| 7315 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7316 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7317 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7318 | if (localeFromDefaultSim != null) { |
| 7319 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7320 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7321 | + localeFromDefaultSim); |
| 7322 | return localeFromDefaultSim.toLanguageTag(); |
| 7323 | } else { |
| 7324 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7325 | } |
| 7326 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7327 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7328 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7329 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7330 | // the SIM and carrier preferences does not include a country we add the country |
| 7331 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7332 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7334 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | return mccLocale.toLanguageTag(); |
| 7336 | } |
| 7337 | |
| 7338 | if (DBG) log("No locale found - returning null"); |
| 7339 | return null; |
| 7340 | } finally { |
| 7341 | Binder.restoreCallingIdentity(identity); |
| 7342 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7346 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7347 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7348 | } |
| 7349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | /** |
| 7351 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7352 | */ |
| 7353 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7354 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7355 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7356 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7357 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7358 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7359 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7360 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7361 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7362 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7363 | * representing the state of the modem. |
| 7364 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7365 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7366 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7367 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7368 | */ |
| 7369 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7370 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7371 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7372 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | |
| 7374 | final long identity = Binder.clearCallingIdentity(); |
| 7375 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7376 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | } finally { |
| 7378 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7379 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7380 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7381 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7382 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7383 | // less than total activity duration. |
| 7384 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7385 | if (info == null) { |
| 7386 | return false; |
| 7387 | } |
| 7388 | int activityDurationMs = |
| 7389 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7390 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7391 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7392 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7393 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7394 | } |
| 7395 | return (info.isValid() |
| 7396 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7397 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7398 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7399 | && (totalTxTimeMs <= activityDurationMs)); |
| 7400 | } |
| 7401 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7402 | /** |
| 7403 | * {@hide} |
| 7404 | * Returns the service state information on specified subscription. |
| 7405 | */ |
| 7406 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7407 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7408 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7409 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7410 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7411 | return null; |
| 7412 | } |
| 7413 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7414 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7415 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7416 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7417 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7418 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7419 | .setCallingPid(Binder.getCallingPid()) |
| 7420 | .setCallingUid(Binder.getCallingUid()) |
| 7421 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7422 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7423 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7424 | .build()); |
| 7425 | |
| 7426 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7427 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7428 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7429 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7430 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7431 | .setCallingPid(Binder.getCallingPid()) |
| 7432 | .setCallingUid(Binder.getCallingUid()) |
| 7433 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7434 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7435 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7436 | .build()); |
| 7437 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7438 | boolean hasFinePermission = |
| 7439 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7440 | boolean hasCoarsePermission = |
| 7441 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7442 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | final long identity = Binder.clearCallingIdentity(); |
| 7444 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7445 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7446 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7447 | Rlog.d(LOG_TAG, |
| 7448 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7449 | return null; |
| 7450 | } |
| 7451 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | final Phone phone = getPhone(subId); |
| 7453 | if (phone == null) { |
| 7454 | return null; |
| 7455 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7456 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7457 | ServiceState ss = phone.getServiceState(); |
| 7458 | |
| 7459 | // Scrub out the location info in ServiceState depending on what level of access |
| 7460 | // the caller has. |
| 7461 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7462 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7463 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | } finally { |
| 7465 | Binder.restoreCallingIdentity(identity); |
| 7466 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7467 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7468 | |
| 7469 | /** |
| 7470 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7471 | * |
| 7472 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7473 | * voicemail ringtone. |
| 7474 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7475 | * PhoneAccount. |
| 7476 | */ |
| 7477 | @Override |
| 7478 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | final long identity = Binder.clearCallingIdentity(); |
| 7480 | try { |
| 7481 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7482 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7483 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7485 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7490 | } |
| 7491 | |
| 7492 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7493 | * Sets the per-account voicemail ringtone. |
| 7494 | * |
| 7495 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7496 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7497 | * |
| 7498 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7499 | * voicemail ringtone. |
| 7500 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7501 | * PhoneAccount. |
| 7502 | */ |
| 7503 | @Override |
| 7504 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7505 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7506 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7507 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7508 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7509 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7510 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7511 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7512 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7513 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7514 | |
| 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
| 7517 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7518 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7519 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | } |
| 7521 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7522 | } finally { |
| 7523 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7524 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7528 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7529 | * |
| 7530 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7531 | * voicemail vibration setting. |
| 7532 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7533 | */ |
| 7534 | @Override |
| 7535 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | final long identity = Binder.clearCallingIdentity(); |
| 7537 | try { |
| 7538 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7539 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7540 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7542 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7544 | } finally { |
| 7545 | Binder.restoreCallingIdentity(identity); |
| 7546 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7547 | } |
| 7548 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7549 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7550 | * Sets the per-account voicemail vibration. |
| 7551 | * |
| 7552 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7553 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7554 | * |
| 7555 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7556 | * voicemail vibration setting. |
| 7557 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7558 | * specific PhoneAccount. |
| 7559 | */ |
| 7560 | @Override |
| 7561 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7562 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7563 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7564 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7565 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7566 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7568 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7569 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7570 | } |
| 7571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | final long identity = Binder.clearCallingIdentity(); |
| 7573 | try { |
| 7574 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7575 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7576 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | } |
| 7578 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7579 | } finally { |
| 7580 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7581 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7582 | } |
| 7583 | |
| 7584 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7585 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7586 | * |
| 7587 | * @throws SecurityException if the caller does not have the required permission |
| 7588 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7589 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7590 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7591 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7595 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7596 | * permission. |
| 7597 | * |
| 7598 | * @throws SecurityException if the caller does not have the required permission |
| 7599 | */ |
| 7600 | private void enforceSendSmsPermission() { |
| 7601 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7602 | } |
| 7603 | |
| 7604 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7605 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7606 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7607 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7608 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7609 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7613 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7614 | if (componentName == null) { |
| 7615 | throw new SecurityException( |
| 7616 | "Caller not current active visual voicemail package[null]"); |
| 7617 | } |
| 7618 | String vvmPackage = componentName.getPackageName(); |
| 7619 | if (!callingPackage.equals(vvmPackage)) { |
| 7620 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7621 | + vvmPackage + "]"); |
| 7622 | } |
| 7623 | } finally { |
| 7624 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7625 | } |
| 7626 | } |
| 7627 | |
| 7628 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7629 | * Return the application ID for the app type. |
| 7630 | * |
| 7631 | * @param subId the subscription ID that this request applies to. |
| 7632 | * @param appType the uicc app type. |
| 7633 | * @return Application ID for specificied app type, or null if no uicc. |
| 7634 | */ |
| 7635 | @Override |
| 7636 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7637 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7638 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7639 | |
| 7640 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7641 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | if (phone == null) { |
| 7643 | return null; |
| 7644 | } |
| 7645 | String aid = null; |
| 7646 | try { |
| 7647 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7648 | .getApplicationByType(appType).getAid(); |
| 7649 | } catch (Exception e) { |
| 7650 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7651 | } |
| 7652 | return aid; |
| 7653 | } finally { |
| 7654 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7655 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7656 | } |
| 7657 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7658 | /** |
| 7659 | * Return the Electronic Serial Number. |
| 7660 | * |
| 7661 | * @param subId the subscription ID that this request applies to. |
| 7662 | * @return ESN or null if error. |
| 7663 | */ |
| 7664 | @Override |
| 7665 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7666 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7667 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7668 | |
| 7669 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7670 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7671 | if (phone == null) { |
| 7672 | return null; |
| 7673 | } |
| 7674 | String esn = null; |
| 7675 | try { |
| 7676 | esn = phone.getEsn(); |
| 7677 | } catch (Exception e) { |
| 7678 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7679 | } |
| 7680 | return esn; |
| 7681 | } finally { |
| 7682 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7683 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7684 | } |
| 7685 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7686 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7687 | * Return the Preferred Roaming List Version. |
| 7688 | * |
| 7689 | * @param subId the subscription ID that this request applies to. |
| 7690 | * @return PRLVersion or null if error. |
| 7691 | */ |
| 7692 | @Override |
| 7693 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7694 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7695 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7696 | |
| 7697 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7698 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | if (phone == null) { |
| 7700 | return null; |
| 7701 | } |
| 7702 | String cdmaPrlVersion = null; |
| 7703 | try { |
| 7704 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7705 | } catch (Exception e) { |
| 7706 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7707 | } |
| 7708 | return cdmaPrlVersion; |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7711 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7712 | } |
| 7713 | |
| 7714 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7715 | * Get snapshot of Telephony histograms |
| 7716 | * @return List of Telephony histograms |
| 7717 | * @hide |
| 7718 | */ |
| 7719 | @Override |
| 7720 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7722 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | |
| 7724 | final long identity = Binder.clearCallingIdentity(); |
| 7725 | try { |
| 7726 | return RIL.getTelephonyRILTimingHistograms(); |
| 7727 | } finally { |
| 7728 | Binder.restoreCallingIdentity(identity); |
| 7729 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7730 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7731 | |
| 7732 | /** |
| 7733 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7734 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7735 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7736 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7737 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7738 | * @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] | 7739 | */ |
| 7740 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7741 | @TelephonyManager.SetCarrierRestrictionResult |
| 7742 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7743 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7744 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7745 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7746 | if (carrierRestrictionRules == null) { |
| 7747 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7748 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7750 | final long identity = Binder.clearCallingIdentity(); |
| 7751 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7752 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7753 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
| 7756 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7757 | } |
| 7758 | |
| 7759 | /** |
| 7760 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7761 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7762 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7763 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7764 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7765 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7766 | */ |
| 7767 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7768 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7769 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7770 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7771 | |
| 7772 | final long identity = Binder.clearCallingIdentity(); |
| 7773 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7774 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7775 | if (response instanceof CarrierRestrictionRules) { |
| 7776 | return (CarrierRestrictionRules) response; |
| 7777 | } |
| 7778 | // Response is an Exception of some kind, |
| 7779 | // which is signalled to the user as a NULL retval |
| 7780 | return null; |
| 7781 | } catch (Exception e) { |
| 7782 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7783 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | } finally { |
| 7785 | Binder.restoreCallingIdentity(identity); |
| 7786 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7787 | } |
| 7788 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7789 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7790 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7791 | * @param subId the subscription ID that this action applies to. |
| 7792 | * @param enabled control enable or disable radio. |
| 7793 | * {@hide} |
| 7794 | */ |
| 7795 | @Override |
| 7796 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7797 | enforceModifyPermission(); |
| 7798 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7801 | if (phone == null) { |
| 7802 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7803 | return; |
| 7804 | } |
| 7805 | try { |
| 7806 | phone.carrierActionSetRadioEnabled(enabled); |
| 7807 | } catch (Exception e) { |
| 7808 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7814 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7815 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7816 | * network status based on which carrier apps could apply actions accordingly, |
| 7817 | * enable/disable default url handler for example. |
| 7818 | * |
| 7819 | * @param subId the subscription ID that this action applies to. |
| 7820 | * @param report control start/stop reporting the default network status. |
| 7821 | * {@hide} |
| 7822 | */ |
| 7823 | @Override |
| 7824 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7825 | enforceModifyPermission(); |
| 7826 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | |
| 7828 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7829 | if (phone == null) { |
| 7830 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7831 | return; |
| 7832 | } |
| 7833 | try { |
| 7834 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7835 | } catch (Exception e) { |
| 7836 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7843 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7844 | * @param subId the subscription ID that this action applies to. |
| 7845 | * {@hide} |
| 7846 | */ |
| 7847 | @Override |
| 7848 | public void carrierActionResetAll(int subId) { |
| 7849 | enforceModifyPermission(); |
| 7850 | final Phone phone = getPhone(subId); |
| 7851 | if (phone == null) { |
| 7852 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7853 | return; |
| 7854 | } |
| 7855 | try { |
| 7856 | phone.carrierActionResetAll(); |
| 7857 | } catch (Exception e) { |
| 7858 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7859 | } |
| 7860 | } |
| 7861 | |
| 7862 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7863 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7864 | * bug report is being generated. |
| 7865 | */ |
| 7866 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7867 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7868 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7869 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7870 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7871 | + Binder.getCallingPid() |
| 7872 | + ", uid=" + Binder.getCallingUid() |
| 7873 | + "without permission " |
| 7874 | + android.Manifest.permission.DUMP); |
| 7875 | return; |
| 7876 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7877 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7878 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7879 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7880 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7881 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7882 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7883 | @NonNull String[] args) { |
| 7884 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7885 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7886 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7887 | } |
| 7888 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7889 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7890 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7891 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7892 | * @param reason the reason the data enable change is taking place |
| 7893 | * @param enabled True if enabling the data, otherwise disabling. |
| 7894 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7895 | */ |
| 7896 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7897 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7898 | boolean enabled) { |
| 7899 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7900 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7901 | try { |
| 7902 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7903 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7904 | } catch (SecurityException se) { |
| 7905 | enforceModifyPermission(); |
| 7906 | } |
| 7907 | } else { |
| 7908 | enforceModifyPermission(); |
| 7909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | |
| 7911 | final long identity = Binder.clearCallingIdentity(); |
| 7912 | try { |
| 7913 | Phone phone = getPhone(subId); |
| 7914 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7915 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7916 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7917 | } else { |
| 7918 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7919 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7920 | } |
| 7921 | } finally { |
| 7922 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7923 | } |
| 7924 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7925 | |
| 7926 | /** |
| 7927 | * Get Client request stats |
| 7928 | * @return List of Client Request Stats |
| 7929 | * @hide |
| 7930 | */ |
| 7931 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7932 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7933 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7934 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7935 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7936 | return null; |
| 7937 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7938 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7939 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7940 | final long identity = Binder.clearCallingIdentity(); |
| 7941 | try { |
| 7942 | if (phone != null) { |
| 7943 | return phone.getClientRequestStats(); |
| 7944 | } |
| 7945 | |
| 7946 | return null; |
| 7947 | } finally { |
| 7948 | Binder.restoreCallingIdentity(identity); |
| 7949 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7950 | } |
| 7951 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7952 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7953 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7954 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7955 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7956 | |
| 7957 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7958 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7959 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7960 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7961 | * @param state State of SIM (power down, power up, pass through) |
| 7962 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7963 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7964 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7965 | * |
| 7966 | **/ |
| 7967 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7968 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7969 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7970 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7971 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7972 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7973 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7974 | final long identity = Binder.clearCallingIdentity(); |
| 7975 | try { |
| 7976 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7977 | phone.setSimPowerState(state, null, workSource); |
| 7978 | } |
| 7979 | } finally { |
| 7980 | Binder.restoreCallingIdentity(identity); |
| 7981 | } |
| 7982 | } |
| 7983 | |
| 7984 | /** |
| 7985 | * Set SIM card power state. |
| 7986 | * |
| 7987 | * @param slotIndex SIM slot id. |
| 7988 | * @param state State of SIM (power down, power up, pass through) |
| 7989 | * @param callback callback to trigger after success or failure |
| 7990 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7991 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7992 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7993 | * |
| 7994 | **/ |
| 7995 | @Override |
| 7996 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7997 | IIntegerConsumer callback) { |
| 7998 | enforceModifyPermission(); |
| 7999 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8000 | |
| 8001 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8002 | |
| 8003 | final long identity = Binder.clearCallingIdentity(); |
| 8004 | try { |
| 8005 | if (phone != null) { |
| 8006 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8007 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8008 | } |
| 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8011 | } |
| 8012 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8013 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8014 | private boolean isUssdApiAllowed(int subId) { |
| 8015 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8016 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8017 | if (configManager == null) { |
| 8018 | return false; |
| 8019 | } |
| 8020 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8021 | if (pb == null) { |
| 8022 | return false; |
| 8023 | } |
| 8024 | return pb.getBoolean( |
| 8025 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8026 | } |
| 8027 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8028 | /** |
| 8029 | * Check if phone is in emergency callback mode |
| 8030 | * @return true if phone is in emergency callback mode |
| 8031 | * @param subId sub id |
| 8032 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8033 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8034 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8035 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8036 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8037 | |
| 8038 | final long identity = Binder.clearCallingIdentity(); |
| 8039 | try { |
| 8040 | if (phone != null) { |
| 8041 | return phone.isInEcm(); |
| 8042 | } else { |
| 8043 | return false; |
| 8044 | } |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8047 | } |
| 8048 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8049 | |
| 8050 | /** |
| 8051 | * Get the current signal strength information for the given subscription. |
| 8052 | * Because this information is not updated when the device is in a low power state |
| 8053 | * it should not be relied-upon to be current. |
| 8054 | * @param subId Subscription index |
| 8055 | * @return the most recent cached signal strength info from the modem |
| 8056 | */ |
| 8057 | @Override |
| 8058 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8059 | final long identity = Binder.clearCallingIdentity(); |
| 8060 | try { |
| 8061 | Phone p = getPhone(subId); |
| 8062 | if (p == null) { |
| 8063 | return null; |
| 8064 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8065 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8066 | return p.getSignalStrength(); |
| 8067 | } finally { |
| 8068 | Binder.restoreCallingIdentity(identity); |
| 8069 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8070 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8071 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8072 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8073 | * Get the current modem radio state for the given slot. |
| 8074 | * @param slotIndex slot index. |
| 8075 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8076 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8077 | * @return the current radio power state from the modem |
| 8078 | */ |
| 8079 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8080 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8081 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8082 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8083 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8084 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8085 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8086 | } |
| 8087 | |
| 8088 | final long identity = Binder.clearCallingIdentity(); |
| 8089 | try { |
| 8090 | return phone.getRadioPowerState(); |
| 8091 | } finally { |
| 8092 | Binder.restoreCallingIdentity(identity); |
| 8093 | } |
| 8094 | } |
| 8095 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8096 | } |
| 8097 | |
| 8098 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8099 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8100 | * |
| 8101 | * <p>Requires one of the following permissions: |
| 8102 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8103 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8104 | * privileges. |
| 8105 | * |
| 8106 | * @param subId subscription id |
| 8107 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8108 | * {@code false}. |
| 8109 | */ |
| 8110 | @Override |
| 8111 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8112 | try { |
| 8113 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8114 | null); |
| 8115 | } catch (Exception e) { |
| 8116 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8117 | mApp, subId, "isDataRoamingEnabled"); |
| 8118 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8119 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8120 | boolean isEnabled = false; |
| 8121 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8122 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8123 | Phone phone = getPhone(subId); |
| 8124 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8127 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8128 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8129 | } |
| 8130 | |
| 8131 | |
| 8132 | /** |
| 8133 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8134 | * |
| 8135 | * <p> Requires permission: |
| 8136 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8137 | * privileges. |
| 8138 | * |
| 8139 | * @param subId subscription id |
| 8140 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8141 | */ |
| 8142 | @Override |
| 8143 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8145 | mApp, subId, "setDataRoamingEnabled"); |
| 8146 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8147 | final long identity = Binder.clearCallingIdentity(); |
| 8148 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8149 | Phone phone = getPhone(subId); |
| 8150 | if (phone != null) { |
| 8151 | phone.setDataRoamingEnabled(isEnabled); |
| 8152 | } |
| 8153 | } finally { |
| 8154 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8155 | } |
| 8156 | } |
| 8157 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8158 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8159 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8160 | TelephonyPermissions |
| 8161 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8162 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8163 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8164 | boolean isAllowed = true; |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8167 | Phone phone = getPhone(subId); |
| 8168 | if (phone != null) { |
| 8169 | isAllowed = phone.isCspPlmnEnabled(); |
| 8170 | } |
| 8171 | } finally { |
| 8172 | Binder.restoreCallingIdentity(identity); |
| 8173 | } |
| 8174 | return isAllowed; |
| 8175 | } |
| 8176 | |
| 8177 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8178 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8179 | // Verify that tha callingPackage belongs to the calling UID |
| 8180 | mApp.getSystemService(AppOpsManager.class) |
| 8181 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8182 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8183 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8184 | try { |
| 8185 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8186 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8187 | } catch (SecurityException e) { |
| 8188 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8189 | // has carrier privileges on an active UICC |
| 8190 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8191 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8192 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8193 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8194 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8195 | |
| 8196 | final long identity = Binder.clearCallingIdentity(); |
| 8197 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8198 | UiccController uiccController = UiccController.getInstance(); |
| 8199 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8200 | if (hasReadPermission) { |
| 8201 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8202 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8203 | |
| 8204 | // Remove private info if the caller doesn't have access |
| 8205 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8206 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8207 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8208 | // is available |
| 8209 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8210 | if (card == null || card.getUiccProfile() == null) { |
| 8211 | // assume no access if the card or profile is unavailable |
| 8212 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8213 | continue; |
| 8214 | } |
| 8215 | UiccProfile profile = card.getUiccProfile(); |
| 8216 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8217 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8218 | filteredInfos.add(cardInfo); |
| 8219 | } else { |
| 8220 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8221 | } |
| 8222 | } |
| 8223 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
| 8226 | } |
| 8227 | } |
| 8228 | |
| 8229 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8230 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8231 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8232 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8233 | final long identity = Binder.clearCallingIdentity(); |
| 8234 | try { |
| 8235 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8236 | if (slots == null) { |
| 8237 | Rlog.i(LOG_TAG, "slots is null."); |
| 8238 | return null; |
| 8239 | } |
| 8240 | |
| 8241 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8242 | for (int i = 0; i < slots.length; i++) { |
| 8243 | UiccSlot slot = slots[i]; |
| 8244 | if (slot == null) { |
| 8245 | continue; |
| 8246 | } |
| 8247 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8248 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8249 | UiccCard card = slot.getUiccCard(); |
| 8250 | if (card != null) { |
| 8251 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8252 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8253 | cardId = slot.getEid(); |
| 8254 | if (TextUtils.isEmpty(cardId)) { |
| 8255 | cardId = slot.getIccId(); |
| 8256 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | } |
| 8258 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8259 | if (cardId != null) { |
| 8260 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8261 | // if cardId is an EID, it's all digits so this is fine |
| 8262 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8263 | } |
| 8264 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8265 | int cardState = 0; |
| 8266 | switch (slot.getCardState()) { |
| 8267 | case CARDSTATE_ABSENT: |
| 8268 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8269 | break; |
| 8270 | case CARDSTATE_PRESENT: |
| 8271 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8272 | break; |
| 8273 | case CARDSTATE_ERROR: |
| 8274 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8275 | break; |
| 8276 | case CARDSTATE_RESTRICTED: |
| 8277 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8278 | break; |
| 8279 | default: |
| 8280 | break; |
| 8281 | |
| 8282 | } |
| 8283 | |
| 8284 | infos[i] = new UiccSlotInfo( |
| 8285 | slot.isActive(), |
| 8286 | slot.isEuicc(), |
| 8287 | cardId, |
| 8288 | cardState, |
| 8289 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8290 | slot.isExtendedApduSupported(), |
| 8291 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | } |
| 8293 | return infos; |
| 8294 | } finally { |
| 8295 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8296 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | @Override |
| 8300 | public boolean switchSlots(int[] physicalSlots) { |
| 8301 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | |
| 8303 | final long identity = Binder.clearCallingIdentity(); |
| 8304 | try { |
| 8305 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8309 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8310 | |
| 8311 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8312 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
| 8315 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8316 | } finally { |
| 8317 | Binder.restoreCallingIdentity(identity); |
| 8318 | } |
| 8319 | } |
| 8320 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8321 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8322 | * A test API to reload the UICC profile. |
| 8323 | * |
| 8324 | * <p>Requires that the calling app has permission |
| 8325 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8326 | * @hide |
| 8327 | */ |
| 8328 | @Override |
| 8329 | public void refreshUiccProfile(int subId) { |
| 8330 | enforceModifyPermission(); |
| 8331 | |
| 8332 | final long identity = Binder.clearCallingIdentity(); |
| 8333 | try { |
| 8334 | Phone phone = getPhone(subId); |
| 8335 | if (phone == null) { |
| 8336 | return; |
| 8337 | } |
| 8338 | UiccCard uiccCard = phone.getUiccCard(); |
| 8339 | if (uiccCard == null) { |
| 8340 | return; |
| 8341 | } |
| 8342 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8343 | if (uiccProfile == null) { |
| 8344 | return; |
| 8345 | } |
| 8346 | uiccProfile.refresh(); |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
| 8349 | } |
| 8350 | } |
| 8351 | |
| 8352 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8353 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8354 | */ |
| 8355 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8356 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8357 | } |
| 8358 | |
| 8359 | /** |
| 8360 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8361 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8362 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8363 | */ |
| 8364 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8365 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8366 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8367 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8368 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8369 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8370 | return isDataRoamingEnabled; |
| 8371 | } |
| 8372 | |
| 8373 | /** |
| 8374 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8375 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8376 | */ |
| 8377 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8378 | List<Integer> list = TelephonyProperties.default_network(); |
| 8379 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8380 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8381 | return list.get(phoneId); |
| 8382 | } |
| 8383 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8384 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8385 | |
| 8386 | @Override |
| 8387 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8388 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8389 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8390 | |
| 8391 | final long identity = Binder.clearCallingIdentity(); |
| 8392 | try { |
| 8393 | final Phone phone = getPhone(subId); |
| 8394 | if (phone == null) { |
| 8395 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8396 | return; |
| 8397 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8398 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8399 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8400 | if (carrierPrivilegeRules == null) { |
| 8401 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8402 | } else { |
| 8403 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8404 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | } finally { |
| 8406 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8407 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8408 | } |
| 8409 | |
| 8410 | @Override |
| 8411 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8412 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | |
| 8414 | final long identity = Binder.clearCallingIdentity(); |
| 8415 | try { |
| 8416 | final Phone phone = getPhone(subId); |
| 8417 | if (phone == null) { |
| 8418 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8419 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8420 | } |
| 8421 | return phone.getCarrierIdListVersion(); |
| 8422 | } finally { |
| 8423 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8424 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8425 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8426 | |
| 8427 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8428 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8429 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8430 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8431 | mApp, subId, callingPackage, callingFeatureId, |
| 8432 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8433 | return -1; |
| 8434 | } |
| 8435 | |
| 8436 | final long identity = Binder.clearCallingIdentity(); |
| 8437 | try { |
| 8438 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8439 | } finally { |
| 8440 | Binder.restoreCallingIdentity(identity); |
| 8441 | } |
| 8442 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8443 | |
| 8444 | @Override |
| 8445 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8446 | TelephonyPermissions |
| 8447 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8448 | mApp, subId, "getCdmaRoamingMode"); |
| 8449 | |
| 8450 | final long identity = Binder.clearCallingIdentity(); |
| 8451 | try { |
| 8452 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8453 | } finally { |
| 8454 | Binder.restoreCallingIdentity(identity); |
| 8455 | } |
| 8456 | } |
| 8457 | |
| 8458 | @Override |
| 8459 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8461 | mApp, subId, "setCdmaRoamingMode"); |
| 8462 | |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
| 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8472 | public int getCdmaSubscriptionMode(int subId) { |
| 8473 | TelephonyPermissions |
| 8474 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8475 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8476 | |
| 8477 | final long identity = Binder.clearCallingIdentity(); |
| 8478 | try { |
| 8479 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8480 | } finally { |
| 8481 | Binder.restoreCallingIdentity(identity); |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8486 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8487 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8488 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
| 8495 | } |
| 8496 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8497 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8498 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8499 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8500 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8501 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8502 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8503 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8504 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8505 | } |
| 8506 | final long identity = Binder.clearCallingIdentity(); |
| 8507 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8508 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8509 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8510 | if (phone.getEmergencyNumberTracker() != null |
| 8511 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8512 | emergencyNumberListInternal.put( |
| 8513 | phone.getSubId(), |
| 8514 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8515 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8516 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8517 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8518 | } finally { |
| 8519 | Binder.restoreCallingIdentity(identity); |
| 8520 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8521 | } |
| 8522 | |
| 8523 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8524 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8525 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8526 | if (!exactMatch) { |
| 8527 | TelephonyPermissions |
| 8528 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8529 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8530 | } |
| 8531 | final long identity = Binder.clearCallingIdentity(); |
| 8532 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8533 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8534 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8535 | && phone.getEmergencyNumberTracker() |
| 8536 | .isEmergencyNumber(number, exactMatch)) { |
| 8537 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8538 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8539 | } |
| 8540 | return false; |
| 8541 | } finally { |
| 8542 | Binder.restoreCallingIdentity(identity); |
| 8543 | } |
| 8544 | } |
| 8545 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8546 | /** |
| 8547 | * Update emergency number list for test mode. |
| 8548 | */ |
| 8549 | @Override |
| 8550 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8551 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8552 | "updateEmergencyNumberListTestMode"); |
| 8553 | |
| 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
| 8556 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8557 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8558 | if (tracker != null) { |
| 8559 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8560 | } |
| 8561 | } |
| 8562 | } finally { |
| 8563 | Binder.restoreCallingIdentity(identity); |
| 8564 | } |
| 8565 | } |
| 8566 | |
| 8567 | /** |
| 8568 | * Get the full emergency number list for test mode. |
| 8569 | */ |
| 8570 | @Override |
| 8571 | public List<String> getEmergencyNumberListTestMode() { |
| 8572 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8573 | "getEmergencyNumberListTestMode"); |
| 8574 | |
| 8575 | final long identity = Binder.clearCallingIdentity(); |
| 8576 | try { |
| 8577 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8578 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8579 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8580 | if (tracker != null) { |
| 8581 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8582 | emergencyNumbers.add(num.getNumber()); |
| 8583 | } |
| 8584 | } |
| 8585 | } |
| 8586 | return new ArrayList<>(emergencyNumbers); |
| 8587 | } finally { |
| 8588 | Binder.restoreCallingIdentity(identity); |
| 8589 | } |
| 8590 | } |
| 8591 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8592 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8593 | public int getEmergencyNumberDbVersion(int subId) { |
| 8594 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8595 | |
| 8596 | final long identity = Binder.clearCallingIdentity(); |
| 8597 | try { |
| 8598 | final Phone phone = getPhone(subId); |
| 8599 | if (phone == null) { |
| 8600 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8601 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8602 | } |
| 8603 | return phone.getEmergencyNumberDbVersion(); |
| 8604 | } finally { |
| 8605 | Binder.restoreCallingIdentity(identity); |
| 8606 | } |
| 8607 | } |
| 8608 | |
| 8609 | @Override |
| 8610 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8611 | enforceModifyPermission(); |
| 8612 | |
| 8613 | final long identity = Binder.clearCallingIdentity(); |
| 8614 | try { |
| 8615 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8616 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8617 | if (tracker != null) { |
| 8618 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8619 | } |
| 8620 | } |
| 8621 | } finally { |
| 8622 | Binder.restoreCallingIdentity(identity); |
| 8623 | } |
| 8624 | } |
| 8625 | |
| 8626 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8627 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8628 | enforceActiveEmergencySessionPermission(); |
| 8629 | |
| 8630 | final long identity = Binder.clearCallingIdentity(); |
| 8631 | try { |
| 8632 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8633 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8634 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8635 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8636 | } |
| 8637 | } |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | @Override |
| 8644 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8645 | enforceActiveEmergencySessionPermission(); |
| 8646 | |
| 8647 | final long identity = Binder.clearCallingIdentity(); |
| 8648 | try { |
| 8649 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8650 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8651 | if (tracker != null) { |
| 8652 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8653 | } |
| 8654 | } |
| 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
| 8657 | } |
| 8658 | } |
| 8659 | |
| 8660 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8661 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8662 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8663 | Phone phone = getPhone(subId); |
| 8664 | if (phone == null) { |
| 8665 | return null; |
| 8666 | } |
| 8667 | final long identity = Binder.clearCallingIdentity(); |
| 8668 | try { |
| 8669 | UiccProfile profile = UiccController.getInstance() |
| 8670 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8671 | if (profile != null) { |
| 8672 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8673 | } |
| 8674 | } finally { |
| 8675 | Binder.restoreCallingIdentity(identity); |
| 8676 | } |
| 8677 | return null; |
| 8678 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8679 | |
| 8680 | /** |
| 8681 | * Enable or disable a modem stack. |
| 8682 | */ |
| 8683 | @Override |
| 8684 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8685 | enforceModifyPermission(); |
| 8686 | |
| 8687 | final long identity = Binder.clearCallingIdentity(); |
| 8688 | try { |
| 8689 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8690 | if (phone == null) { |
| 8691 | return false; |
| 8692 | } else { |
| 8693 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8694 | } |
| 8695 | } finally { |
| 8696 | Binder.restoreCallingIdentity(identity); |
| 8697 | } |
| 8698 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8699 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8700 | /** |
| 8701 | * Whether a modem stack is enabled or not. |
| 8702 | */ |
| 8703 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8704 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8705 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8706 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8707 | if (phone == null) return false; |
| 8708 | |
| 8709 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8710 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8711 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8712 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8713 | } |
| 8714 | |
| 8715 | final long identity = Binder.clearCallingIdentity(); |
| 8716 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8717 | try { |
| 8718 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8719 | } catch (NoSuchElementException ex) { |
| 8720 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8721 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8722 | } finally { |
| 8723 | Binder.restoreCallingIdentity(identity); |
| 8724 | } |
| 8725 | } |
| 8726 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8727 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8728 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8729 | enforceModifyPermission(); |
| 8730 | |
| 8731 | final long identity = Binder.clearCallingIdentity(); |
| 8732 | try { |
| 8733 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8734 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8735 | .commit(); |
| 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8742 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8743 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8744 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8745 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8746 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8747 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8748 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8749 | |
| 8750 | final long identity = Binder.clearCallingIdentity(); |
| 8751 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8752 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8753 | } finally { |
| 8754 | Binder.restoreCallingIdentity(identity); |
| 8755 | } |
| 8756 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8757 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8758 | @TelephonyManager.IsMultiSimSupportedResult |
| 8759 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8760 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8761 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8762 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8763 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8764 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8765 | } |
| 8766 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8767 | // supported by the modem, indicate that it is restricted. |
| 8768 | PhoneCapability staticCapability = |
| 8769 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8770 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8771 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8772 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8773 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8774 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8775 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8776 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8777 | } |
| 8778 | // Check if support of multiple SIMs is restricted by carrier |
| 8779 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8780 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8781 | } |
| 8782 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8783 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8784 | } |
| 8785 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8786 | /** |
| 8787 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8788 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8789 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8790 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8791 | * @param numOfSims number of active sims we want to switch to |
| 8792 | */ |
| 8793 | @Override |
| 8794 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8795 | if (numOfSims == 1) { |
| 8796 | enforceModifyPermission(); |
| 8797 | } else { |
| 8798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8799 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8800 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8801 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8802 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8803 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8804 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8805 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8806 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8807 | return; |
| 8808 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8809 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8810 | } finally { |
| 8811 | Binder.restoreCallingIdentity(identity); |
| 8812 | } |
| 8813 | } |
| 8814 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8815 | @Override |
| 8816 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8817 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8818 | Phone phone = getPhone(subId); |
| 8819 | if (phone == null) { |
| 8820 | return false; |
| 8821 | } |
| 8822 | final long identity = Binder.clearCallingIdentity(); |
| 8823 | try { |
| 8824 | UiccCard uiccCard = phone.getUiccCard(); |
| 8825 | if (uiccCard == null) { |
| 8826 | return false; |
| 8827 | } |
| 8828 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8829 | if (uiccProfile == null) { |
| 8830 | return false; |
| 8831 | } |
| 8832 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8833 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8834 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8835 | } |
| 8836 | return false; |
| 8837 | } finally { |
| 8838 | Binder.restoreCallingIdentity(identity); |
| 8839 | } |
| 8840 | } |
| 8841 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8842 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8843 | * Get whether making changes to modem configurations will trigger reboot. |
| 8844 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8845 | */ |
| 8846 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8847 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8848 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8849 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8850 | mApp, subId, callingPackage, callingFeatureId, |
| 8851 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8852 | return false; |
| 8853 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8854 | final long identity = Binder.clearCallingIdentity(); |
| 8855 | try { |
| 8856 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8857 | } finally { |
| 8858 | Binder.restoreCallingIdentity(identity); |
| 8859 | } |
| 8860 | } |
| 8861 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8862 | private void updateModemStateMetrics() { |
| 8863 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8864 | // TODO: check the state for each modem if the api is ready. |
| 8865 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8866 | } |
| 8867 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8868 | @Override |
| 8869 | public int[] getSlotsMapping() { |
| 8870 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8871 | |
| 8872 | final long identity = Binder.clearCallingIdentity(); |
| 8873 | try { |
| 8874 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8875 | // All logical slots should have a mapping to a physical slot. |
| 8876 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8877 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8878 | for (int i = 0; i < slotInfos.length; i++) { |
| 8879 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8880 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8881 | } |
| 8882 | } |
| 8883 | return logicalSlotsMapping; |
| 8884 | } finally { |
| 8885 | Binder.restoreCallingIdentity(identity); |
| 8886 | } |
| 8887 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8888 | |
| 8889 | /** |
| 8890 | * Get the IRadio HAL Version |
| 8891 | */ |
| 8892 | @Override |
| 8893 | public int getRadioHalVersion() { |
| 8894 | Phone phone = getDefaultPhone(); |
| 8895 | if (phone == null) return -1; |
| 8896 | HalVersion hv = phone.getHalVersion(); |
| 8897 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8898 | return hv.major * 100 + hv.minor; |
| 8899 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8900 | |
| 8901 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8902 | * Get the current calling package name. |
| 8903 | * @return the current calling package name |
| 8904 | */ |
| 8905 | @Override |
| 8906 | public String getCurrentPackageName() { |
| 8907 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8908 | } |
| 8909 | |
| 8910 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8911 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8912 | * corresponding network requests on a subId. |
| 8913 | * |
| 8914 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8915 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8916 | * 2) APN is un-metered for this subscription, or |
| 8917 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8918 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8919 | * |
| 8920 | * @return whether data is allowed for a apn type. |
| 8921 | * |
| 8922 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8923 | */ |
| 8924 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8925 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8926 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8927 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8928 | |
| 8929 | // Now that all security checks passes, perform the operation as ourselves. |
| 8930 | final long identity = Binder.clearCallingIdentity(); |
| 8931 | try { |
| 8932 | Phone phone = getPhone(subId); |
| 8933 | if (phone == null) return false; |
| 8934 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8935 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8936 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8937 | } finally { |
| 8938 | Binder.restoreCallingIdentity(identity); |
| 8939 | } |
| 8940 | } |
| 8941 | |
| 8942 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8943 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8944 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8945 | |
| 8946 | // Now that all security checks passes, perform the operation as ourselves. |
| 8947 | final long identity = Binder.clearCallingIdentity(); |
| 8948 | try { |
| 8949 | Phone phone = getPhone(subId); |
| 8950 | if (phone == null) return true; // By default return true. |
| 8951 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8952 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8953 | } finally { |
| 8954 | Binder.restoreCallingIdentity(identity); |
| 8955 | } |
| 8956 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8957 | |
| 8958 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8959 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8960 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8961 | enforceModifyPermission(); |
| 8962 | long token = Binder.clearCallingIdentity(); |
| 8963 | try { |
| 8964 | Phone phone = getPhone(subscriptionId); |
| 8965 | if (phone == null) { |
| 8966 | try { |
| 8967 | if (resultCallback != null) { |
| 8968 | resultCallback.accept(false); |
| 8969 | } |
| 8970 | } catch (RemoteException e) { |
| 8971 | // ignore |
| 8972 | } |
| 8973 | return; |
| 8974 | } |
| 8975 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8976 | Pair.create(specifiers, (x) -> { |
| 8977 | try { |
| 8978 | if (resultCallback != null) { |
| 8979 | resultCallback.accept(x); |
| 8980 | } |
| 8981 | } catch (RemoteException e) { |
| 8982 | // ignore |
| 8983 | } |
| 8984 | }); |
| 8985 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8986 | } finally { |
| 8987 | Binder.restoreCallingIdentity(token); |
| 8988 | } |
| 8989 | } |
| 8990 | |
| 8991 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8992 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8993 | TelephonyPermissions |
| 8994 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8995 | mApp, subId, "getSystemSelectionChannels"); |
| 8996 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8997 | final long identity = Binder.clearCallingIdentity(); |
| 8998 | try { |
| 8999 | List<RadioAccessSpecifier> specifiers = |
| 9000 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9001 | null, subId, workSource); |
| 9002 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9003 | return specifiers; |
| 9004 | } finally { |
| 9005 | Binder.restoreCallingIdentity(identity); |
| 9006 | } |
| 9007 | } |
| 9008 | |
| 9009 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9010 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9011 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9012 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9013 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9014 | if (iccRecords == null) { |
| 9015 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9016 | return false; |
| 9017 | } |
| 9018 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9019 | } |
| 9020 | |
| 9021 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9022 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9023 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9024 | if (callingPackage == null) { |
| 9025 | callingPackage = getCurrentPackageName(); |
| 9026 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9027 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9028 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9029 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9030 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9031 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9032 | } |
| 9033 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9034 | Intent intent = new Intent(); |
| 9035 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9036 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9037 | // Bring up choose default SMS subscription dialog right now |
| 9038 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9039 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9040 | mApp.startActivity(intent); |
| 9041 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9042 | |
| 9043 | @Override |
| 9044 | public String getMmsUAProfUrl(int subId) { |
| 9045 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9046 | final long identity = Binder.clearCallingIdentity(); |
| 9047 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9048 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9049 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9050 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9051 | return carrierUAProfUrl; |
| 9052 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9053 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9054 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9055 | } finally { |
| 9056 | Binder.restoreCallingIdentity(identity); |
| 9057 | } |
| 9058 | } |
| 9059 | |
| 9060 | @Override |
| 9061 | public String getMmsUserAgent(int subId) { |
| 9062 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9063 | final long identity = Binder.clearCallingIdentity(); |
| 9064 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9065 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9066 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9067 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9068 | return carrierUserAgent; |
| 9069 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9070 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9071 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9072 | } finally { |
| 9073 | Binder.restoreCallingIdentity(identity); |
| 9074 | } |
| 9075 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9076 | |
| 9077 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9078 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9079 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9080 | |
| 9081 | final long identity = Binder.clearCallingIdentity(); |
| 9082 | try { |
| 9083 | Phone phone = getPhone(subscriptionId); |
| 9084 | if (phone == null) return false; |
| 9085 | |
| 9086 | switch (policy) { |
| 9087 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9088 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9089 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9090 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9091 | default: |
| 9092 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9093 | } |
| 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
| 9096 | } |
| 9097 | } |
| 9098 | |
| 9099 | @Override |
| 9100 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9101 | boolean enabled) { |
| 9102 | enforceModifyPermission(); |
| 9103 | |
| 9104 | final long identity = Binder.clearCallingIdentity(); |
| 9105 | try { |
| 9106 | Phone phone = getPhone(subscriptionId); |
| 9107 | if (phone == null) return; |
| 9108 | |
| 9109 | switch (policy) { |
| 9110 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9111 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9112 | break; |
| 9113 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9114 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9115 | break; |
| 9116 | default: |
| 9117 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9118 | } |
| 9119 | } finally { |
| 9120 | Binder.restoreCallingIdentity(identity); |
| 9121 | } |
| 9122 | } |
| 9123 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9124 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9125 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9126 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9127 | * otherwise. |
| 9128 | */ |
| 9129 | @Override |
| 9130 | public void setCepEnabled(boolean isCepEnabled) { |
| 9131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9132 | |
| 9133 | final long identity = Binder.clearCallingIdentity(); |
| 9134 | try { |
| 9135 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9136 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9137 | Phone defaultPhone = phone.getImsPhone(); |
| 9138 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9139 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9140 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9141 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9142 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9143 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9144 | + imsPhone.getMsisdn()); |
| 9145 | } |
| 9146 | } |
| 9147 | } finally { |
| 9148 | Binder.restoreCallingIdentity(identity); |
| 9149 | } |
| 9150 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9151 | |
| 9152 | /** |
| 9153 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9154 | * |
| 9155 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9156 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9157 | * before being read. |
| 9158 | */ |
| 9159 | @Override |
| 9160 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9161 | isCompressed) { |
| 9162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9163 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9164 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9165 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9166 | } |
| 9167 | if (!isImsAvailableOnDevice()) { |
| 9168 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9169 | "IMS not available on device."); |
| 9170 | } |
| 9171 | |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9173 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9174 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9175 | } finally { |
| 9176 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9177 | } |
| 9178 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9179 | |
| 9180 | @Override |
| 9181 | public boolean isIccLockEnabled(int subId) { |
| 9182 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9183 | |
| 9184 | // Now that all security checks passes, perform the operation as ourselves. |
| 9185 | final long identity = Binder.clearCallingIdentity(); |
| 9186 | try { |
| 9187 | Phone phone = getPhone(subId); |
| 9188 | if (phone != null && phone.getIccCard() != null) { |
| 9189 | return phone.getIccCard().getIccLockEnabled(); |
| 9190 | } else { |
| 9191 | return false; |
| 9192 | } |
| 9193 | } finally { |
| 9194 | Binder.restoreCallingIdentity(identity); |
| 9195 | } |
| 9196 | } |
| 9197 | |
| 9198 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9199 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9200 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9201 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9202 | * three cases: |
| 9203 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9204 | * successfully. |
| 9205 | * - Positive number and zero for remaining password attempts. |
| 9206 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9207 | * |
| 9208 | */ |
| 9209 | @Override |
| 9210 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9211 | enforceModifyPermission(); |
| 9212 | |
| 9213 | Phone phone = getPhone(subId); |
| 9214 | if (phone == null) { |
| 9215 | return 0; |
| 9216 | } |
| 9217 | // Now that all security checks passes, perform the operation as ourselves. |
| 9218 | final long identity = Binder.clearCallingIdentity(); |
| 9219 | try { |
| 9220 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9221 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9222 | return attemptsRemaining; |
| 9223 | |
| 9224 | } catch (Exception e) { |
| 9225 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9226 | } finally { |
| 9227 | Binder.restoreCallingIdentity(identity); |
| 9228 | } |
| 9229 | return 0; |
| 9230 | } |
| 9231 | |
| 9232 | /** |
| 9233 | * Change the ICC password used in ICC pin lock. |
| 9234 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9235 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9236 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9237 | * - Positive number and zero for remaining password attempts. |
| 9238 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9239 | * |
| 9240 | */ |
| 9241 | @Override |
| 9242 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9243 | enforceModifyPermission(); |
| 9244 | |
| 9245 | Phone phone = getPhone(subId); |
| 9246 | if (phone == null) { |
| 9247 | return 0; |
| 9248 | } |
| 9249 | // Now that all security checks passes, perform the operation as ourselves. |
| 9250 | final long identity = Binder.clearCallingIdentity(); |
| 9251 | try { |
| 9252 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9253 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9254 | return attemptsRemaining; |
| 9255 | |
| 9256 | } catch (Exception e) { |
| 9257 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
| 9260 | } |
| 9261 | return 0; |
| 9262 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9263 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9264 | /** |
| 9265 | * Request for receiving user activity notification |
| 9266 | */ |
| 9267 | @Override |
| 9268 | public void requestUserActivityNotification() { |
| 9269 | if (!mNotifyUserActivity.get() |
| 9270 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9271 | mNotifyUserActivity.set(true); |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | /** |
| 9276 | * Called when userActivity is signalled in the power manager. |
| 9277 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9278 | */ |
| 9279 | @Override |
| 9280 | public void userActivity() { |
| 9281 | // *************************************** |
| 9282 | // * Inherited from PhoneWindowManager * |
| 9283 | // *************************************** |
| 9284 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9285 | // WITH ITS LOCKS HELD. |
| 9286 | // |
| 9287 | // This code must be VERY careful about the locks |
| 9288 | // it acquires. |
| 9289 | // In fact, the current code acquires way too many, |
| 9290 | // and probably has lurking deadlocks. |
| 9291 | |
| 9292 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9293 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9294 | } |
| 9295 | |
| 9296 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9297 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9298 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9299 | } |
| 9300 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9301 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9302 | @Override |
| 9303 | public boolean canConnectTo5GInDsdsMode() { |
| 9304 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9305 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9306 | |
| 9307 | @Override |
| 9308 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9309 | String callingFeatureId) { |
| 9310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9311 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9312 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9313 | } |
| 9314 | |
| 9315 | Phone phone = getPhone(subId); |
| 9316 | if (phone == null) { |
| 9317 | throw new RuntimeException("phone is not available"); |
| 9318 | } |
| 9319 | // Now that all security checks passes, perform the operation as ourselves. |
| 9320 | final long identity = Binder.clearCallingIdentity(); |
| 9321 | try { |
| 9322 | return phone.getEquivalentHomePlmns(); |
| 9323 | } finally { |
| 9324 | Binder.restoreCallingIdentity(identity); |
| 9325 | } |
| 9326 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9327 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9328 | @Override |
| 9329 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9330 | UaSecurityProtocolIdentifier securityProtocol, |
| 9331 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9332 | throws RemoteException { |
| 9333 | enforceModifyPermission(); |
| 9334 | if (DBG) { |
| 9335 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9336 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9337 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9338 | } |
| 9339 | |
| 9340 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9341 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9342 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9343 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9344 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9345 | if (callback != null) { |
| 9346 | try { |
| 9347 | callback.onAuthenticationFailure( |
| 9348 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9349 | } catch (RemoteException exception) { |
| 9350 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9351 | } |
| 9352 | return; |
| 9353 | } |
| 9354 | } |
| 9355 | |
| 9356 | final long token = Binder.clearCallingIdentity(); |
| 9357 | try { |
| 9358 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9359 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9360 | forceBootStrapping, callback)); |
| 9361 | } finally { |
| 9362 | Binder.restoreCallingIdentity(token); |
| 9363 | } |
| 9364 | } |
| 9365 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9366 | /** |
| 9367 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9368 | * requested radio power state will actually be set. See {@link |
| 9369 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9370 | * |
| 9371 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9372 | * @param enable {@code true} if trying to turn radio on. |
| 9373 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9374 | * false}. |
| 9375 | */ |
| 9376 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9377 | Phone phone = getPhone(subId); |
| 9378 | if (phone != null) { |
| 9379 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9380 | return true; |
| 9381 | } |
| 9382 | return false; |
| 9383 | } |
| 9384 | |
| 9385 | private int handleDataThrottlingRequest(int subId, |
| 9386 | DataThrottlingRequest dataThrottlingRequest) { |
| 9387 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9388 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9389 | if (!setRadioPowerForThermal(subId, true)) { |
| 9390 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9391 | } |
| 9392 | |
| 9393 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9394 | |
| 9395 | int thermalMitigationResult = |
| 9396 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9397 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9398 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9399 | } |
| 9400 | return thermalMitigationResult; |
| 9401 | } |
| 9402 | |
| 9403 | /** |
| 9404 | * Thermal mitigation request to control functionalities at modem. |
| 9405 | * |
| 9406 | * @param subId the id of the subscription. |
| 9407 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9408 | * |
| 9409 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9410 | */ |
| 9411 | @Override |
| 9412 | @ThermalMitigationResult |
| 9413 | public int sendThermalMitigationRequest( |
| 9414 | int subId, |
| 9415 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9416 | enforceModifyPermission(); |
| 9417 | |
| 9418 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9419 | final long identity = Binder.clearCallingIdentity(); |
| 9420 | |
| 9421 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9422 | try { |
| 9423 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9424 | switch (thermalMitigationAction) { |
| 9425 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9426 | thermalMitigationResult = |
| 9427 | handleDataThrottlingRequest(subId, |
| 9428 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9429 | break; |
| 9430 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9431 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9432 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9433 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9434 | } |
| 9435 | |
| 9436 | // Ensure that radio is on. If not able to power on due to phone being |
| 9437 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9438 | if (!setRadioPowerForThermal(subId, true)) { |
| 9439 | thermalMitigationResult = |
| 9440 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9441 | break; |
| 9442 | } |
| 9443 | |
| 9444 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9445 | false); |
| 9446 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9447 | break; |
| 9448 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9449 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9450 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9451 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9452 | } |
| 9453 | |
| 9454 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9455 | if (registry != null) { |
| 9456 | TelephonyConnectionService service = |
| 9457 | registry.getTelephonyConnectionService(); |
| 9458 | Phone phone = getPhone(subId); |
| 9459 | if (phone == null) { |
| 9460 | thermalMitigationResult = |
| 9461 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9462 | break; |
| 9463 | } |
| 9464 | |
| 9465 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9466 | != TelephonyManager.CALL_STATE_IDLE |
| 9467 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9468 | || (service != null && service.isEmergencyCallPending())) { |
| 9469 | String errorMessage = "Phone state is not valid. call state = " |
| 9470 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9471 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9472 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9473 | errorMessage += service == null |
| 9474 | ? " TelephonyConnectionService is null" |
| 9475 | : " isEmergencyCallPending = " |
| 9476 | + service.isEmergencyCallPending(); |
| 9477 | Log.e(LOG_TAG, errorMessage); |
| 9478 | thermalMitigationResult = |
| 9479 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9480 | break; |
| 9481 | } |
| 9482 | } else { |
| 9483 | thermalMitigationResult = |
| 9484 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9485 | break; |
| 9486 | } |
| 9487 | |
| 9488 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9489 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9490 | if (!setRadioPowerForThermal(subId, false)) { |
| 9491 | thermalMitigationResult = |
| 9492 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9493 | break; |
| 9494 | } |
| 9495 | thermalMitigationResult = |
| 9496 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9497 | break; |
| 9498 | default: |
| 9499 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9500 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9501 | } |
| 9502 | } catch (IllegalArgumentException e) { |
| 9503 | throw e; |
| 9504 | } catch (Exception e) { |
| 9505 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9506 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
| 9510 | |
| 9511 | if (DBG) { |
| 9512 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9513 | + thermalMitigationResult); |
| 9514 | } |
| 9515 | |
| 9516 | return thermalMitigationResult; |
| 9517 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9518 | |
| 9519 | /** |
| 9520 | * Set the GbaService Package Name that Telephony will bind to. |
| 9521 | * |
| 9522 | * @param subId The sim that the GbaService is associated with. |
| 9523 | * @param packageName The name of the package to be replaced with. |
| 9524 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9525 | */ |
| 9526 | @Override |
| 9527 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9528 | enforceModifyPermission(); |
| 9529 | |
| 9530 | final long identity = Binder.clearCallingIdentity(); |
| 9531 | try { |
| 9532 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | /** |
| 9539 | * Return the package name of the currently bound GbaService. |
| 9540 | * |
| 9541 | * @param subId The sim that the GbaService is associated with. |
| 9542 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9543 | */ |
| 9544 | @Override |
| 9545 | public String getBoundGbaService(int subId) { |
| 9546 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9547 | |
| 9548 | final long identity = Binder.clearCallingIdentity(); |
| 9549 | try { |
| 9550 | return getGbaManager(subId).getServicePackage(); |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
| 9554 | } |
| 9555 | |
| 9556 | /** |
| 9557 | * Set the release time for telephony to unbind GbaService. |
| 9558 | * |
| 9559 | * @param subId The sim that the GbaService is associated with. |
| 9560 | * @param interval The release time to unbind GbaService by millisecond. |
| 9561 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9562 | */ |
| 9563 | @Override |
| 9564 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9565 | enforceModifyPermission(); |
| 9566 | |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9570 | } finally { |
| 9571 | Binder.restoreCallingIdentity(identity); |
| 9572 | } |
| 9573 | } |
| 9574 | |
| 9575 | /** |
| 9576 | * Return the release time for telephony to unbind GbaService. |
| 9577 | * |
| 9578 | * @param subId The sim that the GbaService is associated with. |
| 9579 | * @return The release time to unbind GbaService by millisecond. |
| 9580 | */ |
| 9581 | @Override |
| 9582 | public int getGbaReleaseTime(int subId) { |
| 9583 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9584 | |
| 9585 | final long identity = Binder.clearCallingIdentity(); |
| 9586 | try { |
| 9587 | return getGbaManager(subId).getReleaseTime(); |
| 9588 | } finally { |
| 9589 | Binder.restoreCallingIdentity(identity); |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | private GbaManager getGbaManager(int subId) { |
| 9594 | GbaManager instance = GbaManager.getInstance(subId); |
| 9595 | if (instance == null) { |
| 9596 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9597 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9598 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9599 | } |
| 9600 | return instance; |
| 9601 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9602 | |
| 9603 | /** |
| 9604 | * indicate whether the device and the carrier can support |
| 9605 | * RCS VoLTE single registration. |
| 9606 | */ |
| 9607 | @Override |
| 9608 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9609 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9610 | |
| 9611 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9612 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9613 | } |
| 9614 | |
| 9615 | final long identity = Binder.clearCallingIdentity(); |
| 9616 | try { |
| 9617 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9618 | if (rpm != null) { |
| 9619 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9620 | } |
| 9621 | return false; |
| 9622 | } finally { |
| 9623 | Binder.restoreCallingIdentity(identity); |
| 9624 | } |
| 9625 | } |
| 9626 | |
| 9627 | /** |
| 9628 | * Register RCS provisioning callback. |
| 9629 | */ |
| 9630 | @Override |
| 9631 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9632 | IRcsConfigCallback callback) { |
| 9633 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9634 | |
| 9635 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9636 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9637 | } |
| 9638 | if (!isImsAvailableOnDevice()) { |
| 9639 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9640 | "IMS not available on device."); |
| 9641 | } |
| 9642 | |
| 9643 | final long identity = Binder.clearCallingIdentity(); |
| 9644 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9645 | if (!RcsProvisioningMonitor.getInstance() |
| 9646 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9647 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9648 | "Service not available for the subscription."); |
| 9649 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9650 | } finally { |
| 9651 | Binder.restoreCallingIdentity(identity); |
| 9652 | } |
| 9653 | } |
| 9654 | |
| 9655 | /** |
| 9656 | * Unregister RCS provisioning callback. |
| 9657 | */ |
| 9658 | @Override |
| 9659 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9660 | IRcsConfigCallback callback) { |
| 9661 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9662 | |
| 9663 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9664 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9665 | } |
| 9666 | if (!isImsAvailableOnDevice()) { |
| 9667 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9668 | "IMS not available on device."); |
| 9669 | } |
| 9670 | |
| 9671 | final long identity = Binder.clearCallingIdentity(); |
| 9672 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9673 | RcsProvisioningMonitor.getInstance() |
| 9674 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9675 | } finally { |
| 9676 | Binder.restoreCallingIdentity(identity); |
| 9677 | } |
| 9678 | } |
| 9679 | |
| 9680 | /** |
| 9681 | * trigger RCS reconfiguration. |
| 9682 | */ |
| 9683 | public void triggerRcsReconfiguration(int subId) { |
| 9684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9685 | mApp, subId, "triggerRcsReconfiguration"); |
| 9686 | |
| 9687 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9688 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9689 | } |
| 9690 | if (!isImsAvailableOnDevice()) { |
| 9691 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9692 | "IMS not available on device."); |
| 9693 | } |
| 9694 | |
| 9695 | final long identity = Binder.clearCallingIdentity(); |
| 9696 | try { |
| 9697 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9698 | } finally { |
| 9699 | Binder.restoreCallingIdentity(identity); |
| 9700 | } |
| 9701 | } |
| 9702 | |
| 9703 | /** |
| 9704 | * Provide the client configuration parameters of the RCS application. |
| 9705 | */ |
| 9706 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9707 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9708 | mApp, subId, "setRcsClientConfiguration"); |
| 9709 | |
| 9710 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9711 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9712 | } |
| 9713 | if (!isImsAvailableOnDevice()) { |
| 9714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9715 | "IMS not available on device."); |
| 9716 | } |
| 9717 | |
| 9718 | final long identity = Binder.clearCallingIdentity(); |
| 9719 | |
| 9720 | try { |
| 9721 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9722 | if (configBinder == null) { |
| 9723 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9724 | } else { |
| 9725 | configBinder.setRcsClientConfiguration(rcc); |
| 9726 | } |
| 9727 | } catch (RemoteException e) { |
| 9728 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9729 | } finally { |
| 9730 | Binder.restoreCallingIdentity(identity); |
| 9731 | } |
| 9732 | } |
| 9733 | |
| 9734 | /** |
| 9735 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9736 | */ |
| 9737 | @Override |
| 9738 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9739 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9740 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9741 | enforceModifyPermission(); |
| 9742 | |
| 9743 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9744 | : Boolean.parseBoolean(enabledStr); |
| 9745 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9746 | } |
| 9747 | |
| 9748 | /** |
| 9749 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9750 | */ |
| 9751 | @Override |
| 9752 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9753 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9754 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9759 | */ |
| 9760 | @Override |
| 9761 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9762 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9763 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9764 | enforceModifyPermission(); |
| 9765 | |
| 9766 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9767 | : Boolean.parseBoolean(enabledStr); |
| 9768 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9769 | subId, enabled); |
| 9770 | } |
| 9771 | |
| 9772 | /** |
| 9773 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9774 | */ |
| 9775 | @Override |
| 9776 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9777 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9778 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9779 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9780 | |
| 9781 | /** |
| 9782 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9783 | * their mobile plan. |
| 9784 | */ |
| 9785 | @Override |
| 9786 | public String getMobileProvisioningUrl() { |
| 9787 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9788 | final long identity = Binder.clearCallingIdentity(); |
| 9789 | try { |
| 9790 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9791 | } finally { |
| 9792 | Binder.restoreCallingIdentity(identity); |
| 9793 | } |
| 9794 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9795 | |
| 9796 | @Override |
| 9797 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9798 | String callingPackage) { |
| 9799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9800 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9801 | |
| 9802 | final int callingUid = Binder.getCallingUid(); |
| 9803 | // Verify that tha callingPackage belongs to the calling UID |
| 9804 | mApp.getSystemService(AppOpsManager.class) |
| 9805 | .checkPackage(callingUid, callingPackage); |
| 9806 | |
| 9807 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9808 | |
| 9809 | final long identity = Binder.clearCallingIdentity(); |
| 9810 | try { |
| 9811 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9812 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9813 | |
| 9814 | if (result instanceof IllegalStateException) { |
| 9815 | throw (IllegalStateException) result; |
| 9816 | } |
| 9817 | } finally { |
| 9818 | Binder.restoreCallingIdentity(identity); |
| 9819 | } |
| 9820 | } |
| 9821 | |
| 9822 | @Override |
| 9823 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9824 | String callingPackage) { |
| 9825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9826 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9827 | |
| 9828 | final int callingUid = Binder.getCallingUid(); |
| 9829 | // Verify that tha callingPackage belongs to the calling UID |
| 9830 | mApp.getSystemService(AppOpsManager.class) |
| 9831 | .checkPackage(callingUid, callingPackage); |
| 9832 | |
| 9833 | final long identity = Binder.clearCallingIdentity(); |
| 9834 | try { |
| 9835 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9836 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9837 | |
| 9838 | if (result instanceof IllegalStateException) { |
| 9839 | throw (IllegalStateException) result; |
| 9840 | } |
| 9841 | } finally { |
| 9842 | Binder.restoreCallingIdentity(identity); |
| 9843 | } |
| 9844 | } |
| 9845 | |
| 9846 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9847 | int callingUid) { |
| 9848 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9849 | // phone/system process do not have further restriction on request |
| 9850 | return; |
| 9851 | } |
| 9852 | |
| 9853 | // Applications has restrictions on how to use the request: |
| 9854 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9855 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9856 | // This is not system caller which has been checked above |
| 9857 | throw new IllegalArgumentException( |
| 9858 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9859 | } |
| 9860 | |
| 9861 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9862 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9863 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9864 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9865 | || info.isEnabled()) { |
| 9866 | throw new IllegalArgumentException( |
| 9867 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9868 | } |
| 9869 | |
| 9870 | // Thresholds length for each RAN need in range. This has been validated in |
| 9871 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9872 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9873 | final int[] thresholds = info.getThresholds(); |
| 9874 | Objects.requireNonNull(thresholds); |
| 9875 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9876 | || thresholds.length |
| 9877 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9878 | throw new IllegalArgumentException( |
| 9879 | "thresholds length is out of range: " + thresholds.length); |
| 9880 | } |
| 9881 | } |
| 9882 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9883 | } |