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; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 95 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 98 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 99 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 100 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 101 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 102 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 103 | import android.telephony.data.ApnSetting; |
| 104 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 105 | import android.telephony.gba.GbaAuthRequest; |
| 106 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 107 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 108 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 109 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 110 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 117 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 118 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 119 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 120 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 121 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 123 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 124 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 126 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 127 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 128 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 129 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 169 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 181 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 183 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 184 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 185 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 186 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 187 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 189 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 190 | import com.android.services.telephony.TelecomAccountRegistry; |
| 191 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 192 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 193 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 194 | import java.io.FileDescriptor; |
| 195 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 197 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 198 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 199 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 200 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 201 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 203 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 204 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 205 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 206 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * Implementation of the ITelephony interface. |
| 210 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 211 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 213 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 214 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 215 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | |
| 217 | // Message codes used with mMainThreadHandler |
| 218 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 219 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 220 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 221 | private static final int CMD_OPEN_CHANNEL = 9; |
| 222 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 223 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 224 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 225 | private static final int CMD_NV_READ_ITEM = 13; |
| 226 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 227 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 228 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 229 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 230 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 231 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 232 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 233 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 234 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 235 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 236 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 237 | private static final int CMD_SEND_ENVELOPE = 25; |
| 238 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 239 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 240 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 241 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 242 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 243 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 244 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 245 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 246 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 247 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 248 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 250 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 251 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 252 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 253 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 254 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 255 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 256 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 257 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 258 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 259 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 260 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 261 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 262 | private static final int CMD_SWITCH_SLOTS = 50; |
| 263 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 264 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 265 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 266 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 267 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 268 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 269 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 270 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 271 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 272 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 273 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 274 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 275 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 276 | private static final int CMD_MODEM_REBOOT = 64; |
| 277 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 278 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 279 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 280 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 281 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 283 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 284 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 285 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 286 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 287 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 288 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 289 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 290 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 291 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 292 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 293 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 294 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 295 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 296 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 297 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 298 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 299 | private static final int CMD_GET_CALL_WAITING = 87; |
| 300 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 301 | private static final int CMD_SET_CALL_WAITING = 89; |
| 302 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 303 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 304 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 305 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 306 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 307 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 308 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 309 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 310 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 311 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 312 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 313 | private static final int CMD_SET_SIM_POWER = 101; |
| 314 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 316 | // Parameters of select command. |
| 317 | private static final int SELECT_COMMAND = 0xA4; |
| 318 | private static final int SELECT_P1 = 0x04; |
| 319 | private static final int SELECT_P2 = 0; |
| 320 | private static final int SELECT_P3 = 0x10; |
| 321 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 322 | /** The singleton instance. */ |
| 323 | private static PhoneInterfaceManager sInstance; |
| 324 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 325 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 326 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 327 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 328 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 329 | private AppOpsManager mAppOps; |
| 330 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 331 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 332 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 333 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 334 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 335 | /** User Activity */ |
| 336 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 337 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 338 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 339 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 340 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 341 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 342 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 343 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 344 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 345 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 346 | // String to store multi SIM allowed |
| 347 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 348 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 349 | // The AID of ISD-R. |
| 350 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 351 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 352 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 353 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 354 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 355 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 356 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 357 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 358 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 359 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 360 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 361 | */ |
| 362 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 363 | "reset_network_erase_modem_config_enabled"; |
| 364 | |
| 365 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 366 | * A request object to use for transmitting data to an ICC. |
| 367 | */ |
| 368 | private static final class IccAPDUArgument { |
| 369 | public int channel, cla, command, p1, p2, p3; |
| 370 | public String data; |
| 371 | |
| 372 | public IccAPDUArgument(int channel, int cla, int command, |
| 373 | int p1, int p2, int p3, String data) { |
| 374 | this.channel = channel; |
| 375 | this.cla = cla; |
| 376 | this.command = command; |
| 377 | this.p1 = p1; |
| 378 | this.p2 = p2; |
| 379 | this.p3 = p3; |
| 380 | this.data = data; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 385 | * A request object to use for transmitting data to an ICC. |
| 386 | */ |
| 387 | private static final class ManualNetworkSelectionArgument { |
| 388 | public OperatorInfo operatorInfo; |
| 389 | public boolean persistSelection; |
| 390 | |
| 391 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 392 | this.operatorInfo = operatorInfo; |
| 393 | this.persistSelection = persistSelection; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 399 | * request after sending. The main thread will notify the request when it is complete. |
| 400 | */ |
| 401 | private static final class MainThreadRequest { |
| 402 | /** The argument to use for the request */ |
| 403 | public Object argument; |
| 404 | /** The result of the request that is run on the main thread */ |
| 405 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 406 | // The subscriber id that this request applies to. Defaults to |
| 407 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 408 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 410 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 411 | public Phone phone; |
| 412 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 413 | public WorkSource workSource; |
| 414 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 415 | public MainThreadRequest(Object argument) { |
| 416 | this.argument = argument; |
| 417 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 418 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 419 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 420 | this.argument = argument; |
| 421 | if (phone != null) { |
| 422 | this.phone = phone; |
| 423 | } |
| 424 | this.workSource = workSource; |
| 425 | } |
| 426 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 427 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 428 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 429 | if (subId != null) { |
| 430 | this.subId = subId; |
| 431 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 432 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 433 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 436 | private static final class IncomingThirdPartyCallArgs { |
| 437 | public final ComponentName component; |
| 438 | public final String callId; |
| 439 | public final String callerDisplayName; |
| 440 | |
| 441 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 442 | String callerDisplayName) { |
| 443 | this.component = component; |
| 444 | this.callId = callId; |
| 445 | this.callerDisplayName = callerDisplayName; |
| 446 | } |
| 447 | } |
| 448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 449 | /** |
| 450 | * A handler that processes messages on the main thread in the phone process. Since many |
| 451 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 452 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 453 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 454 | * on, which will be notified when the operation completes and will contain the result of the |
| 455 | * request. |
| 456 | * |
| 457 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 458 | * note that request.result must be set to something non-null for the calling thread to |
| 459 | * unblock. |
| 460 | */ |
| 461 | private final class MainThreadHandler extends Handler { |
| 462 | @Override |
| 463 | public void handleMessage(Message msg) { |
| 464 | MainThreadRequest request; |
| 465 | Message onCompleted; |
| 466 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 467 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 468 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 469 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | |
| 471 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | case CMD_HANDLE_USSD_REQUEST: { |
| 473 | request = (MainThreadRequest) msg.obj; |
| 474 | final Phone phone = getPhoneFromRequest(request); |
| 475 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 476 | String ussdRequest = ussdObject.first; |
| 477 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 478 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 479 | if (!isUssdApiAllowed(request.subId)) { |
| 480 | // Carrier does not support use of this API, return failure. |
| 481 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 482 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 483 | Bundle returnData = new Bundle(); |
| 484 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 485 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 486 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | request.result = true; |
| 488 | notifyRequester(request); |
| 489 | return; |
| 490 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 491 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | try { |
| 493 | request.result = phone != null |
| 494 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 495 | } catch (CallStateException cse) { |
| 496 | request.result = false; |
| 497 | } |
| 498 | // Wake up the requesting thread |
| 499 | notifyRequester(request); |
| 500 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 503 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 505 | final Phone phone = getPhoneFromRequest(request); |
| 506 | request.result = phone != null ? |
| 507 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 508 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 509 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 510 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 511 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 512 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 513 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 514 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 515 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 517 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 518 | if (uiccCard == null) { |
| 519 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 520 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 522 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 524 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 525 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 527 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 528 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 529 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 530 | break; |
| 531 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 533 | ar = (AsyncResult) msg.obj; |
| 534 | request = (MainThreadRequest) ar.userObj; |
| 535 | if (ar.exception == null && ar.result != null) { |
| 536 | request.result = ar.result; |
| 537 | } else { |
| 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 539 | if (ar.result == null) { |
| 540 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 541 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 543 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | } else { |
| 545 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 546 | } |
| 547 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | break; |
| 550 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 552 | request = (MainThreadRequest) msg.obj; |
| 553 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 554 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | if (uiccCard == null) { |
| 556 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | } else { |
| 560 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 561 | request); |
| 562 | uiccCard.iccTransmitApduBasicChannel( |
| 563 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 564 | iccArgument.p3, iccArgument.data, onCompleted); |
| 565 | } |
| 566 | break; |
| 567 | |
| 568 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 569 | ar = (AsyncResult) msg.obj; |
| 570 | request = (MainThreadRequest) ar.userObj; |
| 571 | if (ar.exception == null && ar.result != null) { |
| 572 | request.result = ar.result; |
| 573 | } else { |
| 574 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 575 | if (ar.result == null) { |
| 576 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 577 | } else if (ar.exception instanceof CommandException) { |
| 578 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 579 | ar.exception); |
| 580 | } else { |
| 581 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 582 | } |
| 583 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | break; |
| 586 | |
| 587 | case CMD_EXCHANGE_SIM_IO: |
| 588 | request = (MainThreadRequest) msg.obj; |
| 589 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 590 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | if (uiccCard == null) { |
| 592 | loge("iccExchangeSimIO: No UICC"); |
| 593 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | } else { |
| 596 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 597 | request); |
| 598 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 599 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 600 | iccArgument.data, onCompleted); |
| 601 | } |
| 602 | break; |
| 603 | |
| 604 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 605 | ar = (AsyncResult) msg.obj; |
| 606 | request = (MainThreadRequest) ar.userObj; |
| 607 | if (ar.exception == null && ar.result != null) { |
| 608 | request.result = ar.result; |
| 609 | } else { |
| 610 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 611 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 612 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | break; |
| 614 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 615 | case CMD_SEND_ENVELOPE: |
| 616 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 617 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 618 | if (uiccCard == null) { |
| 619 | loge("sendEnvelopeWithStatus: No UICC"); |
| 620 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | } else { |
| 623 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 624 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 625 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 626 | break; |
| 627 | |
| 628 | case EVENT_SEND_ENVELOPE_DONE: |
| 629 | ar = (AsyncResult) msg.obj; |
| 630 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 631 | if (ar.exception == null && ar.result != null) { |
| 632 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 633 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 634 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 635 | if (ar.result == null) { |
| 636 | loge("sendEnvelopeWithStatus: Empty response"); |
| 637 | } else if (ar.exception instanceof CommandException) { |
| 638 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 639 | ar.exception); |
| 640 | } else { |
| 641 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 642 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 643 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 644 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | break; |
| 646 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | case CMD_OPEN_CHANNEL: |
| 648 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 649 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 650 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | if (uiccCard == null) { |
| 652 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 653 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 654 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } else { |
| 657 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 658 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 659 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 660 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | case EVENT_OPEN_CHANNEL_DONE: |
| 664 | ar = (AsyncResult) msg.obj; |
| 665 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 667 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | int[] result = (int[]) ar.result; |
| 669 | int channelId = result[0]; |
| 670 | byte[] selectResponse = null; |
| 671 | if (result.length > 1) { |
| 672 | selectResponse = new byte[result.length - 1]; |
| 673 | for (int i = 1; i < result.length; ++i) { |
| 674 | selectResponse[i - 1] = (byte) result[i]; |
| 675 | } |
| 676 | } |
| 677 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 678 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | if (ar.result == null) { |
| 681 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | if (ar.exception != null) { |
| 684 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 685 | } |
| 686 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 687 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 688 | if (ar.exception instanceof CommandException) { |
| 689 | CommandException.Error error = |
| 690 | ((CommandException) (ar.exception)).getCommandError(); |
| 691 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 692 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 693 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 698 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 700 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 701 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 702 | break; |
| 703 | |
| 704 | case CMD_CLOSE_CHANNEL: |
| 705 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 706 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 707 | if (uiccCard == null) { |
| 708 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 709 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 710 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 711 | } else { |
| 712 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 713 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 714 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 719 | break; |
| 720 | |
| 721 | case CMD_NV_READ_ITEM: |
| 722 | request = (MainThreadRequest) msg.obj; |
| 723 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 724 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 725 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | ar = (AsyncResult) msg.obj; |
| 730 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | if (ar.exception == null && ar.result != null) { |
| 732 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | request.result = ""; |
| 735 | if (ar.result == null) { |
| 736 | loge("nvReadItem: Empty response"); |
| 737 | } else if (ar.exception instanceof CommandException) { |
| 738 | loge("nvReadItem: CommandException: " + |
| 739 | ar.exception); |
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 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | break; |
| 746 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | case CMD_NV_WRITE_ITEM: |
| 748 | request = (MainThreadRequest) msg.obj; |
| 749 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 750 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 751 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 752 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case EVENT_NV_WRITE_ITEM_DONE: |
| 756 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 757 | break; |
| 758 | |
| 759 | case CMD_NV_WRITE_CDMA_PRL: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 762 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 766 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 767 | break; |
| 768 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 769 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 771 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 772 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 773 | break; |
| 774 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 775 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 776 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 777 | break; |
| 778 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 779 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 782 | request); |
| 783 | Phone phone = getPhoneFromRequest(request); |
| 784 | if (phone != null) { |
| 785 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 786 | } else { |
| 787 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 788 | request.result = false; |
| 789 | notifyRequester(request); |
| 790 | } |
| 791 | break; |
| 792 | } |
| 793 | |
| 794 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 795 | ar = (AsyncResult) msg.obj; |
| 796 | request = (MainThreadRequest) ar.userObj; |
| 797 | if (ar.exception == null && ar.result != null) { |
| 798 | request.result = ar.result; |
| 799 | } else { |
| 800 | // request.result must be set to something non-null |
| 801 | // for the calling thread to unblock |
| 802 | if (request.result != null) { |
| 803 | request.result = ar.result; |
| 804 | } else { |
| 805 | request.result = false; |
| 806 | } |
| 807 | if (ar.result == null) { |
| 808 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 809 | } else if (ar.exception instanceof CommandException) { |
| 810 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 811 | + ar.exception); |
| 812 | } else { |
| 813 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 814 | } |
| 815 | } |
| 816 | notifyRequester(request); |
| 817 | break; |
| 818 | |
| 819 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 820 | request = (MainThreadRequest) msg.obj; |
| 821 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 822 | Phone phone = getPhoneFromRequest(request); |
| 823 | if (phone != null) { |
| 824 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 825 | request.workSource); |
| 826 | } else { |
| 827 | loge("enableNrDualConnectivity: No phone object"); |
| 828 | request.result = |
| 829 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 830 | notifyRequester(request); |
| 831 | } |
| 832 | break; |
| 833 | } |
| 834 | |
| 835 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 836 | ar = (AsyncResult) msg.obj; |
| 837 | request = (MainThreadRequest) ar.userObj; |
| 838 | if (ar.exception == null) { |
| 839 | request.result = |
| 840 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 841 | } else { |
| 842 | request.result = |
| 843 | TelephonyManager |
| 844 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 845 | if (ar.exception instanceof CommandException) { |
| 846 | CommandException.Error error = |
| 847 | ((CommandException) (ar.exception)).getCommandError(); |
| 848 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 849 | request.result = |
| 850 | TelephonyManager |
| 851 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 852 | } |
| 853 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 854 | + ar.exception); |
| 855 | } else { |
| 856 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 857 | } |
| 858 | } |
| 859 | notifyRequester(request); |
| 860 | break; |
| 861 | } |
| 862 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 863 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 864 | request = (MainThreadRequest) msg.obj; |
| 865 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 866 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 870 | ar = (AsyncResult) msg.obj; |
| 871 | request = (MainThreadRequest) ar.userObj; |
| 872 | if (ar.exception == null && ar.result != null) { |
| 873 | request.result = ar.result; // Integer |
| 874 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 875 | // request.result must be set to something non-null |
| 876 | // for the calling thread to unblock |
| 877 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 878 | if (ar.result == null) { |
| 879 | loge("getPreferredNetworkType: Empty response"); |
| 880 | } else if (ar.exception instanceof CommandException) { |
| 881 | loge("getPreferredNetworkType: CommandException: " + |
| 882 | ar.exception); |
| 883 | } else { |
| 884 | loge("getPreferredNetworkType: Unknown exception"); |
| 885 | } |
| 886 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 891 | request = (MainThreadRequest) msg.obj; |
| 892 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 893 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 894 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | break; |
| 896 | |
| 897 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 898 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 899 | break; |
| 900 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 901 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 902 | request = (MainThreadRequest)msg.obj; |
| 903 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 904 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 905 | break; |
| 906 | |
| 907 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 908 | ar = (AsyncResult)msg.obj; |
| 909 | request = (MainThreadRequest)ar.userObj; |
| 910 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 911 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 912 | break; |
| 913 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 914 | case CMD_SET_VOICEMAIL_NUMBER: |
| 915 | request = (MainThreadRequest) msg.obj; |
| 916 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 917 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 918 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 919 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 923 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 924 | break; |
| 925 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 926 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 927 | request = (MainThreadRequest) msg.obj; |
| 928 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 929 | request); |
| 930 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 931 | break; |
| 932 | |
| 933 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 934 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 935 | break; |
| 936 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 937 | case CMD_PERFORM_NETWORK_SCAN: |
| 938 | request = (MainThreadRequest) msg.obj; |
| 939 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 940 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 941 | break; |
| 942 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 943 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 946 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 947 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 948 | request.argument; |
| 949 | int callForwardingReason = args.first; |
| 950 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 951 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 952 | } |
| 953 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 956 | TelephonyManager.CallForwardingInfoCallback callback = |
| 957 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 958 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 959 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 961 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 962 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 963 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 964 | // any service for voice call. |
| 965 | if ((callForwardInfo.serviceClass |
| 966 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 967 | callForwardingInfo = new CallForwardingInfo(true, |
| 968 | callForwardInfo.reason, |
| 969 | callForwardInfo.number, |
| 970 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 971 | break; |
| 972 | } |
| 973 | } |
| 974 | // Didn't find a call forward info for voice call. |
| 975 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 976 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 977 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 978 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 979 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 980 | } else { |
| 981 | if (ar.result == null) { |
| 982 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 983 | } |
| 984 | if (ar.exception != null) { |
| 985 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 986 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 987 | int errorCode = TelephonyManager |
| 988 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 989 | if (ar.exception instanceof CommandException) { |
| 990 | CommandException.Error error = |
| 991 | ((CommandException) (ar.exception)).getCommandError(); |
| 992 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 993 | errorCode = TelephonyManager |
| 994 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 995 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 996 | errorCode = TelephonyManager |
| 997 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 998 | } |
| 999 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1000 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1001 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1004 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1006 | request = (MainThreadRequest) msg.obj; |
| 1007 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1009 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1010 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1011 | request.argument).first; |
| 1012 | request.phone.setCallForwardingOption( |
| 1013 | callForwardingInfoToSet.isEnabled() |
| 1014 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1015 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | callForwardingInfoToSet.getReason(), |
| 1017 | callForwardingInfoToSet.getNumber(), |
| 1018 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1019 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1021 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | ar = (AsyncResult) msg.obj; |
| 1024 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | Consumer<Integer> callback = |
| 1026 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1027 | request.argument).second; |
| 1028 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1029 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1030 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1031 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | if (ar.exception instanceof CommandException) { |
| 1033 | CommandException.Error error = |
| 1034 | ((CommandException) (ar.exception)).getCommandError(); |
| 1035 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1036 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1037 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1039 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1040 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | } |
| 1042 | } |
| 1043 | callback.accept(errorCode); |
| 1044 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1045 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1046 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1047 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1049 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1051 | request = (MainThreadRequest) msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1053 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 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 EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | ar = (AsyncResult) msg.obj; |
| 1059 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1061 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1062 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1063 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | // Service Class is a bit mask per 3gpp 27.007. |
| 1065 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1066 | if (callForwardResults.length > 1 |
| 1067 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1069 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1071 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1072 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1074 | } |
| 1075 | } else { |
| 1076 | if (ar.result == null) { |
| 1077 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1078 | } |
| 1079 | if (ar.exception != null) { |
| 1080 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1081 | } |
| 1082 | if (ar.exception instanceof CommandException) { |
| 1083 | CommandException.Error error = |
| 1084 | ((CommandException) (ar.exception)).getCommandError(); |
| 1085 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1086 | callForwardingStatus = |
| 1087 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1088 | } |
| 1089 | } |
| 1090 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1092 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1093 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1094 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1096 | request = (MainThreadRequest) msg.obj; |
| 1097 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1099 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1100 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1102 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1104 | ar = (AsyncResult) msg.obj; |
| 1105 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1107 | Consumer<Integer> callback = |
| 1108 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1109 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1110 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | if (ar.exception instanceof CommandException) { |
| 1112 | CommandException.Error error = |
| 1113 | ((CommandException) (ar.exception)).getCommandError(); |
| 1114 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1115 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1116 | } else { |
| 1117 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1118 | } |
| 1119 | } else { |
| 1120 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1121 | } |
| 1122 | } else { |
| 1123 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1124 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1125 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1126 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1127 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1128 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1129 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1130 | ar = (AsyncResult) msg.obj; |
| 1131 | request = (MainThreadRequest) ar.userObj; |
| 1132 | CellNetworkScanResult cellScanResult; |
| 1133 | if (ar.exception == null && ar.result != null) { |
| 1134 | cellScanResult = new CellNetworkScanResult( |
| 1135 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1136 | (List<OperatorInfo>) ar.result); |
| 1137 | } else { |
| 1138 | if (ar.result == null) { |
| 1139 | loge("getCellNetworkScanResults: Empty response"); |
| 1140 | } |
| 1141 | if (ar.exception != null) { |
| 1142 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1143 | } |
| 1144 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1145 | if (ar.exception instanceof CommandException) { |
| 1146 | CommandException.Error error = |
| 1147 | ((CommandException) (ar.exception)).getCommandError(); |
| 1148 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1149 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1150 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1151 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1152 | } |
| 1153 | } |
| 1154 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1155 | } |
| 1156 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1157 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1158 | break; |
| 1159 | |
| 1160 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1161 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1162 | ManualNetworkSelectionArgument selArg = |
| 1163 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1164 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1165 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1166 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1167 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1168 | break; |
| 1169 | |
| 1170 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1171 | ar = (AsyncResult) msg.obj; |
| 1172 | request = (MainThreadRequest) ar.userObj; |
| 1173 | if (ar.exception == null) { |
| 1174 | request.result = true; |
| 1175 | } else { |
| 1176 | request.result = false; |
| 1177 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1178 | } |
| 1179 | notifyRequester(request); |
| 1180 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1181 | break; |
| 1182 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1183 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1184 | request = (MainThreadRequest) msg.obj; |
| 1185 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1186 | if (defaultPhone != null) { |
| 1187 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1188 | } else { |
| 1189 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1190 | Bundle bundle = new Bundle(); |
| 1191 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1192 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1193 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1194 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1195 | break; |
| 1196 | |
| 1197 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1198 | ar = (AsyncResult) msg.obj; |
| 1199 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1200 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1201 | |
| 1202 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1203 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1204 | // Update the last modem activity info and the result of the request. |
| 1205 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1206 | if (isModemActivityInfoValid(info)) { |
| 1207 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1208 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1209 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1210 | .getTransmitTimeMillis(); |
| 1211 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1212 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1213 | } |
| 1214 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1215 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1216 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1217 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1218 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1219 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1220 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1221 | info.getReceiveTimeMillis() |
| 1222 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1223 | } |
| 1224 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1225 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1226 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1227 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1228 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1229 | } else { |
| 1230 | if (ar.result == null) { |
| 1231 | loge("queryModemActivityInfo: Empty response"); |
| 1232 | } else if (ar.exception instanceof CommandException) { |
| 1233 | loge("queryModemActivityInfo: CommandException: " + |
| 1234 | ar.exception); |
| 1235 | } else { |
| 1236 | loge("queryModemActivityInfo: Unknown exception"); |
| 1237 | } |
| 1238 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1239 | Bundle bundle = new Bundle(); |
| 1240 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1241 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1242 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1243 | break; |
| 1244 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1245 | case CMD_SET_ALLOWED_CARRIERS: |
| 1246 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1247 | CarrierRestrictionRules argument = |
| 1248 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1249 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1250 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1251 | break; |
| 1252 | |
| 1253 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1254 | ar = (AsyncResult) msg.obj; |
| 1255 | request = (MainThreadRequest) ar.userObj; |
| 1256 | if (ar.exception == null && ar.result != null) { |
| 1257 | request.result = ar.result; |
| 1258 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1259 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1260 | if (ar.exception instanceof CommandException) { |
| 1261 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1262 | CommandException.Error error = |
| 1263 | ((CommandException) (ar.exception)).getCommandError(); |
| 1264 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1265 | request.result = |
| 1266 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1267 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1268 | } else { |
| 1269 | loge("setAllowedCarriers: Unknown exception"); |
| 1270 | } |
| 1271 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1272 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1273 | break; |
| 1274 | |
| 1275 | case CMD_GET_ALLOWED_CARRIERS: |
| 1276 | request = (MainThreadRequest) msg.obj; |
| 1277 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1278 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1279 | break; |
| 1280 | |
| 1281 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1282 | ar = (AsyncResult) msg.obj; |
| 1283 | request = (MainThreadRequest) ar.userObj; |
| 1284 | if (ar.exception == null && ar.result != null) { |
| 1285 | request.result = ar.result; |
| 1286 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1287 | request.result = new IllegalStateException( |
| 1288 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1289 | if (ar.result == null) { |
| 1290 | loge("getAllowedCarriers: Empty response"); |
| 1291 | } else if (ar.exception instanceof CommandException) { |
| 1292 | loge("getAllowedCarriers: CommandException: " + |
| 1293 | ar.exception); |
| 1294 | } else { |
| 1295 | loge("getAllowedCarriers: Unknown exception"); |
| 1296 | } |
| 1297 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1298 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1299 | break; |
| 1300 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1301 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1302 | ar = (AsyncResult) msg.obj; |
| 1303 | request = (MainThreadRequest) ar.userObj; |
| 1304 | if (ar.exception == null && ar.result != null) { |
| 1305 | request.result = ar.result; |
| 1306 | } else { |
| 1307 | request.result = new IllegalArgumentException( |
| 1308 | "Failed to retrieve Forbidden Plmns"); |
| 1309 | if (ar.result == null) { |
| 1310 | loge("getForbiddenPlmns: Empty response"); |
| 1311 | } else { |
| 1312 | loge("getForbiddenPlmns: Unknown exception"); |
| 1313 | } |
| 1314 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1315 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1316 | break; |
| 1317 | |
| 1318 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1319 | request = (MainThreadRequest) msg.obj; |
| 1320 | uiccCard = getUiccCardFromRequest(request); |
| 1321 | if (uiccCard == null) { |
| 1322 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1323 | request.result = new IllegalArgumentException( |
| 1324 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1325 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1326 | break; |
| 1327 | } |
| 1328 | Integer appType = (Integer) request.argument; |
| 1329 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1330 | if (uiccApp == null) { |
| 1331 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1332 | + appType); |
| 1333 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1334 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1335 | break; |
| 1336 | } else { |
| 1337 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1338 | + " specified type -- " + appType); |
| 1339 | } |
| 1340 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1341 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1342 | onCompleted); |
| 1343 | break; |
| 1344 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1345 | case CMD_SWITCH_SLOTS: |
| 1346 | request = (MainThreadRequest) msg.obj; |
| 1347 | int[] physicalSlots = (int[]) request.argument; |
| 1348 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1349 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1350 | break; |
| 1351 | |
| 1352 | case EVENT_SWITCH_SLOTS_DONE: |
| 1353 | ar = (AsyncResult) msg.obj; |
| 1354 | request = (MainThreadRequest) ar.userObj; |
| 1355 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1356 | notifyRequester(request); |
| 1357 | break; |
| 1358 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1359 | request = (MainThreadRequest) msg.obj; |
| 1360 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1361 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1362 | break; |
| 1363 | |
| 1364 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1365 | ar = (AsyncResult) msg.obj; |
| 1366 | request = (MainThreadRequest) ar.userObj; |
| 1367 | if (ar.exception != null) { |
| 1368 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1369 | } else { |
| 1370 | int mode = ((int[]) ar.result)[0]; |
| 1371 | if (mode == 0) { |
| 1372 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1373 | } else { |
| 1374 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1375 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1376 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1377 | notifyRequester(request); |
| 1378 | break; |
| 1379 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1380 | request = (MainThreadRequest) msg.obj; |
| 1381 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1382 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1383 | break; |
| 1384 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | if (ar.exception != null) { |
| 1388 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1389 | } else { |
| 1390 | request.result = ((int[]) ar.result)[0]; |
| 1391 | } |
| 1392 | notifyRequester(request); |
| 1393 | break; |
| 1394 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1395 | request = (MainThreadRequest) msg.obj; |
| 1396 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1397 | int mode = (int) request.argument; |
| 1398 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1399 | break; |
| 1400 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1401 | ar = (AsyncResult) msg.obj; |
| 1402 | request = (MainThreadRequest) ar.userObj; |
| 1403 | request.result = ar.exception == null; |
| 1404 | notifyRequester(request); |
| 1405 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1406 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1407 | request = (MainThreadRequest) msg.obj; |
| 1408 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1409 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1410 | break; |
| 1411 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1412 | ar = (AsyncResult) msg.obj; |
| 1413 | request = (MainThreadRequest) ar.userObj; |
| 1414 | if (ar.exception != null) { |
| 1415 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1416 | } else { |
| 1417 | request.result = ((int[]) ar.result)[0]; |
| 1418 | } |
| 1419 | notifyRequester(request); |
| 1420 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1421 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1424 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1425 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1426 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1427 | break; |
| 1428 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1429 | ar = (AsyncResult) msg.obj; |
| 1430 | request = (MainThreadRequest) ar.userObj; |
| 1431 | request.result = ar.exception == null; |
| 1432 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1433 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1434 | case CMD_GET_ALL_CELL_INFO: |
| 1435 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1436 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1437 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1438 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1439 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1440 | ar = (AsyncResult) msg.obj; |
| 1441 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1442 | // If a timeout occurs, the response will be null |
| 1443 | request.result = (ar.exception == null && ar.result != null) |
| 1444 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1445 | synchronized (request) { |
| 1446 | request.notifyAll(); |
| 1447 | } |
| 1448 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1449 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1450 | request = (MainThreadRequest) msg.obj; |
| 1451 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1452 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1453 | break; |
| 1454 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1455 | ar = (AsyncResult) msg.obj; |
| 1456 | request = (MainThreadRequest) ar.userObj; |
| 1457 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1458 | try { |
| 1459 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1460 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1461 | cb.onError( |
| 1462 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1463 | ar.exception.getClass().getName(), |
| 1464 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1465 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1466 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1467 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1468 | } else { |
| 1469 | // use the result as returned |
| 1470 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1471 | } |
| 1472 | } catch (RemoteException re) { |
| 1473 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1474 | } |
| 1475 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1476 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1477 | request = (MainThreadRequest) msg.obj; |
| 1478 | WorkSource ws = (WorkSource) request.argument; |
| 1479 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1480 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1481 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1482 | } |
| 1483 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1484 | ar = (AsyncResult) msg.obj; |
| 1485 | request = (MainThreadRequest) ar.userObj; |
| 1486 | if (ar.exception == null) { |
| 1487 | request.result = ar.result; |
| 1488 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1489 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1491 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | synchronized (request) { |
| 1495 | request.notifyAll(); |
| 1496 | } |
| 1497 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1498 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1499 | case CMD_MODEM_REBOOT: |
| 1500 | request = (MainThreadRequest) msg.obj; |
| 1501 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1502 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1503 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1504 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1505 | handleNullReturnEvent(msg, "rebootModem"); |
| 1506 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1507 | case CMD_REQUEST_ENABLE_MODEM: |
| 1508 | request = (MainThreadRequest) msg.obj; |
| 1509 | boolean enable = (boolean) request.argument; |
| 1510 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1511 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1512 | PhoneConfigurationManager.getInstance() |
| 1513 | .enablePhone(request.phone, enable, onCompleted); |
| 1514 | break; |
| 1515 | case EVENT_ENABLE_MODEM_DONE: |
| 1516 | ar = (AsyncResult) msg.obj; |
| 1517 | request = (MainThreadRequest) ar.userObj; |
| 1518 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1519 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1520 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1521 | if ((boolean) request.result) { |
| 1522 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1523 | updateModemStateMetrics(); |
| 1524 | } else { |
| 1525 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1526 | + ar.exception); |
| 1527 | } |
| 1528 | notifyRequester(request); |
| 1529 | break; |
| 1530 | case CMD_GET_MODEM_STATUS: |
| 1531 | request = (MainThreadRequest) msg.obj; |
| 1532 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1533 | PhoneConfigurationManager.getInstance() |
| 1534 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1535 | break; |
| 1536 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1537 | ar = (AsyncResult) msg.obj; |
| 1538 | request = (MainThreadRequest) ar.userObj; |
| 1539 | int id = request.phone.getPhoneId(); |
| 1540 | if (ar.exception == null && ar.result != null) { |
| 1541 | request.result = ar.result; |
| 1542 | //update the cache as modem status has changed |
| 1543 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1544 | (boolean) request.result); |
| 1545 | } else { |
| 1546 | // Return true if modem status cannot be retrieved. For most cases, |
| 1547 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1548 | // and disable modem are not supported. Modem is always on. |
| 1549 | // TODO: this should be fixed in R to support a third |
| 1550 | // status UNKNOWN b/131631629 |
| 1551 | request.result = true; |
| 1552 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1553 | + ar.exception); |
| 1554 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1555 | notifyRequester(request); |
| 1556 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1557 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1558 | request = (MainThreadRequest) msg.obj; |
| 1559 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1560 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1561 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1562 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1563 | break; |
| 1564 | } |
| 1565 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1566 | ar = (AsyncResult) msg.obj; |
| 1567 | request = (MainThreadRequest) ar.userObj; |
| 1568 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1569 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1570 | args.second.accept(ar.exception == null); |
| 1571 | notifyRequester(request); |
| 1572 | break; |
| 1573 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1574 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1575 | request = (MainThreadRequest) msg.obj; |
| 1576 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1577 | Phone phone = getPhoneFromRequest(request); |
| 1578 | if (phone != null) { |
| 1579 | phone.getSystemSelectionChannels(onCompleted); |
| 1580 | } else { |
| 1581 | loge("getSystemSelectionChannels: No phone object"); |
| 1582 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1583 | notifyRequester(request); |
| 1584 | } |
| 1585 | break; |
| 1586 | } |
| 1587 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1588 | ar = (AsyncResult) msg.obj; |
| 1589 | request = (MainThreadRequest) ar.userObj; |
| 1590 | if (ar.exception == null && ar.result != null) { |
| 1591 | request.result = ar.result; |
| 1592 | } else { |
| 1593 | request.result = new IllegalArgumentException( |
| 1594 | "Failed to retrieve system selection channels"); |
| 1595 | if (ar.result == null) { |
| 1596 | loge("getSystemSelectionChannels: Empty response"); |
| 1597 | } else { |
| 1598 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1599 | } |
| 1600 | } |
| 1601 | notifyRequester(request); |
| 1602 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1603 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1604 | ar = (AsyncResult) msg.obj; |
| 1605 | request = (MainThreadRequest) ar.userObj; |
| 1606 | if (ar.exception == null && ar.result != null) { |
| 1607 | request.result = ar.result; |
| 1608 | } else { |
| 1609 | request.result = -1; |
| 1610 | loge("Failed to set Forbidden Plmns"); |
| 1611 | if (ar.result == null) { |
| 1612 | loge("setForbidenPlmns: Empty response"); |
| 1613 | } else if (ar.exception != null) { |
| 1614 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1615 | request.result = -1; |
| 1616 | } else { |
| 1617 | loge("setForbiddenPlmns: Unknown exception"); |
| 1618 | } |
| 1619 | } |
| 1620 | notifyRequester(request); |
| 1621 | break; |
| 1622 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1623 | request = (MainThreadRequest) msg.obj; |
| 1624 | uiccCard = getUiccCardFromRequest(request); |
| 1625 | if (uiccCard == null) { |
| 1626 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1627 | request.result = -1; |
| 1628 | notifyRequester(request); |
| 1629 | break; |
| 1630 | } |
| 1631 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1632 | (Pair<Integer, List<String>>) request.argument; |
| 1633 | appType = setFplmnsArgs.first; |
| 1634 | List<String> fplmns = setFplmnsArgs.second; |
| 1635 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1636 | if (uiccApp == null) { |
| 1637 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1638 | request.result = -1; |
| 1639 | loge("Failed to get UICC App"); |
| 1640 | notifyRequester(request); |
| 1641 | } else { |
| 1642 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1643 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1644 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1645 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1646 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1647 | case CMD_ERASE_MODEM_CONFIG: |
| 1648 | request = (MainThreadRequest) msg.obj; |
| 1649 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1650 | defaultPhone.eraseModemConfig(onCompleted); |
| 1651 | break; |
| 1652 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1653 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1654 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1655 | |
| 1656 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1659 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1660 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1661 | changed.first, changed.second, onCompleted); |
| 1662 | break; |
| 1663 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
| 1666 | if (ar.exception == null) { |
| 1667 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1668 | } else { |
| 1669 | request.result = msg.arg1; |
| 1670 | } |
| 1671 | notifyRequester(request); |
| 1672 | break; |
| 1673 | |
| 1674 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1675 | request = (MainThreadRequest) msg.obj; |
| 1676 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1677 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1678 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1679 | enabled.first, enabled.second, onCompleted); |
| 1680 | break; |
| 1681 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1682 | ar = (AsyncResult) msg.obj; |
| 1683 | request = (MainThreadRequest) ar.userObj; |
| 1684 | if (ar.exception == null) { |
| 1685 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1686 | } else { |
| 1687 | request.result = msg.arg1; |
| 1688 | } |
| 1689 | notifyRequester(request); |
| 1690 | break; |
| 1691 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1692 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1693 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1694 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1695 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1696 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1697 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1698 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1699 | |
| 1700 | case CMD_SET_DATA_THROTTLING: { |
| 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1703 | DataThrottlingRequest dataThrottlingRequest = |
| 1704 | (DataThrottlingRequest) request.argument; |
| 1705 | Phone phone = getPhoneFromRequest(request); |
| 1706 | if (phone != null) { |
| 1707 | phone.setDataThrottling(onCompleted, |
| 1708 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1709 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1710 | } else { |
| 1711 | loge("setDataThrottling: No phone object"); |
| 1712 | request.result = |
| 1713 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1714 | notifyRequester(request); |
| 1715 | } |
| 1716 | |
| 1717 | break; |
| 1718 | } |
| 1719 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1720 | ar = (AsyncResult) msg.obj; |
| 1721 | request = (MainThreadRequest) ar.userObj; |
| 1722 | |
| 1723 | if (ar.exception == null) { |
| 1724 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1725 | } else if (ar.exception instanceof CommandException) { |
| 1726 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1727 | CommandException.Error error = |
| 1728 | ((CommandException) (ar.exception)).getCommandError(); |
| 1729 | |
| 1730 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1731 | request.result = TelephonyManager |
| 1732 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1733 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1734 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1735 | } else { |
| 1736 | request.result = |
| 1737 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1738 | } |
| 1739 | } else { |
| 1740 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1741 | } |
| 1742 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1743 | notifyRequester(request); |
| 1744 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1745 | |
| 1746 | case CMD_SET_SIM_POWER: { |
| 1747 | request = (MainThreadRequest) msg.obj; |
| 1748 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1749 | request = (MainThreadRequest) msg.obj; |
| 1750 | int stateToSet = |
| 1751 | ((Pair<Integer, IIntegerConsumer>) |
| 1752 | request.argument).first; |
| 1753 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1754 | break; |
| 1755 | } |
| 1756 | case EVENT_SET_SIM_POWER_DONE: { |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | IIntegerConsumer callback = |
| 1760 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1761 | if (ar.exception != null) { |
| 1762 | loge("setSimPower exception: " + ar.exception); |
| 1763 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1764 | .RESULT_ERROR_UNKNOWN; |
| 1765 | if (ar.exception instanceof CommandException) { |
| 1766 | CommandException.Error error = |
| 1767 | ((CommandException) (ar.exception)).getCommandError(); |
| 1768 | if (error == CommandException.Error.SIM_ERR) { |
| 1769 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1770 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1771 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1772 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1773 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1774 | } else { |
| 1775 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1776 | } |
| 1777 | } |
| 1778 | try { |
| 1779 | callback.accept(errorCode); |
| 1780 | } catch (RemoteException e) { |
| 1781 | // Ignore if the remote process is no longer available to call back. |
| 1782 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1783 | } |
| 1784 | } else { |
| 1785 | try { |
| 1786 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 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 | } |
| 1792 | break; |
| 1793 | } |
| 1794 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1795 | default: |
| 1796 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1797 | break; |
| 1798 | } |
| 1799 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1800 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1801 | private void notifyRequester(MainThreadRequest request) { |
| 1802 | synchronized (request) { |
| 1803 | request.notifyAll(); |
| 1804 | } |
| 1805 | } |
| 1806 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1807 | private void handleNullReturnEvent(Message msg, String command) { |
| 1808 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1809 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1810 | if (ar.exception == null) { |
| 1811 | request.result = true; |
| 1812 | } else { |
| 1813 | request.result = false; |
| 1814 | if (ar.exception instanceof CommandException) { |
| 1815 | loge(command + ": CommandException: " + ar.exception); |
| 1816 | } else { |
| 1817 | loge(command + ": Unknown exception"); |
| 1818 | } |
| 1819 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1820 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1821 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | /** |
| 1825 | * Posts the specified command to be executed on the main thread, |
| 1826 | * waits for the request to complete, and returns the result. |
| 1827 | * @see #sendRequestAsync |
| 1828 | */ |
| 1829 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1830 | return sendRequest( |
| 1831 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * Posts the specified command to be executed on the main thread, |
| 1836 | * waits for the request to complete, and returns the result. |
| 1837 | * @see #sendRequestAsync |
| 1838 | */ |
| 1839 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1840 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1841 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | /** |
| 1845 | * Posts the specified command to be executed on the main thread, |
| 1846 | * waits for the request to complete, and returns the result. |
| 1847 | * @see #sendRequestAsync |
| 1848 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1849 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1850 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /** |
| 1854 | * Posts the specified command to be executed on the main thread, |
| 1855 | * waits for the request to complete, and returns the result. |
| 1856 | * @see #sendRequestAsync |
| 1857 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1858 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1859 | return sendRequest(command, argument, subId, null, workSource); |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * Posts the specified command to be executed on the main thread, |
| 1864 | * waits for the request to complete, and returns the result. |
| 1865 | * @see #sendRequestAsync |
| 1866 | */ |
| 1867 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1868 | return sendRequest( |
| 1869 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1870 | } |
| 1871 | |
| 1872 | /** |
| 1873 | * Posts the specified command to be executed on the main thread, |
| 1874 | * waits for the request to complete, and returns the result. |
| 1875 | * @see #sendRequestAsync |
| 1876 | */ |
| 1877 | private Object sendRequest( |
| 1878 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1880 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1881 | } |
| 1882 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1883 | MainThreadRequest request = null; |
| 1884 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1885 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1886 | } else if (phone != null) { |
| 1887 | request = new MainThreadRequest(argument, phone, workSource); |
| 1888 | } else { |
| 1889 | request = new MainThreadRequest(argument, subId, workSource); |
| 1890 | } |
| 1891 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1893 | msg.sendToTarget(); |
| 1894 | |
| 1895 | // Wait for the request to complete |
| 1896 | synchronized (request) { |
| 1897 | while (request.result == null) { |
| 1898 | try { |
| 1899 | request.wait(); |
| 1900 | } catch (InterruptedException e) { |
| 1901 | // Do nothing, go back and wait until the request is complete |
| 1902 | } |
| 1903 | } |
| 1904 | } |
| 1905 | return request.result; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1910 | * Posts the specified command to be executed on the main thread, and |
| 1911 | * returns immediately. |
| 1912 | * @see #sendRequest |
| 1913 | */ |
| 1914 | private void sendRequestAsync(int command) { |
| 1915 | mMainThreadHandler.sendEmptyMessage(command); |
| 1916 | } |
| 1917 | |
| 1918 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1919 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1920 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1921 | */ |
| 1922 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1923 | sendRequestAsync(command, argument, null, null); |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1928 | * @see {@link #sendRequest(int,Object)} |
| 1929 | */ |
| 1930 | private void sendRequestAsync( |
| 1931 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1932 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1933 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1934 | msg.sendToTarget(); |
| 1935 | } |
| 1936 | |
| 1937 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1938 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1939 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1940 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1941 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | synchronized (PhoneInterfaceManager.class) { |
| 1943 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1944 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1945 | } else { |
| 1946 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1947 | } |
| 1948 | return sInstance; |
| 1949 | } |
| 1950 | } |
| 1951 | |
| 1952 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1953 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1955 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1956 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1957 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1958 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1959 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1960 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1961 | mTelephonySharedPreferences = |
| 1962 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1963 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1964 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1965 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1966 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1967 | publish(); |
| 1968 | } |
| 1969 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1970 | private Phone getDefaultPhone() { |
| 1971 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1972 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1973 | } |
| 1974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | private void publish() { |
| 1976 | if (DBG) log("publish: " + this); |
| 1977 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1978 | TelephonyFrameworkInitializer |
| 1979 | .getTelephonyServiceManager() |
| 1980 | .getTelephonyServiceRegisterer() |
| 1981 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1984 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1985 | if (request.phone != null) { |
| 1986 | return request.phone; |
| 1987 | } else { |
| 1988 | return getPhoneFromSubId(request.subId); |
| 1989 | } |
| 1990 | } |
| 1991 | |
| 1992 | private Phone getPhoneFromSubId(int subId) { |
| 1993 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1994 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1997 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1998 | Phone phone = getPhoneFromRequest(request); |
| 1999 | return phone == null ? null : |
| 2000 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2001 | } |
| 2002 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2003 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2004 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2005 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2006 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2008 | private void sendEraseModemConfig(Phone phone) { |
| 2009 | if (phone != null) { |
| 2010 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2011 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2012 | final long identity = Binder.clearCallingIdentity(); |
| 2013 | try { |
| 2014 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2015 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2016 | } finally { |
| 2017 | Binder.restoreCallingIdentity(identity); |
| 2018 | } |
| 2019 | } |
| 2020 | } |
| 2021 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2022 | private boolean isImsAvailableOnDevice() { |
| 2023 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2024 | if (pm == null) { |
| 2025 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2026 | // so do not throw error and allow. |
| 2027 | return true; |
| 2028 | } |
| 2029 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2030 | } |
| 2031 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2032 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2033 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2036 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | if (DBG) log("dial: " + number); |
| 2038 | // No permission check needed here: This is just a wrapper around the |
| 2039 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2040 | // the UI before it does anything. |
| 2041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | final long identity = Binder.clearCallingIdentity(); |
| 2043 | try { |
| 2044 | String url = createTelUrl(number); |
| 2045 | if (url == null) { |
| 2046 | return; |
| 2047 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2049 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2050 | PhoneConstants.State state = mCM.getState(subId); |
| 2051 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2052 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2053 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2054 | mApp.startActivity(intent); |
| 2055 | } |
| 2056 | } finally { |
| 2057 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2062 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2065 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | if (DBG) log("call: " + number); |
| 2067 | |
| 2068 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2069 | // need to do a permission check since we're calling startActivity() |
| 2070 | // from the context of the phone app. |
| 2071 | enforceCallPermission(); |
| 2072 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2073 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2074 | != AppOpsManager.MODE_ALLOWED) { |
| 2075 | return; |
| 2076 | } |
| 2077 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2078 | final long identity = Binder.clearCallingIdentity(); |
| 2079 | try { |
| 2080 | String url = createTelUrl(number); |
| 2081 | if (url == null) { |
| 2082 | return; |
| 2083 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2085 | boolean isValid = false; |
| 2086 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2087 | if (slist != null) { |
| 2088 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2089 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2090 | isValid = true; |
| 2091 | break; |
| 2092 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2093 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2094 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2095 | if (!isValid) { |
| 2096 | return; |
| 2097 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2098 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2100 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2101 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2102 | mApp.startActivity(intent); |
| 2103 | } finally { |
| 2104 | Binder.restoreCallingIdentity(identity); |
| 2105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2108 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2109 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2110 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2111 | } |
| 2112 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2113 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2114 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2115 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2116 | } |
| 2117 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2118 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2119 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | |
| 2121 | final long identity = Binder.clearCallingIdentity(); |
| 2122 | try { |
| 2123 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2124 | checkSimPin.start(); |
| 2125 | return checkSimPin.unlockSim(null, pin); |
| 2126 | } finally { |
| 2127 | Binder.restoreCallingIdentity(identity); |
| 2128 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2131 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | |
| 2134 | final long identity = Binder.clearCallingIdentity(); |
| 2135 | try { |
| 2136 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2137 | checkSimPuk.start(); |
| 2138 | return checkSimPuk.unlockSim(puk, pin); |
| 2139 | } finally { |
| 2140 | Binder.restoreCallingIdentity(identity); |
| 2141 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2145 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | * a synchronous one. |
| 2147 | */ |
| 2148 | private static class UnlockSim extends Thread { |
| 2149 | |
| 2150 | private final IccCard mSimCard; |
| 2151 | |
| 2152 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2153 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2154 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | |
| 2156 | // For replies from SimCard interface |
| 2157 | private Handler mHandler; |
| 2158 | |
| 2159 | // For async handler to identify request type |
| 2160 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2161 | |
| 2162 | public UnlockSim(IccCard simCard) { |
| 2163 | mSimCard = simCard; |
| 2164 | } |
| 2165 | |
| 2166 | @Override |
| 2167 | public void run() { |
| 2168 | Looper.prepare(); |
| 2169 | synchronized (UnlockSim.this) { |
| 2170 | mHandler = new Handler() { |
| 2171 | @Override |
| 2172 | public void handleMessage(Message msg) { |
| 2173 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2174 | switch (msg.what) { |
| 2175 | case SUPPLY_PIN_COMPLETE: |
| 2176 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2177 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2178 | mRetryCount = msg.arg1; |
| 2179 | if (ar.exception != null) { |
| 2180 | if (ar.exception instanceof CommandException && |
| 2181 | ((CommandException)(ar.exception)).getCommandError() |
| 2182 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2183 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2184 | } //When UiccCardApp dispose,handle message and return exception |
| 2185 | else if (ar.exception instanceof CommandException && |
| 2186 | ((CommandException) (ar.exception)).getCommandError() |
| 2187 | == CommandException.Error.ABORTED) { |
| 2188 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2189 | } else { |
| 2190 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2191 | } |
| 2192 | } else { |
| 2193 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | mDone = true; |
| 2196 | UnlockSim.this.notifyAll(); |
| 2197 | } |
| 2198 | break; |
| 2199 | } |
| 2200 | } |
| 2201 | }; |
| 2202 | UnlockSim.this.notifyAll(); |
| 2203 | } |
| 2204 | Looper.loop(); |
| 2205 | } |
| 2206 | |
| 2207 | /* |
| 2208 | * Use PIN or PUK to unlock SIM card |
| 2209 | * |
| 2210 | * If PUK is null, unlock SIM card with PIN |
| 2211 | * |
| 2212 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2213 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2214 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | |
| 2216 | while (mHandler == null) { |
| 2217 | try { |
| 2218 | wait(); |
| 2219 | } catch (InterruptedException e) { |
| 2220 | Thread.currentThread().interrupt(); |
| 2221 | } |
| 2222 | } |
| 2223 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2224 | |
| 2225 | if (puk == null) { |
| 2226 | mSimCard.supplyPin(pin, callback); |
| 2227 | } else { |
| 2228 | mSimCard.supplyPuk(puk, pin, callback); |
| 2229 | } |
| 2230 | |
| 2231 | while (!mDone) { |
| 2232 | try { |
| 2233 | Log.d(LOG_TAG, "wait for done"); |
| 2234 | wait(); |
| 2235 | } catch (InterruptedException e) { |
| 2236 | // Restore the interrupted status |
| 2237 | Thread.currentThread().interrupt(); |
| 2238 | } |
| 2239 | } |
| 2240 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2241 | int[] resultArray = new int[2]; |
| 2242 | resultArray[0] = mResult; |
| 2243 | resultArray[1] = mRetryCount; |
| 2244 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2248 | /** |
| 2249 | * This method has been removed due to privacy and stability concerns. |
| 2250 | */ |
| 2251 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2253 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2254 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2257 | @Override |
| 2258 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2259 | mApp.getSystemService(AppOpsManager.class) |
| 2260 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2261 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2262 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2263 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2264 | // Callers targeting S have no business invoking this method. |
| 2265 | return; |
| 2266 | } |
| 2267 | |
| 2268 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2269 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2270 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2271 | .setCallingPackage(callingPackage) |
| 2272 | .setCallingFeatureId(null) |
| 2273 | .setCallingPid(Binder.getCallingPid()) |
| 2274 | .setCallingUid(Binder.getCallingUid()) |
| 2275 | .setMethod("updateServiceLocation") |
| 2276 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2277 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2278 | .build()); |
| 2279 | // Apps that lack location permission have no business calling this method; |
| 2280 | // however, because no permission was declared in the public API, denials must |
| 2281 | // all be "soft". |
| 2282 | switch (locationResult) { |
| 2283 | case DENIED_HARD: /* fall through */ |
| 2284 | case DENIED_SOFT: |
| 2285 | return; |
| 2286 | } |
| 2287 | |
| 2288 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2289 | final long identity = Binder.clearCallingIdentity(); |
| 2290 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2291 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2293 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2294 | } |
| 2295 | } finally { |
| 2296 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2297 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2300 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2301 | @Override |
| 2302 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2303 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2306 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2307 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2308 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2309 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2310 | callingFeatureId); |
| 2311 | } |
| 2312 | |
| 2313 | @Deprecated |
| 2314 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2315 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2316 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2317 | } |
| 2318 | |
| 2319 | @Override |
| 2320 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2321 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2322 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2323 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2324 | return false; |
| 2325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2326 | |
| 2327 | final long identity = Binder.clearCallingIdentity(); |
| 2328 | try { |
| 2329 | return isRadioOnForSubscriber(subId); |
| 2330 | } finally { |
| 2331 | Binder.restoreCallingIdentity(identity); |
| 2332 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2336 | final long identity = Binder.clearCallingIdentity(); |
| 2337 | try { |
| 2338 | final Phone phone = getPhone(subId); |
| 2339 | if (phone != null) { |
| 2340 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2341 | } else { |
| 2342 | return false; |
| 2343 | } |
| 2344 | } finally { |
| 2345 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2346 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2350 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2352 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2353 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2355 | |
| 2356 | final long identity = Binder.clearCallingIdentity(); |
| 2357 | try { |
| 2358 | final Phone phone = getPhone(subId); |
| 2359 | if (phone != null) { |
| 2360 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2361 | } |
| 2362 | } finally { |
| 2363 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2364 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2368 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2371 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2372 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2373 | |
| 2374 | final long identity = Binder.clearCallingIdentity(); |
| 2375 | try { |
| 2376 | final Phone phone = getPhone(subId); |
| 2377 | if (phone == null) { |
| 2378 | return false; |
| 2379 | } |
| 2380 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2381 | toggleRadioOnOffForSubscriber(subId); |
| 2382 | } |
| 2383 | return true; |
| 2384 | } finally { |
| 2385 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2386 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2388 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2389 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2390 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2391 | /* |
| 2392 | * If any of the Radios are available, it will need to be |
| 2393 | * shutdown. So return true if any Radio is available. |
| 2394 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2395 | final long identity = Binder.clearCallingIdentity(); |
| 2396 | try { |
| 2397 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2398 | Phone phone = PhoneFactory.getPhone(i); |
| 2399 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2400 | } |
| 2401 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2402 | return false; |
| 2403 | } finally { |
| 2404 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2405 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2408 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2409 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | enforceModifyPermission(); |
| 2411 | |
| 2412 | final long identity = Binder.clearCallingIdentity(); |
| 2413 | try { |
| 2414 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2415 | logv("Shutting down Phone " + i); |
| 2416 | shutdownRadioUsingPhoneId(i); |
| 2417 | } |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2424 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2425 | if (phone != null && phone.isRadioAvailable()) { |
| 2426 | phone.shutdownRadio(); |
| 2427 | } |
| 2428 | } |
| 2429 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2431 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2432 | |
| 2433 | final long identity = Binder.clearCallingIdentity(); |
| 2434 | try { |
| 2435 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2436 | if (defaultPhone != null) { |
| 2437 | defaultPhone.setRadioPower(turnOn); |
| 2438 | return true; |
| 2439 | } else { |
| 2440 | loge("There's no default phone."); |
| 2441 | return false; |
| 2442 | } |
| 2443 | } finally { |
| 2444 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2445 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2446 | } |
| 2447 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2448 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2450 | |
| 2451 | final long identity = Binder.clearCallingIdentity(); |
| 2452 | try { |
| 2453 | final Phone phone = getPhone(subId); |
| 2454 | if (phone != null) { |
| 2455 | phone.setRadioPower(turnOn); |
| 2456 | return true; |
| 2457 | } else { |
| 2458 | return false; |
| 2459 | } |
| 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2465 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2466 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2467 | public boolean enableDataConnectivity() { |
| 2468 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | |
| 2470 | final long identity = Binder.clearCallingIdentity(); |
| 2471 | try { |
| 2472 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2473 | final Phone phone = getPhone(subId); |
| 2474 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2475 | phone.getDataEnabledSettings().setDataEnabled( |
| 2476 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2477 | return true; |
| 2478 | } else { |
| 2479 | return false; |
| 2480 | } |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2486 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2487 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | public boolean disableDataConnectivity() { |
| 2489 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | |
| 2491 | final long identity = Binder.clearCallingIdentity(); |
| 2492 | try { |
| 2493 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2494 | final Phone phone = getPhone(subId); |
| 2495 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2496 | phone.getDataEnabledSettings().setDataEnabled( |
| 2497 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | return true; |
| 2499 | } else { |
| 2500 | return false; |
| 2501 | } |
| 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2507 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2508 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | final long identity = Binder.clearCallingIdentity(); |
| 2510 | try { |
| 2511 | final Phone phone = getPhone(subId); |
| 2512 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2513 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | } else { |
| 2515 | return false; |
| 2516 | } |
| 2517 | } finally { |
| 2518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2523 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2526 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | enforceCallPermission(); |
| 2528 | |
| 2529 | final long identity = Binder.clearCallingIdentity(); |
| 2530 | try { |
| 2531 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2532 | return; |
| 2533 | } |
| 2534 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2535 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
| 2538 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2539 | }; |
| 2540 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2541 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2547 | return false; |
| 2548 | } |
| 2549 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2552 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2556 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2559 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | final long identity = Binder.clearCallingIdentity(); |
| 2561 | try { |
| 2562 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2563 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2564 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
| 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2570 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2571 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2572 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2573 | } |
| 2574 | |
| 2575 | @Override |
| 2576 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2579 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | if (phone != null) { |
| 2581 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2582 | } else { |
| 2583 | return PhoneConstantConversions.convertDataState( |
| 2584 | PhoneConstants.DataState.DISCONNECTED); |
| 2585 | } |
| 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2588 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2591 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2592 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2593 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2594 | } |
| 2595 | |
| 2596 | @Override |
| 2597 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2600 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | if (phone != null) { |
| 2602 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2603 | } else { |
| 2604 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2605 | } |
| 2606 | } finally { |
| 2607 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2608 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
| 2611 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2612 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2613 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2614 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2615 | |
| 2616 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2617 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2618 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2619 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2620 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2621 | .setCallingPid(Binder.getCallingPid()) |
| 2622 | .setCallingUid(Binder.getCallingUid()) |
| 2623 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2624 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2625 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2626 | .build()); |
| 2627 | switch (locationResult) { |
| 2628 | case DENIED_HARD: |
| 2629 | throw new SecurityException("Not allowed to access cell location"); |
| 2630 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2631 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2632 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2635 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | final long identity = Binder.clearCallingIdentity(); |
| 2637 | try { |
| 2638 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2639 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2640 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | } finally { |
| 2642 | Binder.restoreCallingIdentity(identity); |
| 2643 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2646 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2647 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2648 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2649 | // registered cell info, so return a NULL country instead. |
| 2650 | final long identity = Binder.clearCallingIdentity(); |
| 2651 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2652 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2653 | // Get default phone in this case. |
| 2654 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2655 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2656 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2658 | if (phone == null) return ""; |
| 2659 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2660 | if (sst == null) return ""; |
| 2661 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2662 | if (lt == null) return ""; |
| 2663 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2664 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2665 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2666 | } finally { |
| 2667 | Binder.restoreCallingIdentity(identity); |
| 2668 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2669 | } |
| 2670 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2671 | /** |
| 2672 | * This method was removed due to potential issues caused by performing partial |
| 2673 | * updates of service state, and lack of a credible use case. |
| 2674 | * |
| 2675 | * This has the ability to break the telephony implementation by disabling notification of |
| 2676 | * changes in device connectivity. DO NOT USE THIS! |
| 2677 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2678 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | public void enableLocationUpdates() { |
| 2680 | mApp.enforceCallingOrSelfPermission( |
| 2681 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2684 | /** |
| 2685 | * This method was removed due to potential issues caused by performing partial |
| 2686 | * updates of service state, and lack of a credible use case. |
| 2687 | * |
| 2688 | * This has the ability to break the telephony implementation by disabling notification of |
| 2689 | * changes in device connectivity. DO NOT USE THIS! |
| 2690 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | @Override |
| 2692 | public void disableLocationUpdates() { |
| 2693 | mApp.enforceCallingOrSelfPermission( |
| 2694 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | @Override |
| 2698 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2699 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2700 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2701 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2702 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2703 | throw new SecurityException( |
| 2704 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2705 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2706 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2707 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2708 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2709 | return null; |
| 2710 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2711 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2712 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2714 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2715 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2717 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2718 | for (CellInfo ci : info) { |
| 2719 | if (ci instanceof CellInfoGsm) { |
| 2720 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2721 | } else if (ci instanceof CellInfoWcdma) { |
| 2722 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2725 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2728 | private List<CellInfo> getCachedCellInfo() { |
| 2729 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2730 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2731 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2732 | if (info != null) cellInfos.addAll(info); |
| 2733 | } |
| 2734 | return cellInfos; |
| 2735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | |
| 2737 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2738 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2739 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2740 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2741 | |
| 2742 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2743 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2744 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2745 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2746 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2747 | .setCallingPid(Binder.getCallingPid()) |
| 2748 | .setCallingUid(Binder.getCallingUid()) |
| 2749 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2750 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2751 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2752 | .build()); |
| 2753 | switch (locationResult) { |
| 2754 | case DENIED_HARD: |
| 2755 | throw new SecurityException("Not allowed to access cell info"); |
| 2756 | case DENIED_SOFT: |
| 2757 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2760 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2761 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2762 | return getCachedCellInfo(); |
| 2763 | } |
| 2764 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2765 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2766 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2770 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2771 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2772 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | if (info != null) cellInfos.addAll(info); |
| 2774 | } |
| 2775 | return cellInfos; |
| 2776 | } finally { |
| 2777 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | } |
| 2779 | } |
| 2780 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2781 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2782 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2783 | String callingFeatureId) { |
| 2784 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2785 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2789 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2790 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2791 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2792 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2793 | } |
| 2794 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2795 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2796 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2797 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2798 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2799 | |
| 2800 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2801 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2802 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2803 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2804 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2805 | .setCallingPid(Binder.getCallingPid()) |
| 2806 | .setCallingUid(Binder.getCallingUid()) |
| 2807 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2808 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2809 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2810 | .build()); |
| 2811 | switch (locationResult) { |
| 2812 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2813 | if (TelephonyPermissions |
| 2814 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2815 | // Safetynet logging for b/154934934 |
| 2816 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2817 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2818 | throw new SecurityException("Not allowed to access cell info"); |
| 2819 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2820 | if (TelephonyPermissions |
| 2821 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2822 | // Safetynet logging for b/154934934 |
| 2823 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2824 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2825 | try { |
| 2826 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2827 | } catch (RemoteException re) { |
| 2828 | // Drop without consequences |
| 2829 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2830 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2833 | |
| 2834 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2835 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2836 | |
| 2837 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2838 | } |
| 2839 | |
| 2840 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2842 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2843 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2844 | |
| 2845 | final long identity = Binder.clearCallingIdentity(); |
| 2846 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2847 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2848 | } finally { |
| 2849 | Binder.restoreCallingIdentity(identity); |
| 2850 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2853 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2854 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2855 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2856 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2857 | return null; |
| 2858 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2859 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2860 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2861 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2862 | return null; |
| 2863 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | |
| 2865 | final long identity = Binder.clearCallingIdentity(); |
| 2866 | try { |
| 2867 | return phone.getImei(); |
| 2868 | } finally { |
| 2869 | Binder.restoreCallingIdentity(identity); |
| 2870 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2874 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2875 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2876 | String tac = null; |
| 2877 | if (phone != null) { |
| 2878 | String imei = phone.getImei(); |
| 2879 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2880 | } |
| 2881 | return tac; |
| 2882 | } |
| 2883 | |
| 2884 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2885 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2886 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2887 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2888 | return null; |
| 2889 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2890 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2891 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2892 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2893 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2894 | return null; |
| 2895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 | |
| 2897 | final long identity = Binder.clearCallingIdentity(); |
| 2898 | try { |
| 2899 | return phone.getMeid(); |
| 2900 | } finally { |
| 2901 | Binder.restoreCallingIdentity(identity); |
| 2902 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2906 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2907 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2908 | String manufacturerCode = null; |
| 2909 | if (phone != null) { |
| 2910 | String meid = phone.getMeid(); |
| 2911 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2912 | } |
| 2913 | return manufacturerCode; |
| 2914 | } |
| 2915 | |
| 2916 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2917 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2918 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2919 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2920 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2921 | return null; |
| 2922 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2923 | int subId = phone.getSubId(); |
| 2924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2925 | mApp, subId, callingPackage, callingFeatureId, |
| 2926 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2927 | return null; |
| 2928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2929 | |
| 2930 | final long identity = Binder.clearCallingIdentity(); |
| 2931 | try { |
| 2932 | return phone.getDeviceSvn(); |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(identity); |
| 2935 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2938 | @Override |
| 2939 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | final long identity = Binder.clearCallingIdentity(); |
| 2941 | try { |
| 2942 | final Phone phone = getPhone(subId); |
| 2943 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2944 | } finally { |
| 2945 | Binder.restoreCallingIdentity(identity); |
| 2946 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | @Override |
| 2950 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | final Phone phone = getPhone(subId); |
| 2954 | return phone == null ? null : phone.getCarrierName(); |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
| 2957 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2958 | } |
| 2959 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2960 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2961 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
| 2964 | final Phone phone = getPhone(subId); |
| 2965 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2966 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2973 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2977 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2978 | } finally { |
| 2979 | Binder.restoreCallingIdentity(identity); |
| 2980 | } |
| 2981 | } |
| 2982 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2983 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2984 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2985 | if (!isSubscriptionMccMnc) { |
| 2986 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2987 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2988 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2989 | if (phone == null) { |
| 2990 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2991 | } |
| 2992 | final long identity = Binder.clearCallingIdentity(); |
| 2993 | try { |
| 2994 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
| 2997 | } |
| 2998 | } |
| 2999 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | // |
| 3001 | // Internal helper methods. |
| 3002 | // |
| 3003 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3004 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3005 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3006 | * |
| 3007 | * @throws SecurityException if the caller does not have the required permission |
| 3008 | */ |
| 3009 | private void enforceModifyPermission() { |
| 3010 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3011 | } |
| 3012 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3013 | /** |
| 3014 | * Make sure the caller is system. |
| 3015 | * |
| 3016 | * @throws SecurityException if the caller is not system. |
| 3017 | */ |
| 3018 | private void enforceSystemCaller() { |
| 3019 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3020 | throw new SecurityException("Caller must be system"); |
| 3021 | } |
| 3022 | } |
| 3023 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3024 | private void enforceActiveEmergencySessionPermission() { |
| 3025 | mApp.enforceCallingOrSelfPermission( |
| 3026 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3027 | } |
| 3028 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3029 | /** |
| 3030 | * Make sure the caller has the CALL_PHONE permission. |
| 3031 | * |
| 3032 | * @throws SecurityException if the caller does not have the required permission |
| 3033 | */ |
| 3034 | private void enforceCallPermission() { |
| 3035 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3036 | } |
| 3037 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3038 | private void enforceSettingsPermission() { |
| 3039 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3042 | private String createTelUrl(String number) { |
| 3043 | if (TextUtils.isEmpty(number)) { |
| 3044 | return null; |
| 3045 | } |
| 3046 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3047 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3050 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3051 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3052 | } |
| 3053 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3054 | private static void logv(String msg) { |
| 3055 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3056 | } |
| 3057 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3058 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3059 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3060 | } |
| 3061 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3062 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3064 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3067 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3068 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3072 | if (phone == null) { |
| 3073 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3074 | } else { |
| 3075 | return phone.getPhoneType(); |
| 3076 | } |
| 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3079 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | /** |
| 3083 | * Returns the CDMA ERI icon index to display |
| 3084 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3085 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3086 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3087 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3088 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3091 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3092 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3093 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3094 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3095 | mApp, subId, callingPackage, callingFeatureId, |
| 3096 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3097 | return -1; |
| 3098 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 | |
| 3100 | final long identity = Binder.clearCallingIdentity(); |
| 3101 | try { |
| 3102 | final Phone phone = getPhone(subId); |
| 3103 | if (phone != null) { |
| 3104 | return phone.getCdmaEriIconIndex(); |
| 3105 | } else { |
| 3106 | return -1; |
| 3107 | } |
| 3108 | } finally { |
| 3109 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3110 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | /** |
| 3114 | * Returns the CDMA ERI icon mode, |
| 3115 | * 0 - ON |
| 3116 | * 1 - FLASHING |
| 3117 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3118 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3119 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3120 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3121 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3124 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3125 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3126 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3128 | mApp, subId, callingPackage, callingFeatureId, |
| 3129 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3130 | return -1; |
| 3131 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 | |
| 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | final Phone phone = getPhone(subId); |
| 3136 | if (phone != null) { |
| 3137 | return phone.getCdmaEriIconMode(); |
| 3138 | } else { |
| 3139 | return -1; |
| 3140 | } |
| 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3143 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * Returns the CDMA ERI text, |
| 3148 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3149 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3150 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3151 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3152 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3156 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3157 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3159 | mApp, subId, callingPackage, callingFeatureId, |
| 3160 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3161 | return null; |
| 3162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3163 | |
| 3164 | final long identity = Binder.clearCallingIdentity(); |
| 3165 | try { |
| 3166 | final Phone phone = getPhone(subId); |
| 3167 | if (phone != null) { |
| 3168 | return phone.getCdmaEriText(); |
| 3169 | } else { |
| 3170 | return null; |
| 3171 | } |
| 3172 | } finally { |
| 3173 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3174 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3178 | * Returns the CDMA MDN. |
| 3179 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3180 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3181 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3182 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3183 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | |
| 3185 | final long identity = Binder.clearCallingIdentity(); |
| 3186 | try { |
| 3187 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3188 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | return phone.getLine1Number(); |
| 3190 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | return null; |
| 3193 | } |
| 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | /** |
| 3200 | * Returns the CDMA MIN. |
| 3201 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3202 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3203 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3205 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | |
| 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
| 3209 | final Phone phone = getPhone(subId); |
| 3210 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3211 | return phone.getCdmaMin(); |
| 3212 | } else { |
| 3213 | return null; |
| 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3220 | @Override |
| 3221 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3222 | INumberVerificationCallback callback, String callingPackage) { |
| 3223 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3224 | != PERMISSION_GRANTED) { |
| 3225 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3226 | } |
| 3227 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3228 | |
| 3229 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3230 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3231 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3232 | } |
| 3233 | |
| 3234 | if (range == null) { |
| 3235 | throw new NullPointerException("Range must be non-null"); |
| 3236 | } |
| 3237 | |
| 3238 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3239 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3240 | |
| 3241 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3242 | } |
| 3243 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3244 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3245 | * Returns true if CDMA provisioning needs to run. |
| 3246 | */ |
| 3247 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | final long identity = Binder.clearCallingIdentity(); |
| 3249 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3250 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | } finally { |
| 3252 | Binder.restoreCallingIdentity(identity); |
| 3253 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3254 | } |
| 3255 | |
| 3256 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3257 | * Sets the voice mail number of a given subId. |
| 3258 | */ |
| 3259 | @Override |
| 3260 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3261 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3262 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3263 | |
| 3264 | final long identity = Binder.clearCallingIdentity(); |
| 3265 | try { |
| 3266 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3267 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3268 | return success; |
| 3269 | } finally { |
| 3270 | Binder.restoreCallingIdentity(identity); |
| 3271 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3272 | } |
| 3273 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3274 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3275 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3277 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3278 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3279 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3280 | throw new SecurityException("caller must be system dialer"); |
| 3281 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | |
| 3283 | final long identity = Binder.clearCallingIdentity(); |
| 3284 | try { |
| 3285 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3286 | if (phoneAccountHandle == null) { |
| 3287 | return null; |
| 3288 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3289 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3292 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3296 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3297 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3298 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3300 | mApp, subId, callingPackage, callingFeatureId, |
| 3301 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3302 | return null; |
| 3303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3305 | final long identity = Binder.clearCallingIdentity(); |
| 3306 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3307 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3308 | } finally { |
| 3309 | Binder.restoreCallingIdentity(identity); |
| 3310 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3314 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3315 | VisualVoicemailSmsFilterSettings settings) { |
| 3316 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 | |
| 3318 | final long identity = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
| 3324 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3328 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3329 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | |
| 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
| 3333 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3334 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3338 | } |
| 3339 | |
| 3340 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3341 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3342 | String callingPackage, int subId) { |
| 3343 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3344 | |
| 3345 | final long identity = Binder.clearCallingIdentity(); |
| 3346 | try { |
| 3347 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3348 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | } finally { |
| 3350 | Binder.restoreCallingIdentity(identity); |
| 3351 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3355 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3356 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | |
| 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3361 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3362 | } finally { |
| 3363 | Binder.restoreCallingIdentity(identity); |
| 3364 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3365 | } |
| 3366 | |
| 3367 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3368 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3369 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3370 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3371 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3372 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3373 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3374 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3375 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3376 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3377 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3378 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3379 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3380 | * Sets the voice activation state of a given subId. |
| 3381 | */ |
| 3382 | @Override |
| 3383 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3385 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | |
| 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | final Phone phone = getPhone(subId); |
| 3390 | if (phone != null) { |
| 3391 | phone.setVoiceActivationState(activationState); |
| 3392 | } else { |
| 3393 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3394 | } |
| 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3397 | } |
| 3398 | } |
| 3399 | |
| 3400 | /** |
| 3401 | * Sets the data activation state of a given subId. |
| 3402 | */ |
| 3403 | @Override |
| 3404 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3406 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | final Phone phone = getPhone(subId); |
| 3411 | if (phone != null) { |
| 3412 | phone.setDataActivationState(activationState); |
| 3413 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3414 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3415 | } |
| 3416 | } finally { |
| 3417 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | /** |
| 3422 | * Returns the voice activation state of a given subId. |
| 3423 | */ |
| 3424 | @Override |
| 3425 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3427 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3428 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | if (phone != null) { |
| 3432 | return phone.getVoiceActivationState(); |
| 3433 | } else { |
| 3434 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3435 | } |
| 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | /** |
| 3442 | * Returns the data activation state of a given subId. |
| 3443 | */ |
| 3444 | @Override |
| 3445 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3446 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3448 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | if (phone != null) { |
| 3452 | return phone.getDataActivationState(); |
| 3453 | } else { |
| 3454 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3455 | } |
| 3456 | } finally { |
| 3457 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3462 | * Returns the unread count of voicemails for a subId |
| 3463 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3464 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3465 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3466 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3468 | mApp, subId, callingPackage, callingFeatureId, |
| 3469 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3470 | return 0; |
| 3471 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3472 | final long identity = Binder.clearCallingIdentity(); |
| 3473 | try { |
| 3474 | final Phone phone = getPhone(subId); |
| 3475 | if (phone != null) { |
| 3476 | return phone.getVoiceMessageCount(); |
| 3477 | } else { |
| 3478 | return 0; |
| 3479 | } |
| 3480 | } finally { |
| 3481 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3482 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3486 | * returns true, if the device is in a state where both voice and data |
| 3487 | * are supported simultaneously. This can change based on location or network condition. |
| 3488 | */ |
| 3489 | @Override |
| 3490 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3491 | final long identity = Binder.clearCallingIdentity(); |
| 3492 | try { |
| 3493 | final Phone phone = getPhone(subId); |
| 3494 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3495 | } finally { |
| 3496 | Binder.restoreCallingIdentity(identity); |
| 3497 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3501 | * Send the dialer code if called from the current default dialer or the caller has |
| 3502 | * carrier privilege. |
| 3503 | * @param inputCode The dialer code to send |
| 3504 | */ |
| 3505 | @Override |
| 3506 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3507 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3508 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3509 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3510 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3511 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3512 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3513 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3514 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 | |
| 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3518 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3519 | } finally { |
| 3520 | Binder.restoreCallingIdentity(identity); |
| 3521 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3522 | } |
| 3523 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3524 | @Override |
| 3525 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3526 | TelephonyPermissions |
| 3527 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3528 | mApp, subId, "getNetworkSelectionMode"); |
| 3529 | final long identity = Binder.clearCallingIdentity(); |
| 3530 | try { |
| 3531 | if (!isActiveSubscription(subId)) { |
| 3532 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3533 | } |
| 3534 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3535 | } finally { |
| 3536 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3537 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3540 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3541 | public boolean isInEmergencySmsMode() { |
| 3542 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3543 | final long identity = Binder.clearCallingIdentity(); |
| 3544 | try { |
| 3545 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3546 | if (phone.isInEmergencySmsMode()) { |
| 3547 | return true; |
| 3548 | } |
| 3549 | } |
| 3550 | } finally { |
| 3551 | Binder.restoreCallingIdentity(identity); |
| 3552 | } |
| 3553 | return false; |
| 3554 | } |
| 3555 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3556 | /** |
| 3557 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3558 | * @param subId The subscription to use to check the configuration. |
| 3559 | * @param c The callback that will be used to send the result. |
| 3560 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3561 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3562 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3563 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3564 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3565 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3566 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3567 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3568 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3569 | "IMS not available on device."); |
| 3570 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | final long token = Binder.clearCallingIdentity(); |
| 3572 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3574 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3576 | } catch (ImsException e) { |
| 3577 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(token); |
| 3580 | } |
| 3581 | } |
| 3582 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3583 | /** |
| 3584 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3585 | * @param subId The subscription to use to check the configuration. |
| 3586 | * @param c The callback that will be used to send the result. |
| 3587 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3589 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3590 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3591 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3592 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3593 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3594 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3595 | final long token = Binder.clearCallingIdentity(); |
| 3596 | try { |
| 3597 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3598 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3599 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3600 | } catch (ImsException e) { |
| 3601 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3602 | + "is inactive, ignoring unregister."); |
| 3603 | // If the subscription is no longer active, just return, since the callback |
| 3604 | // will already have been removed internally. |
| 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(token); |
| 3607 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | } |
| 3609 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3610 | /** |
| 3611 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3612 | */ |
| 3613 | @Override |
| 3614 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3615 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3616 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3617 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3618 | "IMS not available on device."); |
| 3619 | } |
| 3620 | final long token = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | Phone phone = getPhone(subId); |
| 3623 | if (phone == null) { |
| 3624 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3625 | + subId + "'"); |
| 3626 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3627 | } |
| 3628 | phone.getImsRegistrationState(regState -> { |
| 3629 | try { |
| 3630 | consumer.accept((regState == null) |
| 3631 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3632 | } catch (RemoteException e) { |
| 3633 | // Ignore if the remote process is no longer available to call back. |
| 3634 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3635 | } |
| 3636 | }); |
| 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(token); |
| 3639 | } |
| 3640 | } |
| 3641 | |
| 3642 | /** |
| 3643 | * Get the transport type for the IMS service registration state. |
| 3644 | */ |
| 3645 | @Override |
| 3646 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3647 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3648 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3649 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3650 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3651 | "IMS not available on device."); |
| 3652 | } |
| 3653 | final long token = Binder.clearCallingIdentity(); |
| 3654 | try { |
| 3655 | Phone phone = getPhone(subId); |
| 3656 | if (phone == null) { |
| 3657 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3658 | + subId + "'"); |
| 3659 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3660 | } |
| 3661 | phone.getImsRegistrationTech(regTech -> { |
| 3662 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3663 | int regTechConverted = (regTech == null) |
| 3664 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3665 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3666 | regTechConverted); |
| 3667 | try { |
| 3668 | consumer.accept(regTechConverted); |
| 3669 | } catch (RemoteException e) { |
| 3670 | // Ignore if the remote process is no longer available to call back. |
| 3671 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3672 | } |
| 3673 | }); |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(token); |
| 3676 | } |
| 3677 | } |
| 3678 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3679 | /** |
| 3680 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3681 | * @param subId The subscription to use to check the configuration. |
| 3682 | * @param c The callback that will be used to send the result. |
| 3683 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3684 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3685 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3686 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3687 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3688 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3689 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3691 | "IMS not available on device."); |
| 3692 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3693 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3694 | final long token = Binder.clearCallingIdentity(); |
| 3695 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3696 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3697 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3698 | } catch (ImsException e) { |
| 3699 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(token); |
| 3702 | } |
| 3703 | } |
| 3704 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3705 | /** |
| 3706 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3707 | * @param subId The subscription to use to check the configuration. |
| 3708 | * @param c The callback that will be used to send the result. |
| 3709 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3710 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3711 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3712 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3713 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3714 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3715 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3716 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3717 | |
| 3718 | final long token = Binder.clearCallingIdentity(); |
| 3719 | try { |
| 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3721 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3722 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3723 | } catch (ImsException e) { |
| 3724 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3725 | + "is inactive, ignoring unregister."); |
| 3726 | // If the subscription is no longer active, just return, since the callback |
| 3727 | // will already have been removed internally. |
| 3728 | } finally { |
| 3729 | Binder.restoreCallingIdentity(token); |
| 3730 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3734 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3735 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3737 | final long token = Binder.clearCallingIdentity(); |
| 3738 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3743 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3744 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3745 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3746 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(token); |
| 3749 | } |
| 3750 | } |
| 3751 | |
| 3752 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3753 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3754 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3755 | final long token = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | Phone phone = getPhone(subId); |
| 3758 | if (phone == null) return false; |
| 3759 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3760 | } catch (com.android.ims.ImsException e) { |
| 3761 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3762 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | } finally { |
| 3764 | Binder.restoreCallingIdentity(token); |
| 3765 | } |
| 3766 | } |
| 3767 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3768 | /** |
| 3769 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3770 | * subscription. |
| 3771 | * @param subId The subscription to use to check the configuration. |
| 3772 | * @param callback The callback that will be used to send the result. |
| 3773 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3774 | * @param transportType The transport type of the MmTelFeature capability. |
| 3775 | */ |
| 3776 | @Override |
| 3777 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3778 | int transportType) { |
| 3779 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3780 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3781 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3782 | "IMS not available on device."); |
| 3783 | } |
| 3784 | final long token = Binder.clearCallingIdentity(); |
| 3785 | try { |
| 3786 | int slotId = getSlotIndex(subId); |
| 3787 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3788 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3789 | + subId + "'"); |
| 3790 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3791 | } |
| 3792 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3793 | transportType, aBoolean -> { |
| 3794 | try { |
| 3795 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3796 | } catch (RemoteException e) { |
| 3797 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3798 | + "running. Ignore"); |
| 3799 | } |
| 3800 | }); |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(token); |
| 3803 | } |
| 3804 | } |
| 3805 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3806 | /** |
| 3807 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3808 | * @param subId The subscription to use to check the configuration. |
| 3809 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3810 | @Override |
| 3811 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3812 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3813 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3814 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3815 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3816 | final long token = Binder.clearCallingIdentity(); |
| 3817 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3818 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3820 | } catch (ImsException e) { |
| 3821 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(token); |
| 3824 | } |
| 3825 | } |
| 3826 | |
| 3827 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3828 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3830 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | final long identity = Binder.clearCallingIdentity(); |
| 3832 | try { |
| 3833 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3834 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3835 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3836 | } catch (ImsException e) { |
| 3837 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | } finally { |
| 3839 | Binder.restoreCallingIdentity(identity); |
| 3840 | } |
| 3841 | } |
| 3842 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3843 | /** |
| 3844 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3845 | * @param subId The subscription to use to check the configuration. |
| 3846 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3847 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3848 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3849 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3850 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3851 | final long identity = Binder.clearCallingIdentity(); |
| 3852 | try { |
| 3853 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3854 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3855 | } catch (ImsException e) { |
| 3856 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
| 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3863 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3865 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3866 | final long identity = Binder.clearCallingIdentity(); |
| 3867 | try { |
| 3868 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3869 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3870 | } catch (ImsException e) { |
| 3871 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(identity); |
| 3874 | } |
| 3875 | } |
| 3876 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3877 | /** |
| 3878 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3879 | * @param subId The subscription to use to check the configuration. |
| 3880 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | @Override |
| 3882 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3883 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3884 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | final long identity = Binder.clearCallingIdentity(); |
| 3886 | try { |
| 3887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3888 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3889 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3890 | } catch (ImsException e) { |
| 3891 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(identity); |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3898 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3900 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3904 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3905 | } catch (ImsException e) { |
| 3906 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | } finally { |
| 3908 | Binder.restoreCallingIdentity(identity); |
| 3909 | } |
| 3910 | } |
| 3911 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3912 | /** |
| 3913 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3914 | * @param subId The subscription to use to check the configuration. |
| 3915 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3916 | @Override |
| 3917 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3918 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3919 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
| 3922 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3923 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3924 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3925 | } catch (ImsException e) { |
| 3926 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3927 | } finally { |
| 3928 | Binder.restoreCallingIdentity(identity); |
| 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3933 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3934 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3935 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
| 3938 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3939 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3940 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3941 | } catch (ImsException e) { |
| 3942 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3943 | } finally { |
| 3944 | Binder.restoreCallingIdentity(identity); |
| 3945 | } |
| 3946 | } |
| 3947 | |
| 3948 | @Override |
| 3949 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3950 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3951 | "setVoWiFiNonPersistent"); |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3956 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3957 | } catch (ImsException e) { |
| 3958 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | } finally { |
| 3960 | Binder.restoreCallingIdentity(identity); |
| 3961 | } |
| 3962 | } |
| 3963 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3964 | /** |
| 3965 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3966 | * @param subId The subscription to use to check the configuration. |
| 3967 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | @Override |
| 3969 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3970 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3971 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | final long identity = Binder.clearCallingIdentity(); |
| 3973 | try { |
| 3974 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3975 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3977 | } catch (ImsException e) { |
| 3978 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | } finally { |
| 3980 | Binder.restoreCallingIdentity(identity); |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | @Override |
| 3985 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3987 | "setVoWiFiModeSetting"); |
| 3988 | final long identity = Binder.clearCallingIdentity(); |
| 3989 | try { |
| 3990 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3991 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3993 | } catch (ImsException e) { |
| 3994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | @Override |
| 4001 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4002 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4006 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4008 | } catch (ImsException e) { |
| 4009 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
| 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | @Override |
| 4016 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4018 | "setVoWiFiRoamingModeSetting"); |
| 4019 | final long identity = Binder.clearCallingIdentity(); |
| 4020 | try { |
| 4021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4022 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4024 | } catch (ImsException e) { |
| 4025 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(identity); |
| 4028 | } |
| 4029 | } |
| 4030 | |
| 4031 | @Override |
| 4032 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4034 | "setRttCapabilityEnabled"); |
| 4035 | final long identity = Binder.clearCallingIdentity(); |
| 4036 | try { |
| 4037 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4039 | } catch (ImsException e) { |
| 4040 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | } finally { |
| 4042 | Binder.restoreCallingIdentity(identity); |
| 4043 | } |
| 4044 | } |
| 4045 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4046 | /** |
| 4047 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4048 | * @param subId The subscription to use to check the configuration. |
| 4049 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | @Override |
| 4051 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4052 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4053 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4054 | final long identity = Binder.clearCallingIdentity(); |
| 4055 | try { |
| 4056 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4057 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4059 | } catch (ImsException e) { |
| 4060 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
| 4064 | } |
| 4065 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4066 | @Override |
| 4067 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4068 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4069 | final long identity = Binder.clearCallingIdentity(); |
| 4070 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4071 | if (!isImsAvailableOnDevice()) { |
| 4072 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4073 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4074 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4075 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4076 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4077 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4078 | } catch (ImsException e) { |
| 4079 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4080 | } finally { |
| 4081 | Binder.restoreCallingIdentity(identity); |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | @Override |
| 4086 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4087 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4088 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4089 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4090 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4091 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4092 | try { |
| 4093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4094 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4095 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4096 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4097 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4098 | + "is inactive, ignoring unregister."); |
| 4099 | // If the subscription is no longer active, just return, since the callback will already |
| 4100 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
| 4104 | } |
| 4105 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4106 | |
| 4107 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4109 | message); |
| 4110 | } |
| 4111 | |
| 4112 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4113 | boolean isMmtelCapability) { |
| 4114 | Phone phone = getPhone(subId); |
| 4115 | if (phone == null) { |
| 4116 | loge("phone instance null for subid " + subId); |
| 4117 | return false; |
| 4118 | } |
| 4119 | if (isMmtelCapability) { |
| 4120 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4121 | return false; |
| 4122 | } |
| 4123 | } else { |
| 4124 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4125 | return false; |
| 4126 | } |
| 4127 | } |
| 4128 | return true; |
| 4129 | } |
| 4130 | |
| 4131 | @Override |
| 4132 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4133 | boolean isProvisioned) { |
| 4134 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4135 | |
| 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
| 4138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4139 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4140 | return; |
| 4141 | } |
| 4142 | |
| 4143 | // this capability requires provisioning, route to the correct API. |
| 4144 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4145 | switch (capability) { |
| 4146 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4147 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4148 | ims.setEabProvisioned(isProvisioned); |
| 4149 | break; |
| 4150 | default: { |
| 4151 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4152 | + "rcs capability '" + capability + "', which does not require " |
| 4153 | + "provisioning."); |
| 4154 | } |
| 4155 | } |
| 4156 | } finally { |
| 4157 | Binder.restoreCallingIdentity(identity); |
| 4158 | } |
| 4159 | |
| 4160 | } |
| 4161 | |
| 4162 | |
| 4163 | @Override |
| 4164 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4165 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
| 4168 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4169 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4170 | return true; |
| 4171 | } |
| 4172 | |
| 4173 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4174 | switch (capability) { |
| 4175 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4176 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4177 | return ims.isEabProvisionedOnDevice(); |
| 4178 | |
| 4179 | default: { |
| 4180 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4181 | + "capability '" + capability + "', which does not require " |
| 4182 | + "provisioning."); |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | } finally { |
| 4187 | Binder.restoreCallingIdentity(identity); |
| 4188 | } |
| 4189 | } |
| 4190 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4191 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4192 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4193 | boolean isProvisioned) { |
| 4194 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4195 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4196 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4197 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4198 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4199 | final long identity = Binder.clearCallingIdentity(); |
| 4200 | try { |
| 4201 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4202 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 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 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4210 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4211 | ims.setVolteProvisioned(isProvisioned); |
| 4212 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4213 | ims.setWfcProvisioned(isProvisioned); |
| 4214 | } |
| 4215 | break; |
| 4216 | } |
| 4217 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4218 | // There is currently no difference in VT provisioning type. |
| 4219 | ims.setVtProvisioned(isProvisioned); |
| 4220 | break; |
| 4221 | } |
| 4222 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4223 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4224 | // change the capability of the feature instead if needed. |
| 4225 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4226 | == isProvisioned) { |
| 4227 | // No change in provisioning. |
| 4228 | return; |
| 4229 | } |
| 4230 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4231 | try { |
| 4232 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4233 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4234 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4235 | + ", Exception" + e.getMessage()); |
| 4236 | } |
| 4237 | break; |
| 4238 | } |
| 4239 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4240 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4241 | + "MmTel capability '" + capability + "', which does not require " |
| 4242 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | |
| 4246 | } finally { |
| 4247 | Binder.restoreCallingIdentity(identity); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | @Override |
| 4252 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4253 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4254 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4255 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4256 | } |
| 4257 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4258 | final long identity = Binder.clearCallingIdentity(); |
| 4259 | try { |
| 4260 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4261 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4262 | return true; |
| 4263 | } |
| 4264 | |
| 4265 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4266 | switch (capability) { |
| 4267 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4268 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4269 | return ims.isVolteProvisionedOnDevice(); |
| 4270 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4271 | return ims.isWfcProvisionedOnDevice(); |
| 4272 | } |
| 4273 | // This should never happen, since we are checking tech above to make sure it |
| 4274 | // is either LTE or IWLAN. |
| 4275 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4276 | + "capability."); |
| 4277 | } |
| 4278 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4279 | // There is currently no difference in VT provisioning type. |
| 4280 | return ims.isVtProvisionedOnDevice(); |
| 4281 | } |
| 4282 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4283 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4284 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4285 | } |
| 4286 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4287 | throw new IllegalArgumentException( |
| 4288 | "Tried to get provisioning for MmTel capability '" + capability |
| 4289 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | } finally { |
| 4294 | Binder.restoreCallingIdentity(identity); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | @Override |
| 4299 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4300 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4301 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4302 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4303 | } |
| 4304 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4305 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4306 | return (provisionedBits & capability) > 0; |
| 4307 | } |
| 4308 | |
| 4309 | @Override |
| 4310 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4311 | boolean isProvisioned) { |
| 4312 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4313 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4314 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4315 | } |
| 4316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4317 | "setProvisioningStatusForCapability"); |
| 4318 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4319 | // If the current provisioning status for capability already matches isProvisioned, |
| 4320 | // do nothing. |
| 4321 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4322 | return; |
| 4323 | } |
| 4324 | if (isProvisioned) { |
| 4325 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4326 | } else { |
| 4327 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4328 | } |
| 4329 | } |
| 4330 | |
| 4331 | /** |
| 4332 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4333 | * technology. The bitfield should mirror the bitfield defined by |
| 4334 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4335 | */ |
| 4336 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4337 | String key = getMmTelProvisioningKey(subId, tech); |
| 4338 | // Default is no capabilities are provisioned. |
| 4339 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4340 | } |
| 4341 | |
| 4342 | /** |
| 4343 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4344 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4345 | * technology specified. |
| 4346 | * |
| 4347 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4348 | */ |
| 4349 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4350 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4351 | String key = getMmTelProvisioningKey(subId, tech); |
| 4352 | editor.putInt(key, newField); |
| 4353 | editor.commit(); |
| 4354 | } |
| 4355 | |
| 4356 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4357 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4358 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4359 | } |
| 4360 | |
| 4361 | /** |
| 4362 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4363 | * carrier associated with the subscription id. |
| 4364 | */ |
| 4365 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4366 | int capability) { |
| 4367 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4368 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4369 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4370 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4371 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4372 | false); |
| 4373 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4374 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4375 | |
| 4376 | // First check to make sure that the capability requires provisioning. |
| 4377 | switch (capability) { |
| 4378 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4379 | // intentional fallthrough |
| 4380 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4381 | if (requireVoiceVtProvisioning) { |
| 4382 | // Voice and Video requires provisioning |
| 4383 | return true; |
| 4384 | } |
| 4385 | break; |
| 4386 | } |
| 4387 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4388 | if (requireUtProvisioning) { |
| 4389 | // UT requires provisioning |
| 4390 | return true; |
| 4391 | } |
| 4392 | break; |
| 4393 | } |
| 4394 | } |
| 4395 | return false; |
| 4396 | } |
| 4397 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4398 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4399 | int capability) { |
| 4400 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4401 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4402 | |
| 4403 | boolean requireRcsProvisioning = c.getBoolean( |
| 4404 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4405 | |
| 4406 | // First check to make sure that the capability requires provisioning. |
| 4407 | switch (capability) { |
| 4408 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4409 | // intentional fallthrough |
| 4410 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4411 | if (requireRcsProvisioning) { |
| 4412 | // OPTION or PRESENCE requires provisioning |
| 4413 | return true; |
| 4414 | } |
| 4415 | break; |
| 4416 | } |
| 4417 | } |
| 4418 | return false; |
| 4419 | } |
| 4420 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4421 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4422 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4423 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4424 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4425 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4426 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4427 | final long identity = Binder.clearCallingIdentity(); |
| 4428 | try { |
| 4429 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4430 | int slotId = getSlotIndex(subId); |
| 4431 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4432 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4433 | + subId + "' for key:" + key); |
| 4434 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4435 | } |
| 4436 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4437 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4438 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4439 | + subId + "' for key:" + key); |
| 4440 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4441 | } finally { |
| 4442 | Binder.restoreCallingIdentity(identity); |
| 4443 | } |
| 4444 | } |
| 4445 | |
| 4446 | @Override |
| 4447 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4448 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4449 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4450 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4451 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4452 | final long identity = Binder.clearCallingIdentity(); |
| 4453 | try { |
| 4454 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4455 | int slotId = getSlotIndex(subId); |
| 4456 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4457 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4458 | + subId + "' for key:" + key); |
| 4459 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4460 | } |
| 4461 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4462 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4463 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4464 | + subId + "' for key:" + key); |
| 4465 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | @Override |
| 4472 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4473 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4474 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4475 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4477 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
| 4480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4481 | int slotId = getSlotIndex(subId); |
| 4482 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4483 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4484 | + subId + "' for key:" + key); |
| 4485 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4486 | } |
| 4487 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4488 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4489 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4490 | + "' for key:" + key); |
| 4491 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(identity); |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | @Override |
| 4498 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4499 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4500 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4501 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4503 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4507 | int slotId = getSlotIndex(subId); |
| 4508 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4509 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4510 | + subId + "' for key:" + key); |
| 4511 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4512 | } |
| 4513 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4514 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4515 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4516 | + "' for key:" + key); |
| 4517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
| 4521 | } |
| 4522 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4523 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4524 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4525 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4526 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4527 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | } |
| 4529 | return slotId; |
| 4530 | } |
| 4531 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4532 | private int getSlotIndex(int subId) { |
| 4533 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4534 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4535 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4536 | } |
| 4537 | return slotId; |
| 4538 | } |
| 4539 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4540 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4541 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4542 | */ |
| 4543 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4544 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4545 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4546 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4547 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4548 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4549 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4550 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4551 | mApp, subId, callingPackage, callingFeatureId, |
| 4552 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4553 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4554 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | final long identity = Binder.clearCallingIdentity(); |
| 4557 | try { |
| 4558 | final Phone phone = getPhone(subId); |
| 4559 | if (phone != null) { |
| 4560 | return phone.getServiceState().getDataNetworkType(); |
| 4561 | } else { |
| 4562 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4563 | } |
| 4564 | } finally { |
| 4565 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4566 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | /** |
| 4570 | * Returns the data network type |
| 4571 | */ |
| 4572 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4573 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4574 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4575 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /** |
| 4579 | * Returns the data network type for a subId |
| 4580 | */ |
| 4581 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4582 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4583 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4584 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4585 | mApp, subId, callingPackage, callingFeatureId, |
| 4586 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4587 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4588 | } |
| 4589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | final long identity = Binder.clearCallingIdentity(); |
| 4591 | try { |
| 4592 | final Phone phone = getPhone(subId); |
| 4593 | if (phone != null) { |
| 4594 | return phone.getServiceState().getDataNetworkType(); |
| 4595 | } else { |
| 4596 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4597 | } |
| 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4600 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4604 | * Returns the Voice network type for a subId |
| 4605 | */ |
| 4606 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4607 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4608 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4609 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4610 | mApp, subId, callingPackage, callingFeatureId, |
| 4611 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4612 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4613 | } |
| 4614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
| 4617 | final Phone phone = getPhone(subId); |
| 4618 | if (phone != null) { |
| 4619 | return phone.getServiceState().getVoiceNetworkType(); |
| 4620 | } else { |
| 4621 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4622 | } |
| 4623 | } finally { |
| 4624 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4625 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | /** |
| 4629 | * @return true if a ICC card is present |
| 4630 | */ |
| 4631 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4632 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4633 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4634 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4638 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4639 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4640 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4641 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4642 | final long identity = Binder.clearCallingIdentity(); |
| 4643 | try { |
| 4644 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4645 | if (phone != null) { |
| 4646 | return phone.getIccCard().hasIccCard(); |
| 4647 | } else { |
| 4648 | return false; |
| 4649 | } |
| 4650 | } finally { |
| 4651 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | /** |
| 4656 | * Return if the current radio is LTE on CDMA. This |
| 4657 | * is a tri-state return value as for a period of time |
| 4658 | * the mode may be unknown. |
| 4659 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4660 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4661 | * @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] | 4662 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4663 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4664 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4665 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4666 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4667 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4670 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4671 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4672 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4673 | try { |
| 4674 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4675 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4676 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4677 | } |
| 4678 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4679 | final long identity = Binder.clearCallingIdentity(); |
| 4680 | try { |
| 4681 | final Phone phone = getPhone(subId); |
| 4682 | if (phone == null) { |
| 4683 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4684 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4685 | return TelephonyProperties.lte_on_cdma_device() |
| 4686 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4687 | } |
| 4688 | } finally { |
| 4689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4690 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4693 | /** |
| 4694 | * {@hide} |
| 4695 | * Returns Default subId, 0 in the case of single standby. |
| 4696 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4697 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4698 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4699 | } |
| 4700 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4701 | private int getSlotForDefaultSubscription() { |
| 4702 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4703 | } |
| 4704 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4705 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4706 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4707 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4708 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4709 | private boolean isActiveSubscription(int subId) { |
| 4710 | return mSubscriptionController.isActiveSubId(subId); |
| 4711 | } |
| 4712 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4713 | /** |
| 4714 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4715 | */ |
| 4716 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4719 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4720 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4721 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(identity); |
| 4724 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4725 | } |
| 4726 | |
| 4727 | /** |
| 4728 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4729 | */ |
| 4730 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
| 4733 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4734 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4739 | } |
| 4740 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4741 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4742 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4743 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4744 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4745 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4746 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4747 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4748 | if (phoneId == -1) { |
| 4749 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4750 | + " does not correspond to an active phone"); |
| 4751 | } |
| 4752 | return PhoneFactory.getPhone(phoneId); |
| 4753 | } |
| 4754 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4755 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4756 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4757 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4759 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4761 | if (DBG) { |
| 4762 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4763 | } |
| 4764 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4765 | p2); |
| 4766 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4767 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4768 | |
| 4769 | @Override |
| 4770 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4771 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4772 | enforceModifyPermission(); |
| 4773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4774 | if (DBG) { |
| 4775 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4776 | } |
| 4777 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4778 | callingPackage, aid, p2); |
| 4779 | } |
| 4780 | |
| 4781 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4782 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | final long identity = Binder.clearCallingIdentity(); |
| 4784 | try { |
| 4785 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4786 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4787 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4788 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4789 | if (bestComponent == null |
| 4790 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4791 | loge("The calling package is not allowed to access ISD-R."); |
| 4792 | throw new SecurityException( |
| 4793 | "The calling package is not allowed to access ISD-R."); |
| 4794 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4795 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4797 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4798 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4799 | null /* workSource */); |
| 4800 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4801 | return response; |
| 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(identity); |
| 4804 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4808 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4810 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4811 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4812 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4813 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4814 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4815 | @Override |
| 4816 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4817 | enforceModifyPermission(); |
| 4818 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4819 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4820 | channel); |
| 4821 | } |
| 4822 | |
| 4823 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | final long identity = Binder.clearCallingIdentity(); |
| 4825 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4826 | if (channel < 0) { |
| 4827 | return false; |
| 4828 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4829 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4830 | null /* workSource */); |
| 4831 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4832 | return success; |
| 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4835 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4836 | } |
| 4837 | |
| 4838 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4839 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4840 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4842 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4843 | if (DBG) { |
| 4844 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4845 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4846 | + p3 + " data=" + data); |
| 4847 | } |
| 4848 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4849 | command, p1, p2, p3, data); |
| 4850 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4851 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4852 | @Override |
| 4853 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4854 | int command, int p1, int p2, int p3, String data) { |
| 4855 | enforceModifyPermission(); |
| 4856 | if (DBG) { |
| 4857 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4858 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4859 | + p3 + " data=" + data); |
| 4860 | } |
| 4861 | return iccTransmitApduLogicalChannelWithPermission( |
| 4862 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4863 | data); |
| 4864 | } |
| 4865 | |
| 4866 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4867 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | final long identity = Binder.clearCallingIdentity(); |
| 4869 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4870 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | return ""; |
| 4872 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4873 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4875 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4876 | null /* workSource */); |
| 4877 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4878 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | // Append the returned status code to the end of the response payload. |
| 4880 | String s = Integer.toHexString( |
| 4881 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4882 | if (response.payload != null) { |
| 4883 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4884 | } |
| 4885 | return s; |
| 4886 | } finally { |
| 4887 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4888 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4889 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4890 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4891 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4892 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4893 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4895 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4896 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4897 | if (DBG) { |
| 4898 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4899 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4900 | } |
| 4901 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4902 | cla, command, p1, p2, p3, data); |
| 4903 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4904 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4905 | @Override |
| 4906 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4907 | int command, int p1, int p2, int p3, String data) { |
| 4908 | enforceModifyPermission(); |
| 4909 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4910 | if (DBG) { |
| 4911 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4912 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4913 | + " data=" + data); |
| 4914 | } |
| 4915 | |
| 4916 | return iccTransmitApduBasicChannelWithPermission( |
| 4917 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4918 | p2, p3, data); |
| 4919 | } |
| 4920 | |
| 4921 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4922 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4923 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
| 4926 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4927 | && TextUtils.equals(ISDR_AID, data)) { |
| 4928 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4929 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4930 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4931 | if (bestComponent == null |
| 4932 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4933 | loge("The calling package is not allowed to select ISD-R."); |
| 4934 | throw new SecurityException( |
| 4935 | "The calling package is not allowed to select ISD-R."); |
| 4936 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4937 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4938 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4940 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4941 | null /* workSource */); |
| 4942 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4943 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | // Append the returned status code to the end of the response payload. |
| 4945 | String s = Integer.toHexString( |
| 4946 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4947 | if (response.payload != null) { |
| 4948 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4949 | } |
| 4950 | return s; |
| 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4953 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4957 | 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] | 4958 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4960 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4961 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
| 4964 | if (DBG) { |
| 4965 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4966 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4967 | } |
| 4968 | |
| 4969 | IccIoResult response = |
| 4970 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4971 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4972 | subId); |
| 4973 | |
| 4974 | if (DBG) { |
| 4975 | log("Exchange SIM_IO [R]" + response); |
| 4976 | } |
| 4977 | |
| 4978 | byte[] result = null; |
| 4979 | int length = 2; |
| 4980 | if (response.payload != null) { |
| 4981 | length = 2 + response.payload.length; |
| 4982 | result = new byte[length]; |
| 4983 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4984 | } else { |
| 4985 | result = new byte[length]; |
| 4986 | } |
| 4987 | |
| 4988 | result[length - 1] = (byte) response.sw2; |
| 4989 | result[length - 2] = (byte) response.sw1; |
| 4990 | return result; |
| 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4993 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4996 | /** |
| 4997 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4998 | * on a particular subscription |
| 4999 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5000 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5001 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5003 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5004 | return null; |
| 5005 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | |
| 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | try { |
| 5009 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5010 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5011 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5012 | return null; |
| 5013 | } |
| 5014 | Object response = sendRequest( |
| 5015 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5016 | if (response instanceof String[]) { |
| 5017 | return (String[]) response; |
| 5018 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5019 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5021 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5024 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5025 | } |
| 5026 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5027 | /** |
| 5028 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5029 | * subscription. |
| 5030 | * |
| 5031 | * @param subId the id of the subscription. |
| 5032 | * @param appType the uicc app type, must be USIM or SIM. |
| 5033 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5034 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5035 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5036 | * @return number of fplmns that is successfully written to the SIM. |
| 5037 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5038 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5039 | String callingFeatureId) { |
| 5040 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5041 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5042 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5043 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5044 | } |
| 5045 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5046 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5047 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5048 | } |
| 5049 | if (fplmns == null) { |
| 5050 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5051 | } |
| 5052 | for (String fplmn : fplmns) { |
| 5053 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5054 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5055 | } |
| 5056 | } |
| 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
| 5059 | Object response = sendRequest( |
| 5060 | CMD_SET_FORBIDDEN_PLMNS, |
| 5061 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5062 | subId); |
| 5063 | return (int) response; |
| 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
| 5067 | } |
| 5068 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5069 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5070 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5072 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | final long identity = Binder.clearCallingIdentity(); |
| 5075 | try { |
| 5076 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5077 | if (response.payload == null) { |
| 5078 | return ""; |
| 5079 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5081 | // Append the returned status code to the end of the response payload. |
| 5082 | String s = Integer.toHexString( |
| 5083 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5084 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5085 | return s; |
| 5086 | } finally { |
| 5087 | Binder.restoreCallingIdentity(identity); |
| 5088 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5089 | } |
| 5090 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5091 | /** |
| 5092 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5093 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5094 | * |
| 5095 | * @param itemID the ID of the item to read |
| 5096 | * @return the NV item as a String, or null on error. |
| 5097 | */ |
| 5098 | @Override |
| 5099 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5100 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5101 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5102 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5103 | |
| 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | try { |
| 5106 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5107 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5108 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5109 | return value; |
| 5110 | } finally { |
| 5111 | Binder.restoreCallingIdentity(identity); |
| 5112 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | /** |
| 5116 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5117 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5118 | * |
| 5119 | * @param itemID the ID of the item to read |
| 5120 | * @param itemValue the value to write, as a String |
| 5121 | * @return true on success; false on any failure |
| 5122 | */ |
| 5123 | @Override |
| 5124 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5125 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5127 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5128 | |
| 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
| 5131 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5132 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5133 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5135 | return success; |
| 5136 | } finally { |
| 5137 | Binder.restoreCallingIdentity(identity); |
| 5138 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5139 | } |
| 5140 | |
| 5141 | /** |
| 5142 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5143 | * Used for device configuration by some CDMA operators. |
| 5144 | * |
| 5145 | * @param preferredRoamingList byte array containing the new PRL |
| 5146 | * @return true on success; false on any failure |
| 5147 | */ |
| 5148 | @Override |
| 5149 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5151 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5152 | |
| 5153 | final long identity = Binder.clearCallingIdentity(); |
| 5154 | try { |
| 5155 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5156 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5157 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5158 | return success; |
| 5159 | } finally { |
| 5160 | Binder.restoreCallingIdentity(identity); |
| 5161 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
| 5164 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5165 | * 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] | 5166 | * Used for device configuration by some CDMA operators. |
| 5167 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5168 | * @param slotIndex - device slot. |
| 5169 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5170 | * @return true on success; false on any failure |
| 5171 | */ |
| 5172 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5173 | public boolean resetModemConfig(int slotIndex) { |
| 5174 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5175 | if (phone != null) { |
| 5176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5177 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
| 5181 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5182 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5183 | return success; |
| 5184 | } finally { |
| 5185 | Binder.restoreCallingIdentity(identity); |
| 5186 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5188 | return false; |
| 5189 | } |
| 5190 | |
| 5191 | /** |
| 5192 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5193 | * |
| 5194 | * @param slotIndex - device slot. |
| 5195 | * |
| 5196 | * @return true on success; false on any failure |
| 5197 | */ |
| 5198 | @Override |
| 5199 | public boolean rebootModem(int slotIndex) { |
| 5200 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5201 | if (phone != null) { |
| 5202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5203 | mApp, phone.getSubId(), "rebootModem"); |
| 5204 | |
| 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5208 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5209 | return success; |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
| 5212 | } |
| 5213 | } |
| 5214 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5215 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5216 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5217 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5218 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5219 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5220 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5221 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5222 | return new String[0]; |
| 5223 | } |
| 5224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5227 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5233 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5234 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5235 | * {@link #disableIms(int)}. |
| 5236 | * @param slotIndex device slot. |
| 5237 | */ |
| 5238 | public void resetIms(int slotIndex) { |
| 5239 | enforceModifyPermission(); |
| 5240 | |
| 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
| 5243 | if (mImsResolver == null) { |
| 5244 | // may happen if the does not support IMS. |
| 5245 | return; |
| 5246 | } |
| 5247 | mImsResolver.disableIms(slotIndex); |
| 5248 | mImsResolver.enableIms(slotIndex); |
| 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
| 5252 | } |
| 5253 | |
| 5254 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5255 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5256 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5257 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5258 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5259 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5260 | |
| 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5263 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5264 | // may happen if the device does not support IMS. |
| 5265 | return; |
| 5266 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5267 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | } finally { |
| 5269 | Binder.restoreCallingIdentity(identity); |
| 5270 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5274 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5275 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5276 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5277 | public void disableIms(int slotId) { |
| 5278 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 | |
| 5280 | final long identity = Binder.clearCallingIdentity(); |
| 5281 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5282 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5283 | // may happen if the device does not support IMS. |
| 5284 | return; |
| 5285 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5286 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
| 5289 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5293 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5294 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5295 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5296 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5297 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5298 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | |
| 5300 | final long identity = Binder.clearCallingIdentity(); |
| 5301 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5302 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5303 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5304 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5305 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5306 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5307 | } finally { |
| 5308 | Binder.restoreCallingIdentity(identity); |
| 5309 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5310 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5311 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5312 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5313 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5314 | @Override |
| 5315 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5316 | enforceModifyPermission(); |
| 5317 | |
| 5318 | final long identity = Binder.clearCallingIdentity(); |
| 5319 | try { |
| 5320 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5321 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5328 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5329 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5330 | */ |
| 5331 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5332 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5333 | |
| 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5336 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5337 | // may happen if the device does not support IMS. |
| 5338 | return null; |
| 5339 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5340 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | } finally { |
| 5342 | Binder.restoreCallingIdentity(identity); |
| 5343 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5344 | } |
| 5345 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5346 | /** |
| 5347 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5348 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5349 | */ |
| 5350 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5351 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | |
| 5353 | final long identity = Binder.clearCallingIdentity(); |
| 5354 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5355 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5356 | // may happen if the device does not support IMS. |
| 5357 | return null; |
| 5358 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5359 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } finally { |
| 5361 | Binder.restoreCallingIdentity(identity); |
| 5362 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5363 | } |
| 5364 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5365 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5366 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5367 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5368 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5369 | * @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] | 5370 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5371 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5372 | * @param packageName The name of the package that the current configuration will be replaced |
| 5373 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5374 | * @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] | 5375 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5376 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5377 | int[] featureTypes, String packageName) { |
| 5378 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5379 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5380 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5381 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5382 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5383 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | final long identity = Binder.clearCallingIdentity(); |
| 5385 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5386 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5387 | // may happen if the device does not support IMS. |
| 5388 | return false; |
| 5389 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5390 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5391 | for (int featureType : featureTypes) { |
| 5392 | featureConfig.put(featureType, packageName); |
| 5393 | } |
| 5394 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5395 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(identity); |
| 5398 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5402 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5403 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5404 | * |
| 5405 | * This should only be used for testing. |
| 5406 | * |
| 5407 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5408 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5409 | */ |
| 5410 | @Override |
| 5411 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5412 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5413 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5414 | "clearCarrierImsServiceOverride"); |
| 5415 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5416 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5417 | "clearCarrierImsServiceOverride"); |
| 5418 | |
| 5419 | final long identity = Binder.clearCallingIdentity(); |
| 5420 | try { |
| 5421 | if (mImsResolver == null) { |
| 5422 | // may happen if the device does not support IMS. |
| 5423 | return false; |
| 5424 | } |
| 5425 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
| 5429 | } |
| 5430 | |
| 5431 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5432 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5433 | * |
| 5434 | * @param slotId The slot that the ImsService is associated with. |
| 5435 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5436 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5437 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5438 | * @return the package name of the ImsService configuration. |
| 5439 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5441 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5442 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5443 | TelephonyPermissions |
| 5444 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5445 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5446 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5447 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | final long identity = Binder.clearCallingIdentity(); |
| 5449 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5450 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5451 | // may happen if the device does not support IMS. |
| 5452 | return ""; |
| 5453 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5454 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5455 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5456 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | } finally { |
| 5458 | Binder.restoreCallingIdentity(identity); |
| 5459 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5462 | /** |
| 5463 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5464 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5465 | * @param callback A callback with an integer containing the |
| 5466 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5467 | */ |
| 5468 | @Override |
| 5469 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5470 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5471 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5472 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5473 | "IMS not available on device."); |
| 5474 | } |
| 5475 | final long token = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | int slotId = getSlotIndex(subId); |
| 5478 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5479 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5480 | + subId + "'"); |
| 5481 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5482 | } |
| 5483 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5484 | try { |
| 5485 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5486 | } catch (RemoteException e) { |
| 5487 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5488 | + "Ignore"); |
| 5489 | } |
| 5490 | }); |
| 5491 | } finally { |
| 5492 | Binder.restoreCallingIdentity(token); |
| 5493 | } |
| 5494 | } |
| 5495 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5496 | public void setImsRegistrationState(boolean registered) { |
| 5497 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 | |
| 5499 | final long identity = Binder.clearCallingIdentity(); |
| 5500 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5501 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5502 | } finally { |
| 5503 | Binder.restoreCallingIdentity(identity); |
| 5504 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5508 | * Set the network selection mode to automatic. |
| 5509 | * |
| 5510 | */ |
| 5511 | @Override |
| 5512 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5514 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5515 | |
| 5516 | final long identity = Binder.clearCallingIdentity(); |
| 5517 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5518 | if (!isActiveSubscription(subId)) { |
| 5519 | return; |
| 5520 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5521 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5522 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5523 | } finally { |
| 5524 | Binder.restoreCallingIdentity(identity); |
| 5525 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5528 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5529 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5530 | * |
| 5531 | * @param subId the id of the subscription. |
| 5532 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5533 | * the operator to attach to. |
| 5534 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5535 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5536 | * normal network selection next time. |
| 5537 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5538 | */ |
| 5539 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5540 | public boolean setNetworkSelectionModeManual( |
| 5541 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5543 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5544 | |
| 5545 | if (!isActiveSubscription(subId)) { |
| 5546 | return false; |
| 5547 | } |
| 5548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5551 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5553 | if (DBG) { |
| 5554 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5555 | + " operator: " + operatorInfo); |
| 5556 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5558 | } finally { |
| 5559 | Binder.restoreCallingIdentity(identity); |
| 5560 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5561 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5562 | /** |
| 5563 | * Get the manual network selection |
| 5564 | * |
| 5565 | * @param subId the id of the subscription. |
| 5566 | * |
| 5567 | * @return the previously saved user selected PLMN |
| 5568 | */ |
| 5569 | @Override |
| 5570 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5571 | TelephonyPermissions |
| 5572 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5573 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5574 | |
| 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | try { |
| 5577 | if (!isActiveSubscription(subId)) { |
| 5578 | return ""; |
| 5579 | } |
| 5580 | |
| 5581 | final Phone phone = getPhone(subId); |
| 5582 | if (phone == null) { |
| 5583 | return ""; |
| 5584 | } |
| 5585 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5586 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5587 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5588 | } finally { |
| 5589 | Binder.restoreCallingIdentity(identity); |
| 5590 | } |
| 5591 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5592 | |
| 5593 | /** |
| 5594 | * Scans for available networks. |
| 5595 | */ |
| 5596 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5597 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5598 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5600 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5601 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5602 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5603 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5604 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5605 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5606 | .setCallingPid(Binder.getCallingPid()) |
| 5607 | .setCallingUid(Binder.getCallingUid()) |
| 5608 | .setMethod("getCellNetworkScanResults") |
| 5609 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5610 | .build()); |
| 5611 | switch (locationResult) { |
| 5612 | case DENIED_HARD: |
| 5613 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5614 | case DENIED_SOFT: |
| 5615 | return null; |
| 5616 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5618 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | try { |
| 5620 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5621 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5622 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | } finally { |
| 5624 | Binder.restoreCallingIdentity(identity); |
| 5625 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5626 | } |
| 5627 | |
| 5628 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5629 | * Get the call forwarding info, given the call forwarding reason. |
| 5630 | */ |
| 5631 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5632 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5633 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5634 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5635 | long identity = Binder.clearCallingIdentity(); |
| 5636 | try { |
| 5637 | if (DBG) { |
| 5638 | log("getCallForwarding: subId " + subId |
| 5639 | + " callForwardingReason" + callForwardingReason); |
| 5640 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5641 | |
| 5642 | Phone phone = getPhone(subId); |
| 5643 | if (phone == null) { |
| 5644 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5645 | callback.onError( |
| 5646 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5647 | } catch (RemoteException e) { |
| 5648 | // ignore |
| 5649 | } |
| 5650 | return; |
| 5651 | } |
| 5652 | |
| 5653 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5654 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5655 | @Override |
| 5656 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5657 | try { |
| 5658 | callback.onCallForwardingInfoAvailable(info); |
| 5659 | } catch (RemoteException e) { |
| 5660 | // ignore |
| 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | @Override |
| 5665 | public void onError(int error) { |
| 5666 | try { |
| 5667 | callback.onError(error); |
| 5668 | } catch (RemoteException e) { |
| 5669 | // ignore |
| 5670 | } |
| 5671 | } |
| 5672 | }); |
| 5673 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5674 | } finally { |
| 5675 | Binder.restoreCallingIdentity(identity); |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | /** |
| 5680 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5681 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5682 | */ |
| 5683 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5684 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5685 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5686 | enforceModifyPermission(); |
| 5687 | long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | if (DBG) { |
| 5690 | log("setCallForwarding: subId " + subId |
| 5691 | + " callForwardingInfo" + callForwardingInfo); |
| 5692 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5693 | |
| 5694 | Phone phone = getPhone(subId); |
| 5695 | if (phone == null) { |
| 5696 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5697 | callback.accept( |
| 5698 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5699 | } catch (RemoteException e) { |
| 5700 | // ignore |
| 5701 | } |
| 5702 | return; |
| 5703 | } |
| 5704 | |
| 5705 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5706 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5707 | |
| 5708 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5709 | } finally { |
| 5710 | Binder.restoreCallingIdentity(identity); |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5715 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5716 | */ |
| 5717 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5718 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5719 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5720 | long identity = Binder.clearCallingIdentity(); |
| 5721 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5722 | |
| 5723 | Phone phone = getPhone(subId); |
| 5724 | if (phone == null) { |
| 5725 | try { |
| 5726 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5727 | } catch (RemoteException e) { |
| 5728 | // ignore |
| 5729 | } |
| 5730 | return; |
| 5731 | } |
| 5732 | |
| 5733 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5734 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5735 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5736 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
| 5740 | } |
| 5741 | |
| 5742 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5743 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5744 | */ |
| 5745 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5746 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5747 | enforceModifyPermission(); |
| 5748 | long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5750 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5751 | |
| 5752 | Phone phone = getPhone(subId); |
| 5753 | if (phone == null) { |
| 5754 | try { |
| 5755 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5756 | } catch (RemoteException e) { |
| 5757 | // ignore |
| 5758 | } |
| 5759 | return; |
| 5760 | } |
| 5761 | |
| 5762 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5763 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5764 | |
| 5765 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5772 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5773 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5774 | * @param subId id of the subscription |
| 5775 | * @param request contains the radio access networks with bands/channels to scan |
| 5776 | * @param messenger callback messenger for scan results or errors |
| 5777 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5778 | * @return the id of the requested scan which can be used to stop the scan. |
| 5779 | */ |
| 5780 | @Override |
| 5781 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5782 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5784 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5785 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5786 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5787 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5788 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5789 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5790 | .setCallingPid(Binder.getCallingPid()) |
| 5791 | .setCallingUid(Binder.getCallingUid()) |
| 5792 | .setMethod("requestNetworkScan") |
| 5793 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5794 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5795 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5796 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5797 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5798 | if (e != null) { |
| 5799 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5800 | throw e; |
| 5801 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5802 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5803 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5804 | } |
| 5805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5807 | int callingUid = Binder.getCallingUid(); |
| 5808 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5809 | final long identity = Binder.clearCallingIdentity(); |
| 5810 | try { |
| 5811 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5812 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5813 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(identity); |
| 5816 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5819 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5820 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5821 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5822 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5823 | boolean hasNetworkScanPermission = |
| 5824 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5825 | == PERMISSION_GRANTED; |
| 5826 | |
| 5827 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5828 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5829 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5833 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5834 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5835 | return new SecurityException("Specific channels must not be" |
| 5836 | + " scanned without location access."); |
| 5837 | } |
| 5838 | } |
| 5839 | } |
| 5840 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5841 | return null; |
| 5842 | } |
| 5843 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5844 | /** |
| 5845 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5846 | * |
| 5847 | * @param subId id of the subscription |
| 5848 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5849 | */ |
| 5850 | @Override |
| 5851 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5853 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5855 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5858 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | } finally { |
| 5860 | Binder.restoreCallingIdentity(identity); |
| 5861 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5865 | * Get the calculated preferred network type. |
| 5866 | * Used for debugging incorrect network type. |
| 5867 | * |
| 5868 | * @return the preferred network type, defined in RILConstants.java. |
| 5869 | */ |
| 5870 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5871 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5872 | final Phone defaultPhone = getDefaultPhone(); |
| 5873 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5874 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5875 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5876 | } |
| 5877 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | final long identity = Binder.clearCallingIdentity(); |
| 5879 | try { |
| 5880 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5881 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | } finally { |
| 5883 | Binder.restoreCallingIdentity(identity); |
| 5884 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5888 | * Get the preferred network type. |
| 5889 | * Used for device configuration by some CDMA operators. |
| 5890 | * |
| 5891 | * @return the preferred network type, defined in RILConstants.java. |
| 5892 | */ |
| 5893 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5894 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5895 | TelephonyPermissions |
| 5896 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5897 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5898 | |
| 5899 | final long identity = Binder.clearCallingIdentity(); |
| 5900 | try { |
| 5901 | if (DBG) log("getPreferredNetworkType"); |
| 5902 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5903 | int networkType = (result != null ? result[0] : -1); |
| 5904 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5905 | return networkType; |
| 5906 | } finally { |
| 5907 | Binder.restoreCallingIdentity(identity); |
| 5908 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | /** |
| 5912 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5913 | * |
| 5914 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5915 | * @return true on success; false on any failure. |
| 5916 | */ |
| 5917 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5918 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5920 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | |
| 5922 | final long identity = Binder.clearCallingIdentity(); |
| 5923 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5924 | Boolean success = (Boolean) sendRequest( |
| 5925 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5926 | |
| 5927 | if (success) { |
| 5928 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5929 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5930 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5931 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5932 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5933 | } finally { |
| 5934 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5935 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5936 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5937 | |
| 5938 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5939 | * Get the allowed network types that store in the telephony provider. |
| 5940 | * |
| 5941 | * @param subId the id of the subscription. |
| 5942 | * @return allowedNetworkTypes the allowed network types. |
| 5943 | */ |
| 5944 | @Override |
| 5945 | public long getAllowedNetworkTypes(int subId) { |
| 5946 | TelephonyPermissions |
| 5947 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5948 | mApp, subId, "getAllowedNetworkTypes"); |
| 5949 | |
| 5950 | final long identity = Binder.clearCallingIdentity(); |
| 5951 | try { |
| 5952 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5953 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5954 | } finally { |
| 5955 | Binder.restoreCallingIdentity(identity); |
| 5956 | } |
| 5957 | } |
| 5958 | |
| 5959 | /** |
| 5960 | * Set the allowed network types. |
| 5961 | * |
| 5962 | * @param subId the id of the subscription. |
| 5963 | * @param allowedNetworkTypes the allowed network types. |
| 5964 | * @return true on success; false on any failure. |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5969 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5970 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5971 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5972 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5973 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5974 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5975 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5976 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5977 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5978 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5982 | * Get the allowed network types for certain reason. |
| 5983 | * |
| 5984 | * @param subId the id of the subscription. |
| 5985 | * @param reason the reason the allowed network type change is taking place |
| 5986 | * @return the allowed network types. |
| 5987 | */ |
| 5988 | @Override |
| 5989 | public long getAllowedNetworkTypesForReason(int subId, |
| 5990 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5991 | TelephonyPermissions |
| 5992 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5993 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5994 | final long identity = Binder.clearCallingIdentity(); |
| 5995 | try { |
| 5996 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5997 | } finally { |
| 5998 | Binder.restoreCallingIdentity(identity); |
| 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6003 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6004 | * @param subId subscription id of the sim card |
| 6005 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6006 | * This can be passed following states |
| 6007 | * <ol> |
| 6008 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6009 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6010 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6011 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6012 | * </ol> |
| 6013 | * @return operation result. |
| 6014 | */ |
| 6015 | @Override |
| 6016 | public int setNrDualConnectivityState(int subId, |
| 6017 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6019 | mApp, subId, "enableNRDualConnectivity"); |
| 6020 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
| 6023 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6024 | nrDualConnectivityState, subId, |
| 6025 | workSource); |
| 6026 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6027 | return result; |
| 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
| 6031 | } |
| 6032 | |
| 6033 | /** |
| 6034 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6035 | * @return true if dual connectivity is enabled else false |
| 6036 | */ |
| 6037 | @Override |
| 6038 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6039 | TelephonyPermissions |
| 6040 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6041 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6042 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
| 6045 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6046 | null, subId, workSource); |
| 6047 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6048 | return isEnabled; |
| 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
| 6051 | } |
| 6052 | } |
| 6053 | |
| 6054 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6055 | * get carrier bandwidth per primary and secondary carrier |
| 6056 | * @param subId subscription id of the sim card |
| 6057 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6058 | */ |
| 6059 | @Override |
| 6060 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6061 | TelephonyPermissions |
| 6062 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6063 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6064 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6065 | final long identity = Binder.clearCallingIdentity(); |
| 6066 | try { |
| 6067 | CarrierBandwidth carrierBandwidth = |
| 6068 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6069 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6070 | return carrierBandwidth; |
| 6071 | } finally { |
| 6072 | Binder.restoreCallingIdentity(identity); |
| 6073 | } |
| 6074 | } |
| 6075 | |
| 6076 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6077 | * Get the effective allowed network types on the device. |
| 6078 | * This API will return an intersection of allowed network types for all reasons, |
| 6079 | * including the configuration done through setAllowedNetworkTypes |
| 6080 | * |
| 6081 | * @param subId the id of the subscription. |
| 6082 | * @return the allowed network types |
| 6083 | */ |
| 6084 | @Override |
| 6085 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6086 | TelephonyPermissions |
| 6087 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6088 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6089 | final long identity = Binder.clearCallingIdentity(); |
| 6090 | try { |
| 6091 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | /** |
| 6098 | * Set the allowed network types of the device and |
| 6099 | * provide the reason triggering the allowed network change. |
| 6100 | * |
| 6101 | * @param subId the id of the subscription. |
| 6102 | * @param reason the reason the allowed network type change is taking place |
| 6103 | * @param allowedNetworkTypes the allowed network types. |
| 6104 | * @return true on success; false on any failure. |
| 6105 | */ |
| 6106 | @Override |
| 6107 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6108 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6110 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6111 | final long identity = Binder.clearCallingIdentity(); |
| 6112 | try { |
| 6113 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6114 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6115 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6116 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6117 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6118 | } finally { |
| 6119 | Binder.restoreCallingIdentity(identity); |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6124 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6125 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6126 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6127 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6128 | * @hide |
| 6129 | */ |
| 6130 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6131 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6133 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6134 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6136 | if (phone != null) { |
| 6137 | return phone.hasMatchedTetherApnSetting(); |
| 6138 | } else { |
| 6139 | return false; |
| 6140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6143 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6144 | } |
| 6145 | |
| 6146 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6147 | * Enable or disable always reporting signal strength changes from radio. |
| 6148 | * |
| 6149 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6150 | */ |
| 6151 | @Override |
| 6152 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6153 | enforceModifyPermission(); |
| 6154 | enforceSystemCaller(); |
| 6155 | |
| 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | final Phone phone = getPhone(subId); |
| 6158 | try { |
| 6159 | if (phone != null) { |
| 6160 | if (DBG) { |
| 6161 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6162 | + " isEnable=" + isEnable); |
| 6163 | } |
| 6164 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6165 | } else { |
| 6166 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6167 | + subId); |
| 6168 | } |
| 6169 | } finally { |
| 6170 | Binder.restoreCallingIdentity(identity); |
| 6171 | } |
| 6172 | } |
| 6173 | |
| 6174 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6175 | * Get the user enabled state of Mobile Data. |
| 6176 | * |
| 6177 | * TODO: remove and use isUserDataEnabled. |
| 6178 | * This can't be removed now because some vendor codes |
| 6179 | * calls through ITelephony directly while they should |
| 6180 | * use TelephonyManager. |
| 6181 | * |
| 6182 | * @return true on enabled |
| 6183 | */ |
| 6184 | @Override |
| 6185 | public boolean getDataEnabled(int subId) { |
| 6186 | return isUserDataEnabled(subId); |
| 6187 | } |
| 6188 | |
| 6189 | /** |
| 6190 | * Get whether mobile data is enabled per user setting. |
| 6191 | * |
| 6192 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6193 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6194 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6195 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6196 | * |
| 6197 | * @return {@code true} if data is enabled else {@code false} |
| 6198 | */ |
| 6199 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6200 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6201 | try { |
| 6202 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6203 | null); |
| 6204 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6206 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | |
| 6209 | final long identity = Binder.clearCallingIdentity(); |
| 6210 | try { |
| 6211 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6212 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6213 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6214 | if (phone != null) { |
| 6215 | boolean retVal = phone.isUserDataEnabled(); |
| 6216 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6217 | return retVal; |
| 6218 | } else { |
| 6219 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6220 | return false; |
| 6221 | } |
| 6222 | } finally { |
| 6223 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6224 | } |
| 6225 | } |
| 6226 | |
| 6227 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6228 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6229 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6230 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6231 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6232 | * @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] | 6233 | */ |
| 6234 | @Override |
| 6235 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6236 | try { |
| 6237 | try { |
| 6238 | mApp.enforceCallingOrSelfPermission( |
| 6239 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6240 | null); |
| 6241 | } catch (Exception e) { |
| 6242 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6243 | "isDataEnabled"); |
| 6244 | } |
| 6245 | } catch (Exception e) { |
| 6246 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6247 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6248 | |
| 6249 | final long identity = Binder.clearCallingIdentity(); |
| 6250 | try { |
| 6251 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6252 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6253 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6254 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6255 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6257 | return retVal; |
| 6258 | } else { |
| 6259 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6260 | return false; |
| 6261 | } |
| 6262 | } finally { |
| 6263 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6264 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6265 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6266 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6267 | /** |
| 6268 | * Check if data is enabled for a specific reason |
| 6269 | * @param subId Subscription index |
| 6270 | * @param reason the reason the data enable change is taking place |
| 6271 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6272 | */ |
| 6273 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6274 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6275 | @TelephonyManager.DataEnabledReason int reason) { |
| 6276 | try { |
| 6277 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6278 | null); |
| 6279 | } catch (Exception e) { |
| 6280 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6281 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | |
| 6285 | final long identity = Binder.clearCallingIdentity(); |
| 6286 | try { |
| 6287 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6288 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6289 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6290 | + " reason=" + reason); |
| 6291 | } |
| 6292 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6293 | if (phone != null) { |
| 6294 | boolean retVal; |
| 6295 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6296 | retVal = phone.isUserDataEnabled(); |
| 6297 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6298 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6299 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6300 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6301 | return retVal; |
| 6302 | } else { |
| 6303 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6304 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6305 | + subId + " retVal=false"); |
| 6306 | } |
| 6307 | return false; |
| 6308 | } |
| 6309 | } finally { |
| 6310 | Binder.restoreCallingIdentity(identity); |
| 6311 | } |
| 6312 | } |
| 6313 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6314 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6315 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6316 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6317 | // Skip the check if it's one of these special uids |
| 6318 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6319 | } |
| 6320 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6321 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6322 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6323 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6324 | || subController == null) return privilegeFromSim; |
| 6325 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6326 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6327 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6328 | |
| 6329 | final long identity = Binder.clearCallingIdentity(); |
| 6330 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6331 | int subId = phone.getSubId(); |
| 6332 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6333 | // A test override is in place for the privileges for this subId, so don't try to |
| 6334 | // read the subscription privileges. |
| 6335 | return privilegeFromSim; |
| 6336 | } |
| 6337 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6338 | SubscriptionManager subManager = (SubscriptionManager) |
| 6339 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6340 | for (String pkg : packages) { |
| 6341 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6342 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6343 | } |
| 6344 | } |
| 6345 | return privilegeFromSim; |
| 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
| 6349 | } |
| 6350 | |
| 6351 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6352 | String pkgName) { |
| 6353 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6354 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6355 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6356 | || subController == null) return privilegeFromSim; |
| 6357 | |
| 6358 | final long identity = Binder.clearCallingIdentity(); |
| 6359 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6360 | int subId = phone.getSubId(); |
| 6361 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6362 | // A test override is in place for the privileges for this subId, so don't try to |
| 6363 | // read the subscription privileges. |
| 6364 | return privilegeFromSim; |
| 6365 | } |
| 6366 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6367 | SubscriptionManager subManager = (SubscriptionManager) |
| 6368 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6369 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6370 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6371 | } finally { |
| 6372 | Binder.restoreCallingIdentity(identity); |
| 6373 | } |
| 6374 | } |
| 6375 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6376 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6377 | public int getCarrierPrivilegeStatus(int subId) { |
| 6378 | final Phone phone = getPhone(subId); |
| 6379 | if (phone == null) { |
| 6380 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6381 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6382 | } |
| 6383 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6384 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6385 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6386 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6387 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6388 | |
| 6389 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6390 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6391 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6392 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6393 | |
| 6394 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6395 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6396 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6397 | final Phone phone = getPhone(subId); |
| 6398 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6399 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6400 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6401 | } |
| 6402 | UiccProfile profile = |
| 6403 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6404 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6405 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6406 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6407 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6408 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6409 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6410 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6411 | } |
| 6412 | |
| 6413 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6414 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6415 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6416 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6420 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6421 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6422 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6423 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6424 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6425 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6426 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6427 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6428 | } |
| 6429 | |
| 6430 | @Override |
| 6431 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6432 | if (TextUtils.isEmpty(pkgName)) |
| 6433 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6434 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6435 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6436 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6437 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6438 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6439 | continue; |
| 6440 | } |
| 6441 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6442 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6443 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6444 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6445 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6446 | break; |
| 6447 | } |
| 6448 | } |
| 6449 | |
| 6450 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6451 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6452 | |
| 6453 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6454 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6455 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6456 | loge("phoneId " + phoneId + " is not valid."); |
| 6457 | return null; |
| 6458 | } |
| 6459 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6460 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6461 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6462 | return null ; |
| 6463 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6464 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6467 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6468 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6469 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6470 | List<String> privilegedPackages = new ArrayList<>(); |
| 6471 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6472 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6473 | // has UICC in that slot. |
| 6474 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6475 | if (card.hasCarrierPrivilegeRules()) { |
| 6476 | if (packages == null) { |
| 6477 | // Only check packages in user 0 for now |
| 6478 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6479 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6480 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6481 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6482 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6483 | } |
| 6484 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6485 | PackageInfo pkgInfo = packages.get(p); |
| 6486 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6487 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6488 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6489 | privilegedPackages.add(pkgInfo.packageName); |
| 6490 | } |
| 6491 | } |
| 6492 | } |
| 6493 | } |
| 6494 | return privilegedPackages; |
| 6495 | } |
| 6496 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6497 | @Override |
| 6498 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6499 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6500 | |
| 6501 | final long identity = Binder.clearCallingIdentity(); |
| 6502 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6503 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6504 | try { |
| 6505 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6506 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6507 | } |
| 6508 | } finally { |
| 6509 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6510 | } |
| 6511 | return privilegedPackages; |
| 6512 | } |
| 6513 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6514 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6515 | final Phone phone = getPhone(subId); |
| 6516 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6517 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6518 | return null; |
| 6519 | } |
| 6520 | String iccId = card.getIccId(); |
| 6521 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6522 | return null; |
| 6523 | } |
| 6524 | return iccId; |
| 6525 | } |
| 6526 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6527 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6528 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6529 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6530 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6531 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
| 6535 | final String iccId = getIccId(subId); |
| 6536 | final Phone phone = getPhone(subId); |
| 6537 | if (phone == null) { |
| 6538 | return false; |
| 6539 | } |
| 6540 | final String subscriberId = phone.getSubscriberId(); |
| 6541 | |
| 6542 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6543 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6544 | + subscriberId + " to " + number); |
| 6545 | } |
| 6546 | |
| 6547 | if (TextUtils.isEmpty(iccId)) { |
| 6548 | return false; |
| 6549 | } |
| 6550 | |
| 6551 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6552 | |
| 6553 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6554 | if (alphaTag == null) { |
| 6555 | editor.remove(alphaTagPrefKey); |
| 6556 | } else { |
| 6557 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6558 | } |
| 6559 | |
| 6560 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6561 | // track all merged IMSIs based on line number |
| 6562 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6563 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6564 | if (number == null) { |
| 6565 | editor.remove(numberPrefKey); |
| 6566 | editor.remove(subscriberPrefKey); |
| 6567 | } else { |
| 6568 | editor.putString(numberPrefKey, number); |
| 6569 | editor.putString(subscriberPrefKey, subscriberId); |
| 6570 | } |
| 6571 | |
| 6572 | editor.commit(); |
| 6573 | return true; |
| 6574 | } finally { |
| 6575 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6576 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6577 | } |
| 6578 | |
| 6579 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6580 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6581 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6582 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6584 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6585 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6586 | return null; |
| 6587 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | String iccId = getIccId(subId); |
| 6592 | if (iccId != null) { |
| 6593 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6594 | if (DBG_MERGE) { |
| 6595 | log("getLine1NumberForDisplay returning " |
| 6596 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6597 | } |
| 6598 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6599 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6601 | return null; |
| 6602 | } finally { |
| 6603 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6604 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6608 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6609 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6611 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6612 | return null; |
| 6613 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6614 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6615 | final long identity = Binder.clearCallingIdentity(); |
| 6616 | try { |
| 6617 | String iccId = getIccId(subId); |
| 6618 | if (iccId != null) { |
| 6619 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6620 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6621 | } |
| 6622 | return null; |
| 6623 | } finally { |
| 6624 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6625 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6626 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6627 | |
| 6628 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6629 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6630 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6631 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6632 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6633 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6634 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6635 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6636 | return null; |
| 6637 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6638 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6639 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6640 | // the process, where TelephonyManager was instantiated. |
| 6641 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6642 | final long identity = Binder.clearCallingIdentity(); |
| 6643 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6644 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6645 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6646 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6647 | |
| 6648 | // Figure out what subscribers are currently active |
| 6649 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6650 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6651 | // Only consider subs which match the current subId |
| 6652 | // This logic can be simplified. See b/131189269 for progress. |
| 6653 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6654 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6655 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6656 | |
| 6657 | // First pass, find a number override for an active subscriber |
| 6658 | String mergeNumber = null; |
| 6659 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6660 | for (String key : prefs.keySet()) { |
| 6661 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6662 | final String subscriberId = (String) prefs.get(key); |
| 6663 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6664 | final String iccId = key.substring( |
| 6665 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6666 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6667 | mergeNumber = (String) prefs.get(numberKey); |
| 6668 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6669 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | + " for active subscriber " + subscriberId); |
| 6671 | } |
| 6672 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6673 | break; |
| 6674 | } |
| 6675 | } |
| 6676 | } |
| 6677 | } |
| 6678 | |
| 6679 | // Shortcut when no active merged subscribers |
| 6680 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6681 | return null; |
| 6682 | } |
| 6683 | |
| 6684 | // Second pass, find all subscribers under that line override |
| 6685 | final ArraySet<String> result = new ArraySet<>(); |
| 6686 | for (String key : prefs.keySet()) { |
| 6687 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6688 | final String number = (String) prefs.get(key); |
| 6689 | if (mergeNumber.equals(number)) { |
| 6690 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6691 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6692 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6693 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6694 | result.add(subscriberId); |
| 6695 | } |
| 6696 | } |
| 6697 | } |
| 6698 | } |
| 6699 | |
| 6700 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6701 | Arrays.sort(resultArray); |
| 6702 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6703 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6704 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6705 | } |
| 6706 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6709 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6710 | } |
| 6711 | |
| 6712 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6713 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6714 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6715 | |
| 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
| 6718 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6719 | TelephonyManager.class); |
| 6720 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6721 | if (subscriberId == null) { |
| 6722 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6723 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6724 | + subId); |
| 6725 | } |
| 6726 | return null; |
| 6727 | } |
| 6728 | |
| 6729 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6730 | .getSubscriptionInfo(subId); |
| 6731 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6732 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6733 | if (groupUuid == null) { |
| 6734 | return new String[]{subscriberId}; |
| 6735 | } |
| 6736 | |
| 6737 | // Get all subscriberIds from the group. |
| 6738 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6739 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6740 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6741 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6742 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6743 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6744 | if (subscriberId != null) { |
| 6745 | mergedSubscriberIds.add(subscriberId); |
| 6746 | } |
| 6747 | } |
| 6748 | |
| 6749 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6750 | } finally { |
| 6751 | Binder.restoreCallingIdentity(identity); |
| 6752 | |
| 6753 | } |
| 6754 | } |
| 6755 | |
| 6756 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6757 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6758 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6759 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | |
| 6761 | final long identity = Binder.clearCallingIdentity(); |
| 6762 | try { |
| 6763 | final Phone phone = getPhone(subId); |
| 6764 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
| 6767 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6768 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6769 | |
| 6770 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6771 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6772 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6773 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6774 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6775 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | |
| 6777 | final long identity = Binder.clearCallingIdentity(); |
| 6778 | try { |
| 6779 | final Phone phone = getPhone(subId); |
| 6780 | if (phone == null) { |
| 6781 | return false; |
| 6782 | } |
| 6783 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6784 | cdmaNonRoamingList); |
| 6785 | } finally { |
| 6786 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6787 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6791 | @Deprecated |
| 6792 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6793 | enforceModifyPermission(); |
| 6794 | |
| 6795 | int returnValue = 0; |
| 6796 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6797 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6798 | if(result.exception == null) { |
| 6799 | if (result.result != null) { |
| 6800 | byte[] responseData = (byte[])(result.result); |
| 6801 | if(responseData.length > oemResp.length) { |
| 6802 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6803 | responseData.length + "bytes. Buffer Size is " + |
| 6804 | oemResp.length + "bytes."); |
| 6805 | } |
| 6806 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6807 | returnValue = responseData.length; |
| 6808 | } |
| 6809 | } else { |
| 6810 | CommandException ex = (CommandException) result.exception; |
| 6811 | returnValue = ex.getCommandError().ordinal(); |
| 6812 | if(returnValue > 0) returnValue *= -1; |
| 6813 | } |
| 6814 | } catch (RuntimeException e) { |
| 6815 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6816 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6817 | if(returnValue > 0) returnValue *= -1; |
| 6818 | } |
| 6819 | |
| 6820 | return returnValue; |
| 6821 | } |
| 6822 | |
| 6823 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6824 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6825 | try { |
| 6826 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6827 | } catch (RuntimeException e) { |
| 6828 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6829 | } |
| 6830 | } |
| 6831 | |
| 6832 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6833 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6834 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6835 | try { |
| 6836 | TelephonyPermissions |
| 6837 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6838 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6839 | } catch (SecurityException e) { |
| 6840 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6841 | throw e; |
| 6842 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6843 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6844 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6845 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6847 | final long identity = Binder.clearCallingIdentity(); |
| 6848 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6849 | TelephonyPermissions |
| 6850 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6851 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6852 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
| 6855 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6856 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6857 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6858 | |
| 6859 | @Override |
| 6860 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6861 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6862 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | |
| 6864 | final long identity = Binder.clearCallingIdentity(); |
| 6865 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6866 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6867 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | } finally { |
| 6869 | Binder.restoreCallingIdentity(identity); |
| 6870 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6871 | } |
| 6872 | |
| 6873 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6874 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6875 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6876 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6877 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6878 | return false; |
| 6879 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6880 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6881 | final long identity = Binder.clearCallingIdentity(); |
| 6882 | try { |
| 6883 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6884 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6885 | // In the long run, we may instead need to check if there exists a connection service |
| 6886 | // which can support video calling. |
| 6887 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6888 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6889 | return imsManager.isVtEnabledByPlatform() |
| 6890 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6891 | && imsManager.isVtEnabledByUser(); |
| 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6895 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6896 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6897 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6898 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6899 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6901 | mApp, subId, callingPackage, callingFeatureId, |
| 6902 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | return false; |
| 6904 | } |
| 6905 | |
| 6906 | final long identity = Binder.clearCallingIdentity(); |
| 6907 | try { |
| 6908 | CarrierConfigManager configManager = |
| 6909 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6910 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6911 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6912 | } finally { |
| 6913 | Binder.restoreCallingIdentity(identity); |
| 6914 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6915 | } |
| 6916 | |
| 6917 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6918 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6920 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 | return false; |
| 6922 | } |
| 6923 | |
| 6924 | final long identity = Binder.clearCallingIdentity(); |
| 6925 | try { |
| 6926 | CarrierConfigManager configManager = |
| 6927 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6928 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6929 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6930 | } finally { |
| 6931 | Binder.restoreCallingIdentity(identity); |
| 6932 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6933 | } |
| 6934 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6935 | @Override |
| 6936 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6937 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6938 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6939 | } |
| 6940 | |
| 6941 | @Override |
| 6942 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6943 | final long identity = Binder.clearCallingIdentity(); |
| 6944 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6945 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6946 | } finally { |
| 6947 | Binder.restoreCallingIdentity(identity); |
| 6948 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6949 | } |
| 6950 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6951 | /** |
| 6952 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6953 | * support for the feature and device firmware support. |
| 6954 | * |
| 6955 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6956 | */ |
| 6957 | @Override |
| 6958 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6959 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6960 | final Phone phone = getPhone(subscriptionId); |
| 6961 | if (phone == null) { |
| 6962 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6963 | return false; |
| 6964 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6965 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6966 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6968 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6969 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6970 | return isCarrierSupported && isDeviceSupported; |
| 6971 | } finally { |
| 6972 | Binder.restoreCallingIdentity(identity); |
| 6973 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6974 | } |
| 6975 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6976 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6977 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6978 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6979 | * 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] | 6980 | */ |
| 6981 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6984 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6985 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6986 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6987 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6988 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6989 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | } finally { |
| 6991 | Binder.restoreCallingIdentity(identity); |
| 6992 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6993 | } |
| 6994 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6995 | @Deprecated |
| 6996 | @Override |
| 6997 | public String getDeviceId(String callingPackage) { |
| 6998 | return getDeviceIdWithFeature(callingPackage, null); |
| 6999 | } |
| 7000 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7001 | /** |
| 7002 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7003 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7004 | * |
| 7005 | * <p>Requires Permission: |
| 7006 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7007 | */ |
| 7008 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7009 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7010 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7011 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7012 | return null; |
| 7013 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7014 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7015 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7016 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7017 | return null; |
| 7018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | return phone.getDeviceId(); |
| 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
| 7025 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7026 | } |
| 7027 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7028 | /** |
| 7029 | * {@hide} |
| 7030 | * Returns the IMS Registration Status on a particular subid |
| 7031 | * |
| 7032 | * @param subId |
| 7033 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7034 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7035 | Phone phone = getPhone(subId); |
| 7036 | if (phone != null) { |
| 7037 | return phone.isImsRegistered(); |
| 7038 | } else { |
| 7039 | return false; |
| 7040 | } |
| 7041 | } |
| 7042 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7043 | @Override |
| 7044 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| 7047 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7048 | } finally { |
| 7049 | Binder.restoreCallingIdentity(identity); |
| 7050 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7051 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7052 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7053 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7054 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7055 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7057 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7058 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7059 | } |
| 7060 | final long identity = Binder.clearCallingIdentity(); |
| 7061 | try { |
| 7062 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7069 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7070 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7071 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7072 | final long identity = Binder.clearCallingIdentity(); |
| 7073 | try { |
| 7074 | Phone phone = getPhone(subscriptionId); |
| 7075 | if (phone == null) { |
| 7076 | return null; |
| 7077 | } |
| 7078 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7079 | } finally { |
| 7080 | Binder.restoreCallingIdentity(identity); |
| 7081 | } |
| 7082 | } |
| 7083 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7084 | /** |
| 7085 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7086 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7087 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7088 | final long identity = Binder.clearCallingIdentity(); |
| 7089 | try { |
| 7090 | Phone phone = getPhone(subId); |
| 7091 | if (phone != null) { |
| 7092 | return phone.isWifiCallingEnabled(); |
| 7093 | } else { |
| 7094 | return false; |
| 7095 | } |
| 7096 | } finally { |
| 7097 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7098 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7099 | } |
| 7100 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7101 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7102 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7103 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7104 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | final long identity = Binder.clearCallingIdentity(); |
| 7106 | try { |
| 7107 | Phone phone = getPhone(subId); |
| 7108 | if (phone != null) { |
| 7109 | return phone.isVideoEnabled(); |
| 7110 | } else { |
| 7111 | return false; |
| 7112 | } |
| 7113 | } finally { |
| 7114 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | /** |
| 7119 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7120 | * defined in {@link ImsRegistrationImplBase}. |
| 7121 | */ |
| 7122 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7123 | final long identity = Binder.clearCallingIdentity(); |
| 7124 | try { |
| 7125 | Phone phone = getPhone(subId); |
| 7126 | if (phone != null) { |
| 7127 | return phone.getImsRegistrationTech(); |
| 7128 | } else { |
| 7129 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7130 | } |
| 7131 | } finally { |
| 7132 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7133 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7136 | @Override |
| 7137 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7138 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7139 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7140 | return; |
| 7141 | } |
| 7142 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7143 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7144 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7145 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7146 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7147 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7148 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7149 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7150 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7151 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7152 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7153 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7154 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7155 | // There has been issues when Sms raw table somehow stores orphan |
| 7156 | // fragments. They lead to garbled message when new fragments come |
| 7157 | // in and combined with those stale ones. In case this happens again, |
| 7158 | // user can reset all network settings which will clean up this table. |
| 7159 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7160 | // Clean up IMS settings as well here. |
| 7161 | int slotId = getSlotIndex(subId); |
| 7162 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7163 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7164 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7165 | |
| 7166 | // Erase modem config if erase modem on network setting is enabled. |
| 7167 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7168 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7169 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7170 | sendEraseModemConfig(getDefaultPhone()); |
| 7171 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7172 | } finally { |
| 7173 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7174 | } |
| 7175 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7176 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7177 | private void cleanUpSmsRawTable(Context context) { |
| 7178 | ContentResolver resolver = context.getContentResolver(); |
| 7179 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7180 | resolver.delete(uri, null, null); |
| 7181 | } |
| 7182 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7183 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7184 | public String getSimLocaleForSubscriber(int subId) { |
| 7185 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7186 | final Phone phone = getPhone(subId); |
| 7187 | if (phone == null) { |
| 7188 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7189 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7190 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7191 | final long identity = Binder.clearCallingIdentity(); |
| 7192 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7193 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7194 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7195 | if (info == null) { |
| 7196 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7197 | return null; |
| 7198 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7200 | // preferences (EF-PL and EF-LI)... |
| 7201 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7202 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7203 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7204 | if (localeFromDefaultSim != null) { |
| 7205 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7206 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7207 | + localeFromDefaultSim); |
| 7208 | return localeFromDefaultSim.toLanguageTag(); |
| 7209 | } else { |
| 7210 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7211 | } |
| 7212 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7215 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7216 | // the SIM and carrier preferences does not include a country we add the country |
| 7217 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7218 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7220 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7221 | return mccLocale.toLanguageTag(); |
| 7222 | } |
| 7223 | |
| 7224 | if (DBG) log("No locale found - returning null"); |
| 7225 | return null; |
| 7226 | } finally { |
| 7227 | Binder.restoreCallingIdentity(identity); |
| 7228 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7229 | } |
| 7230 | |
| 7231 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7232 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7233 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7234 | } |
| 7235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | /** |
| 7237 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7238 | */ |
| 7239 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7240 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7241 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7242 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7243 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7244 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7245 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7246 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7247 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7248 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7249 | * representing the state of the modem. |
| 7250 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7251 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7252 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7253 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7254 | */ |
| 7255 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7256 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7257 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7258 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7259 | |
| 7260 | final long identity = Binder.clearCallingIdentity(); |
| 7261 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7262 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7263 | } finally { |
| 7264 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7265 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7266 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7267 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7268 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7269 | // less than total activity duration. |
| 7270 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7271 | if (info == null) { |
| 7272 | return false; |
| 7273 | } |
| 7274 | int activityDurationMs = |
| 7275 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7276 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7277 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7278 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7279 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7280 | } |
| 7281 | return (info.isValid() |
| 7282 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7283 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7284 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7285 | && (totalTxTimeMs <= activityDurationMs)); |
| 7286 | } |
| 7287 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7288 | /** |
| 7289 | * {@hide} |
| 7290 | * Returns the service state information on specified subscription. |
| 7291 | */ |
| 7292 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7293 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7294 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7295 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7296 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7297 | return null; |
| 7298 | } |
| 7299 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7300 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7301 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7302 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7303 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7304 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7305 | .setCallingPid(Binder.getCallingPid()) |
| 7306 | .setCallingUid(Binder.getCallingUid()) |
| 7307 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7308 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7309 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7310 | .build()); |
| 7311 | |
| 7312 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7313 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7314 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7315 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7316 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7317 | .setCallingPid(Binder.getCallingPid()) |
| 7318 | .setCallingUid(Binder.getCallingUid()) |
| 7319 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7320 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7321 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7322 | .build()); |
| 7323 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7324 | boolean hasFinePermission = |
| 7325 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7326 | boolean hasCoarsePermission = |
| 7327 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7328 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7331 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7332 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7333 | Rlog.d(LOG_TAG, |
| 7334 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7335 | return null; |
| 7336 | } |
| 7337 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7338 | final Phone phone = getPhone(subId); |
| 7339 | if (phone == null) { |
| 7340 | return null; |
| 7341 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7342 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7343 | ServiceState ss = phone.getServiceState(); |
| 7344 | |
| 7345 | // Scrub out the location info in ServiceState depending on what level of access |
| 7346 | // the caller has. |
| 7347 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7348 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7349 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | } finally { |
| 7351 | Binder.restoreCallingIdentity(identity); |
| 7352 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7353 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7354 | |
| 7355 | /** |
| 7356 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7357 | * |
| 7358 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7359 | * voicemail ringtone. |
| 7360 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7361 | * PhoneAccount. |
| 7362 | */ |
| 7363 | @Override |
| 7364 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7365 | final long identity = Binder.clearCallingIdentity(); |
| 7366 | try { |
| 7367 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7368 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7369 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7370 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7373 | } finally { |
| 7374 | Binder.restoreCallingIdentity(identity); |
| 7375 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7376 | } |
| 7377 | |
| 7378 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7379 | * Sets the per-account voicemail ringtone. |
| 7380 | * |
| 7381 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7382 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7383 | * |
| 7384 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7385 | * voicemail ringtone. |
| 7386 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7387 | * PhoneAccount. |
| 7388 | */ |
| 7389 | @Override |
| 7390 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7391 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7392 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7394 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7395 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7396 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7397 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7398 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7400 | |
| 7401 | final long identity = Binder.clearCallingIdentity(); |
| 7402 | try { |
| 7403 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7404 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7405 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | } |
| 7407 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7408 | } finally { |
| 7409 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7410 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7414 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7415 | * |
| 7416 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7417 | * voicemail vibration setting. |
| 7418 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7419 | */ |
| 7420 | @Override |
| 7421 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7422 | final long identity = Binder.clearCallingIdentity(); |
| 7423 | try { |
| 7424 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7425 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7426 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7429 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7430 | } finally { |
| 7431 | Binder.restoreCallingIdentity(identity); |
| 7432 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7433 | } |
| 7434 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7435 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7436 | * Sets the per-account voicemail vibration. |
| 7437 | * |
| 7438 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7439 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7440 | * |
| 7441 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7442 | * voicemail vibration setting. |
| 7443 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7444 | * specific PhoneAccount. |
| 7445 | */ |
| 7446 | @Override |
| 7447 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7448 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7449 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7450 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7451 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7452 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7454 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7455 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7456 | } |
| 7457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | final long identity = Binder.clearCallingIdentity(); |
| 7459 | try { |
| 7460 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7461 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7462 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7463 | } |
| 7464 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7465 | } finally { |
| 7466 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7467 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7468 | } |
| 7469 | |
| 7470 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7471 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7472 | * |
| 7473 | * @throws SecurityException if the caller does not have the required permission |
| 7474 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7475 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7476 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7477 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
| 7480 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7481 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7482 | * permission. |
| 7483 | * |
| 7484 | * @throws SecurityException if the caller does not have the required permission |
| 7485 | */ |
| 7486 | private void enforceSendSmsPermission() { |
| 7487 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7488 | } |
| 7489 | |
| 7490 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7491 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7492 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7493 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7494 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7495 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7496 | final long identity = Binder.clearCallingIdentity(); |
| 7497 | try { |
| 7498 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7499 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | if (componentName == null) { |
| 7501 | throw new SecurityException( |
| 7502 | "Caller not current active visual voicemail package[null]"); |
| 7503 | } |
| 7504 | String vvmPackage = componentName.getPackageName(); |
| 7505 | if (!callingPackage.equals(vvmPackage)) { |
| 7506 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7507 | + vvmPackage + "]"); |
| 7508 | } |
| 7509 | } finally { |
| 7510 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7515 | * Return the application ID for the app type. |
| 7516 | * |
| 7517 | * @param subId the subscription ID that this request applies to. |
| 7518 | * @param appType the uicc app type. |
| 7519 | * @return Application ID for specificied app type, or null if no uicc. |
| 7520 | */ |
| 7521 | @Override |
| 7522 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7523 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7524 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | |
| 7526 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7527 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | if (phone == null) { |
| 7529 | return null; |
| 7530 | } |
| 7531 | String aid = null; |
| 7532 | try { |
| 7533 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7534 | .getApplicationByType(appType).getAid(); |
| 7535 | } catch (Exception e) { |
| 7536 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7537 | } |
| 7538 | return aid; |
| 7539 | } finally { |
| 7540 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7541 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7542 | } |
| 7543 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7544 | /** |
| 7545 | * Return the Electronic Serial Number. |
| 7546 | * |
| 7547 | * @param subId the subscription ID that this request applies to. |
| 7548 | * @return ESN or null if error. |
| 7549 | */ |
| 7550 | @Override |
| 7551 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7552 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7553 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | |
| 7555 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7556 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | if (phone == null) { |
| 7558 | return null; |
| 7559 | } |
| 7560 | String esn = null; |
| 7561 | try { |
| 7562 | esn = phone.getEsn(); |
| 7563 | } catch (Exception e) { |
| 7564 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7565 | } |
| 7566 | return esn; |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7569 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7570 | } |
| 7571 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7572 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7573 | * Return the Preferred Roaming List Version. |
| 7574 | * |
| 7575 | * @param subId the subscription ID that this request applies to. |
| 7576 | * @return PRLVersion or null if error. |
| 7577 | */ |
| 7578 | @Override |
| 7579 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7580 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7581 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7582 | |
| 7583 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7584 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | if (phone == null) { |
| 7586 | return null; |
| 7587 | } |
| 7588 | String cdmaPrlVersion = null; |
| 7589 | try { |
| 7590 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7591 | } catch (Exception e) { |
| 7592 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7593 | } |
| 7594 | return cdmaPrlVersion; |
| 7595 | } finally { |
| 7596 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7597 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7601 | * Get snapshot of Telephony histograms |
| 7602 | * @return List of Telephony histograms |
| 7603 | * @hide |
| 7604 | */ |
| 7605 | @Override |
| 7606 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7608 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7609 | |
| 7610 | final long identity = Binder.clearCallingIdentity(); |
| 7611 | try { |
| 7612 | return RIL.getTelephonyRILTimingHistograms(); |
| 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7616 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7617 | |
| 7618 | /** |
| 7619 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7620 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7621 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7622 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7623 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7624 | * @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] | 7625 | */ |
| 7626 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7627 | @TelephonyManager.SetCarrierRestrictionResult |
| 7628 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7629 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7630 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7631 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7632 | if (carrierRestrictionRules == null) { |
| 7633 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7634 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7636 | final long identity = Binder.clearCallingIdentity(); |
| 7637 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7638 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7639 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7640 | } finally { |
| 7641 | Binder.restoreCallingIdentity(identity); |
| 7642 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7643 | } |
| 7644 | |
| 7645 | /** |
| 7646 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7647 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7648 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7649 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7650 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7651 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7652 | */ |
| 7653 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7654 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7655 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7656 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | |
| 7658 | final long identity = Binder.clearCallingIdentity(); |
| 7659 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7660 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7661 | if (response instanceof CarrierRestrictionRules) { |
| 7662 | return (CarrierRestrictionRules) response; |
| 7663 | } |
| 7664 | // Response is an Exception of some kind, |
| 7665 | // which is signalled to the user as a NULL retval |
| 7666 | return null; |
| 7667 | } catch (Exception e) { |
| 7668 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7669 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | } finally { |
| 7671 | Binder.restoreCallingIdentity(identity); |
| 7672 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7673 | } |
| 7674 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7675 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7676 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7677 | * @param subId the subscription ID that this action applies to. |
| 7678 | * @param enabled control enable or disable radio. |
| 7679 | * {@hide} |
| 7680 | */ |
| 7681 | @Override |
| 7682 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7683 | enforceModifyPermission(); |
| 7684 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7685 | |
| 7686 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7687 | if (phone == null) { |
| 7688 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7689 | return; |
| 7690 | } |
| 7691 | try { |
| 7692 | phone.carrierActionSetRadioEnabled(enabled); |
| 7693 | } catch (Exception e) { |
| 7694 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7697 | } |
| 7698 | } |
| 7699 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7700 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7701 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7702 | * network status based on which carrier apps could apply actions accordingly, |
| 7703 | * enable/disable default url handler for example. |
| 7704 | * |
| 7705 | * @param subId the subscription ID that this action applies to. |
| 7706 | * @param report control start/stop reporting the default network status. |
| 7707 | * {@hide} |
| 7708 | */ |
| 7709 | @Override |
| 7710 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7711 | enforceModifyPermission(); |
| 7712 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7713 | |
| 7714 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7715 | if (phone == null) { |
| 7716 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7717 | return; |
| 7718 | } |
| 7719 | try { |
| 7720 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7721 | } catch (Exception e) { |
| 7722 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7725 | } |
| 7726 | } |
| 7727 | |
| 7728 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7729 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7730 | * @param subId the subscription ID that this action applies to. |
| 7731 | * {@hide} |
| 7732 | */ |
| 7733 | @Override |
| 7734 | public void carrierActionResetAll(int subId) { |
| 7735 | enforceModifyPermission(); |
| 7736 | final Phone phone = getPhone(subId); |
| 7737 | if (phone == null) { |
| 7738 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7739 | return; |
| 7740 | } |
| 7741 | try { |
| 7742 | phone.carrierActionResetAll(); |
| 7743 | } catch (Exception e) { |
| 7744 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7745 | } |
| 7746 | } |
| 7747 | |
| 7748 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7749 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7750 | * bug report is being generated. |
| 7751 | */ |
| 7752 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7753 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7754 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7755 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7756 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7757 | + Binder.getCallingPid() |
| 7758 | + ", uid=" + Binder.getCallingUid() |
| 7759 | + "without permission " |
| 7760 | + android.Manifest.permission.DUMP); |
| 7761 | return; |
| 7762 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7763 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7764 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7765 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7766 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7767 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7768 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7769 | @NonNull String[] args) { |
| 7770 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7771 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7772 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7775 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7776 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7777 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7778 | * @param reason the reason the data enable change is taking place |
| 7779 | * @param enabled True if enabling the data, otherwise disabling. |
| 7780 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7781 | */ |
| 7782 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7783 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7784 | boolean enabled) { |
| 7785 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7786 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7787 | try { |
| 7788 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7789 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7790 | } catch (SecurityException se) { |
| 7791 | enforceModifyPermission(); |
| 7792 | } |
| 7793 | } else { |
| 7794 | enforceModifyPermission(); |
| 7795 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | |
| 7797 | final long identity = Binder.clearCallingIdentity(); |
| 7798 | try { |
| 7799 | Phone phone = getPhone(subId); |
| 7800 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7801 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7802 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7803 | } else { |
| 7804 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7806 | } |
| 7807 | } finally { |
| 7808 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7809 | } |
| 7810 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7811 | |
| 7812 | /** |
| 7813 | * Get Client request stats |
| 7814 | * @return List of Client Request Stats |
| 7815 | * @hide |
| 7816 | */ |
| 7817 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7818 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7819 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7820 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7821 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7822 | return null; |
| 7823 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7824 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
| 7828 | if (phone != null) { |
| 7829 | return phone.getClientRequestStats(); |
| 7830 | } |
| 7831 | |
| 7832 | return null; |
| 7833 | } finally { |
| 7834 | Binder.restoreCallingIdentity(identity); |
| 7835 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7836 | } |
| 7837 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7838 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7839 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7840 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7841 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7842 | |
| 7843 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7844 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7845 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7846 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7847 | * @param state State of SIM (power down, power up, pass through) |
| 7848 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7849 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7850 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7851 | * |
| 7852 | **/ |
| 7853 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7854 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7855 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7856 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7857 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7858 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7859 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7860 | final long identity = Binder.clearCallingIdentity(); |
| 7861 | try { |
| 7862 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7863 | phone.setSimPowerState(state, null, workSource); |
| 7864 | } |
| 7865 | } finally { |
| 7866 | Binder.restoreCallingIdentity(identity); |
| 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | /** |
| 7871 | * Set SIM card power state. |
| 7872 | * |
| 7873 | * @param slotIndex SIM slot id. |
| 7874 | * @param state State of SIM (power down, power up, pass through) |
| 7875 | * @param callback callback to trigger after success or failure |
| 7876 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7877 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7878 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7879 | * |
| 7880 | **/ |
| 7881 | @Override |
| 7882 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7883 | IIntegerConsumer callback) { |
| 7884 | enforceModifyPermission(); |
| 7885 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7886 | |
| 7887 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7888 | |
| 7889 | final long identity = Binder.clearCallingIdentity(); |
| 7890 | try { |
| 7891 | if (phone != null) { |
| 7892 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7893 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7894 | } |
| 7895 | } finally { |
| 7896 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7897 | } |
| 7898 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7899 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7900 | private boolean isUssdApiAllowed(int subId) { |
| 7901 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7902 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7903 | if (configManager == null) { |
| 7904 | return false; |
| 7905 | } |
| 7906 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7907 | if (pb == null) { |
| 7908 | return false; |
| 7909 | } |
| 7910 | return pb.getBoolean( |
| 7911 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7912 | } |
| 7913 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7914 | /** |
| 7915 | * Check if phone is in emergency callback mode |
| 7916 | * @return true if phone is in emergency callback mode |
| 7917 | * @param subId sub id |
| 7918 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7919 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7920 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7921 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7922 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7923 | |
| 7924 | final long identity = Binder.clearCallingIdentity(); |
| 7925 | try { |
| 7926 | if (phone != null) { |
| 7927 | return phone.isInEcm(); |
| 7928 | } else { |
| 7929 | return false; |
| 7930 | } |
| 7931 | } finally { |
| 7932 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7933 | } |
| 7934 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7935 | |
| 7936 | /** |
| 7937 | * Get the current signal strength information for the given subscription. |
| 7938 | * Because this information is not updated when the device is in a low power state |
| 7939 | * it should not be relied-upon to be current. |
| 7940 | * @param subId Subscription index |
| 7941 | * @return the most recent cached signal strength info from the modem |
| 7942 | */ |
| 7943 | @Override |
| 7944 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7945 | final long identity = Binder.clearCallingIdentity(); |
| 7946 | try { |
| 7947 | Phone p = getPhone(subId); |
| 7948 | if (p == null) { |
| 7949 | return null; |
| 7950 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | return p.getSignalStrength(); |
| 7953 | } finally { |
| 7954 | Binder.restoreCallingIdentity(identity); |
| 7955 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7956 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7957 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7958 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7959 | * Get the current modem radio state for the given slot. |
| 7960 | * @param slotIndex slot index. |
| 7961 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7962 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7963 | * @return the current radio power state from the modem |
| 7964 | */ |
| 7965 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7966 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7967 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7968 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7970 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7971 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7972 | } |
| 7973 | |
| 7974 | final long identity = Binder.clearCallingIdentity(); |
| 7975 | try { |
| 7976 | return phone.getRadioPowerState(); |
| 7977 | } finally { |
| 7978 | Binder.restoreCallingIdentity(identity); |
| 7979 | } |
| 7980 | } |
| 7981 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7982 | } |
| 7983 | |
| 7984 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7985 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7986 | * |
| 7987 | * <p>Requires one of the following permissions: |
| 7988 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7989 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7990 | * privileges. |
| 7991 | * |
| 7992 | * @param subId subscription id |
| 7993 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7994 | * {@code false}. |
| 7995 | */ |
| 7996 | @Override |
| 7997 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7998 | try { |
| 7999 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8000 | null); |
| 8001 | } catch (Exception e) { |
| 8002 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8003 | mApp, subId, "isDataRoamingEnabled"); |
| 8004 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8005 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8006 | boolean isEnabled = false; |
| 8007 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8008 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8009 | Phone phone = getPhone(subId); |
| 8010 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8011 | } finally { |
| 8012 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8013 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8014 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8015 | } |
| 8016 | |
| 8017 | |
| 8018 | /** |
| 8019 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8020 | * |
| 8021 | * <p> Requires permission: |
| 8022 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8023 | * privileges. |
| 8024 | * |
| 8025 | * @param subId subscription id |
| 8026 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8027 | */ |
| 8028 | @Override |
| 8029 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8031 | mApp, subId, "setDataRoamingEnabled"); |
| 8032 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8033 | final long identity = Binder.clearCallingIdentity(); |
| 8034 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8035 | Phone phone = getPhone(subId); |
| 8036 | if (phone != null) { |
| 8037 | phone.setDataRoamingEnabled(isEnabled); |
| 8038 | } |
| 8039 | } finally { |
| 8040 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8041 | } |
| 8042 | } |
| 8043 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8044 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8045 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8046 | TelephonyPermissions |
| 8047 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8048 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8049 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8050 | boolean isAllowed = true; |
| 8051 | final long identity = Binder.clearCallingIdentity(); |
| 8052 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8053 | Phone phone = getPhone(subId); |
| 8054 | if (phone != null) { |
| 8055 | isAllowed = phone.isCspPlmnEnabled(); |
| 8056 | } |
| 8057 | } finally { |
| 8058 | Binder.restoreCallingIdentity(identity); |
| 8059 | } |
| 8060 | return isAllowed; |
| 8061 | } |
| 8062 | |
| 8063 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8064 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8065 | // Verify that tha callingPackage belongs to the calling UID |
| 8066 | mApp.getSystemService(AppOpsManager.class) |
| 8067 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8068 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8069 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8070 | try { |
| 8071 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8072 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8073 | } catch (SecurityException e) { |
| 8074 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8075 | // has carrier privileges on an active UICC |
| 8076 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8077 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8078 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8079 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8080 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8081 | |
| 8082 | final long identity = Binder.clearCallingIdentity(); |
| 8083 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8084 | UiccController uiccController = UiccController.getInstance(); |
| 8085 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8086 | if (hasReadPermission) { |
| 8087 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8088 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8089 | |
| 8090 | // Remove private info if the caller doesn't have access |
| 8091 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8092 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8093 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8094 | // is available |
| 8095 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8096 | if (card == null || card.getUiccProfile() == null) { |
| 8097 | // assume no access if the card or profile is unavailable |
| 8098 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8099 | continue; |
| 8100 | } |
| 8101 | UiccProfile profile = card.getUiccProfile(); |
| 8102 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8103 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8104 | filteredInfos.add(cardInfo); |
| 8105 | } else { |
| 8106 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8107 | } |
| 8108 | } |
| 8109 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8110 | } finally { |
| 8111 | Binder.restoreCallingIdentity(identity); |
| 8112 | } |
| 8113 | } |
| 8114 | |
| 8115 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8116 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8117 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8118 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8119 | final long identity = Binder.clearCallingIdentity(); |
| 8120 | try { |
| 8121 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8122 | if (slots == null) { |
| 8123 | Rlog.i(LOG_TAG, "slots is null."); |
| 8124 | return null; |
| 8125 | } |
| 8126 | |
| 8127 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8128 | for (int i = 0; i < slots.length; i++) { |
| 8129 | UiccSlot slot = slots[i]; |
| 8130 | if (slot == null) { |
| 8131 | continue; |
| 8132 | } |
| 8133 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8134 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | UiccCard card = slot.getUiccCard(); |
| 8136 | if (card != null) { |
| 8137 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8138 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8139 | cardId = slot.getEid(); |
| 8140 | if (TextUtils.isEmpty(cardId)) { |
| 8141 | cardId = slot.getIccId(); |
| 8142 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | } |
| 8144 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8145 | if (cardId != null) { |
| 8146 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8147 | // if cardId is an EID, it's all digits so this is fine |
| 8148 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8149 | } |
| 8150 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8151 | int cardState = 0; |
| 8152 | switch (slot.getCardState()) { |
| 8153 | case CARDSTATE_ABSENT: |
| 8154 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8155 | break; |
| 8156 | case CARDSTATE_PRESENT: |
| 8157 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8158 | break; |
| 8159 | case CARDSTATE_ERROR: |
| 8160 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8161 | break; |
| 8162 | case CARDSTATE_RESTRICTED: |
| 8163 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8164 | break; |
| 8165 | default: |
| 8166 | break; |
| 8167 | |
| 8168 | } |
| 8169 | |
| 8170 | infos[i] = new UiccSlotInfo( |
| 8171 | slot.isActive(), |
| 8172 | slot.isEuicc(), |
| 8173 | cardId, |
| 8174 | cardState, |
| 8175 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8176 | slot.isExtendedApduSupported(), |
| 8177 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8178 | } |
| 8179 | return infos; |
| 8180 | } finally { |
| 8181 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8182 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8183 | } |
| 8184 | |
| 8185 | @Override |
| 8186 | public boolean switchSlots(int[] physicalSlots) { |
| 8187 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8188 | |
| 8189 | final long identity = Binder.clearCallingIdentity(); |
| 8190 | try { |
| 8191 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8192 | } finally { |
| 8193 | Binder.restoreCallingIdentity(identity); |
| 8194 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8195 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8196 | |
| 8197 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8198 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8199 | final long identity = Binder.clearCallingIdentity(); |
| 8200 | try { |
| 8201 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
| 8204 | } |
| 8205 | } |
| 8206 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8207 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8208 | * A test API to reload the UICC profile. |
| 8209 | * |
| 8210 | * <p>Requires that the calling app has permission |
| 8211 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8212 | * @hide |
| 8213 | */ |
| 8214 | @Override |
| 8215 | public void refreshUiccProfile(int subId) { |
| 8216 | enforceModifyPermission(); |
| 8217 | |
| 8218 | final long identity = Binder.clearCallingIdentity(); |
| 8219 | try { |
| 8220 | Phone phone = getPhone(subId); |
| 8221 | if (phone == null) { |
| 8222 | return; |
| 8223 | } |
| 8224 | UiccCard uiccCard = phone.getUiccCard(); |
| 8225 | if (uiccCard == null) { |
| 8226 | return; |
| 8227 | } |
| 8228 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8229 | if (uiccProfile == null) { |
| 8230 | return; |
| 8231 | } |
| 8232 | uiccProfile.refresh(); |
| 8233 | } finally { |
| 8234 | Binder.restoreCallingIdentity(identity); |
| 8235 | } |
| 8236 | } |
| 8237 | |
| 8238 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8239 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8240 | */ |
| 8241 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8242 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8243 | } |
| 8244 | |
| 8245 | /** |
| 8246 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8247 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8248 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8249 | */ |
| 8250 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8251 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8252 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8253 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8254 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8255 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8256 | return isDataRoamingEnabled; |
| 8257 | } |
| 8258 | |
| 8259 | /** |
| 8260 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8261 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8262 | */ |
| 8263 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8264 | List<Integer> list = TelephonyProperties.default_network(); |
| 8265 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8266 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8267 | return list.get(phoneId); |
| 8268 | } |
| 8269 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8270 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8271 | |
| 8272 | @Override |
| 8273 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8274 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8275 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | |
| 8277 | final long identity = Binder.clearCallingIdentity(); |
| 8278 | try { |
| 8279 | final Phone phone = getPhone(subId); |
| 8280 | if (phone == null) { |
| 8281 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8282 | return; |
| 8283 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8284 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8285 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8286 | if (carrierPrivilegeRules == null) { |
| 8287 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8288 | } else { |
| 8289 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | } finally { |
| 8292 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8293 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | @Override |
| 8297 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8298 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | |
| 8300 | final long identity = Binder.clearCallingIdentity(); |
| 8301 | try { |
| 8302 | final Phone phone = getPhone(subId); |
| 8303 | if (phone == null) { |
| 8304 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8305 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8306 | } |
| 8307 | return phone.getCarrierIdListVersion(); |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8310 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8311 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8312 | |
| 8313 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8314 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8315 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8316 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8317 | mApp, subId, callingPackage, callingFeatureId, |
| 8318 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8319 | return -1; |
| 8320 | } |
| 8321 | |
| 8322 | final long identity = Binder.clearCallingIdentity(); |
| 8323 | try { |
| 8324 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8325 | } finally { |
| 8326 | Binder.restoreCallingIdentity(identity); |
| 8327 | } |
| 8328 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8329 | |
| 8330 | @Override |
| 8331 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8332 | TelephonyPermissions |
| 8333 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8334 | mApp, subId, "getCdmaRoamingMode"); |
| 8335 | |
| 8336 | final long identity = Binder.clearCallingIdentity(); |
| 8337 | try { |
| 8338 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8339 | } finally { |
| 8340 | Binder.restoreCallingIdentity(identity); |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | @Override |
| 8345 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8347 | mApp, subId, "setCdmaRoamingMode"); |
| 8348 | |
| 8349 | final long identity = Binder.clearCallingIdentity(); |
| 8350 | try { |
| 8351 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8352 | } finally { |
| 8353 | Binder.restoreCallingIdentity(identity); |
| 8354 | } |
| 8355 | } |
| 8356 | |
| 8357 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8358 | public int getCdmaSubscriptionMode(int subId) { |
| 8359 | TelephonyPermissions |
| 8360 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8361 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8362 | |
| 8363 | final long identity = Binder.clearCallingIdentity(); |
| 8364 | try { |
| 8365 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8366 | } finally { |
| 8367 | Binder.restoreCallingIdentity(identity); |
| 8368 | } |
| 8369 | } |
| 8370 | |
| 8371 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8372 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8373 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8374 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8375 | |
| 8376 | final long identity = Binder.clearCallingIdentity(); |
| 8377 | try { |
| 8378 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8379 | } finally { |
| 8380 | Binder.restoreCallingIdentity(identity); |
| 8381 | } |
| 8382 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8383 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8384 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8385 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8386 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8388 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8389 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8390 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8391 | } |
| 8392 | final long identity = Binder.clearCallingIdentity(); |
| 8393 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8394 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8395 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8396 | if (phone.getEmergencyNumberTracker() != null |
| 8397 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8398 | emergencyNumberListInternal.put( |
| 8399 | phone.getSubId(), |
| 8400 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8401 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8402 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8403 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8404 | } finally { |
| 8405 | Binder.restoreCallingIdentity(identity); |
| 8406 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8407 | } |
| 8408 | |
| 8409 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8410 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8411 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8412 | if (!exactMatch) { |
| 8413 | TelephonyPermissions |
| 8414 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8415 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8416 | } |
| 8417 | final long identity = Binder.clearCallingIdentity(); |
| 8418 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8419 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8420 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8421 | && phone.getEmergencyNumberTracker() |
| 8422 | .isEmergencyNumber(number, exactMatch)) { |
| 8423 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8424 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8425 | } |
| 8426 | return false; |
| 8427 | } finally { |
| 8428 | Binder.restoreCallingIdentity(identity); |
| 8429 | } |
| 8430 | } |
| 8431 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8432 | /** |
| 8433 | * Update emergency number list for test mode. |
| 8434 | */ |
| 8435 | @Override |
| 8436 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8437 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8438 | "updateEmergencyNumberListTestMode"); |
| 8439 | |
| 8440 | final long identity = Binder.clearCallingIdentity(); |
| 8441 | try { |
| 8442 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8443 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8444 | if (tracker != null) { |
| 8445 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8446 | } |
| 8447 | } |
| 8448 | } finally { |
| 8449 | Binder.restoreCallingIdentity(identity); |
| 8450 | } |
| 8451 | } |
| 8452 | |
| 8453 | /** |
| 8454 | * Get the full emergency number list for test mode. |
| 8455 | */ |
| 8456 | @Override |
| 8457 | public List<String> getEmergencyNumberListTestMode() { |
| 8458 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8459 | "getEmergencyNumberListTestMode"); |
| 8460 | |
| 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8464 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8465 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8466 | if (tracker != null) { |
| 8467 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8468 | emergencyNumbers.add(num.getNumber()); |
| 8469 | } |
| 8470 | } |
| 8471 | } |
| 8472 | return new ArrayList<>(emergencyNumbers); |
| 8473 | } finally { |
| 8474 | Binder.restoreCallingIdentity(identity); |
| 8475 | } |
| 8476 | } |
| 8477 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8478 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8479 | public int getEmergencyNumberDbVersion(int subId) { |
| 8480 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8481 | |
| 8482 | final long identity = Binder.clearCallingIdentity(); |
| 8483 | try { |
| 8484 | final Phone phone = getPhone(subId); |
| 8485 | if (phone == null) { |
| 8486 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8487 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8488 | } |
| 8489 | return phone.getEmergencyNumberDbVersion(); |
| 8490 | } finally { |
| 8491 | Binder.restoreCallingIdentity(identity); |
| 8492 | } |
| 8493 | } |
| 8494 | |
| 8495 | @Override |
| 8496 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8497 | enforceModifyPermission(); |
| 8498 | |
| 8499 | final long identity = Binder.clearCallingIdentity(); |
| 8500 | try { |
| 8501 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8502 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8503 | if (tracker != null) { |
| 8504 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8505 | } |
| 8506 | } |
| 8507 | } finally { |
| 8508 | Binder.restoreCallingIdentity(identity); |
| 8509 | } |
| 8510 | } |
| 8511 | |
| 8512 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8513 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8514 | enforceActiveEmergencySessionPermission(); |
| 8515 | |
| 8516 | final long identity = Binder.clearCallingIdentity(); |
| 8517 | try { |
| 8518 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8519 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8520 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8521 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8522 | } |
| 8523 | } |
| 8524 | } finally { |
| 8525 | Binder.restoreCallingIdentity(identity); |
| 8526 | } |
| 8527 | } |
| 8528 | |
| 8529 | @Override |
| 8530 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8531 | enforceActiveEmergencySessionPermission(); |
| 8532 | |
| 8533 | final long identity = Binder.clearCallingIdentity(); |
| 8534 | try { |
| 8535 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8536 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8537 | if (tracker != null) { |
| 8538 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8539 | } |
| 8540 | } |
| 8541 | } finally { |
| 8542 | Binder.restoreCallingIdentity(identity); |
| 8543 | } |
| 8544 | } |
| 8545 | |
| 8546 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8547 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8548 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8549 | Phone phone = getPhone(subId); |
| 8550 | if (phone == null) { |
| 8551 | return null; |
| 8552 | } |
| 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
| 8555 | UiccProfile profile = UiccController.getInstance() |
| 8556 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8557 | if (profile != null) { |
| 8558 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8559 | } |
| 8560 | } finally { |
| 8561 | Binder.restoreCallingIdentity(identity); |
| 8562 | } |
| 8563 | return null; |
| 8564 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8565 | |
| 8566 | /** |
| 8567 | * Enable or disable a modem stack. |
| 8568 | */ |
| 8569 | @Override |
| 8570 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8571 | enforceModifyPermission(); |
| 8572 | |
| 8573 | final long identity = Binder.clearCallingIdentity(); |
| 8574 | try { |
| 8575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8576 | if (phone == null) { |
| 8577 | return false; |
| 8578 | } else { |
| 8579 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8580 | } |
| 8581 | } finally { |
| 8582 | Binder.restoreCallingIdentity(identity); |
| 8583 | } |
| 8584 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8585 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8586 | /** |
| 8587 | * Whether a modem stack is enabled or not. |
| 8588 | */ |
| 8589 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8590 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8591 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8592 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8593 | if (phone == null) return false; |
| 8594 | |
| 8595 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8596 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8597 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8598 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8599 | } |
| 8600 | |
| 8601 | final long identity = Binder.clearCallingIdentity(); |
| 8602 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8603 | try { |
| 8604 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8605 | } catch (NoSuchElementException ex) { |
| 8606 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8607 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
| 8610 | } |
| 8611 | } |
| 8612 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8613 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8614 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8615 | enforceModifyPermission(); |
| 8616 | |
| 8617 | final long identity = Binder.clearCallingIdentity(); |
| 8618 | try { |
| 8619 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8620 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8621 | .commit(); |
| 8622 | } finally { |
| 8623 | Binder.restoreCallingIdentity(identity); |
| 8624 | } |
| 8625 | } |
| 8626 | |
| 8627 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8628 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8629 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8631 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8632 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8633 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8634 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8635 | |
| 8636 | final long identity = Binder.clearCallingIdentity(); |
| 8637 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8638 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
| 8641 | } |
| 8642 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8643 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8644 | @TelephonyManager.IsMultiSimSupportedResult |
| 8645 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8646 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8647 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8648 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8649 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8650 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8651 | } |
| 8652 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8653 | // supported by the modem, indicate that it is restricted. |
| 8654 | PhoneCapability staticCapability = |
| 8655 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8656 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8657 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8658 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8659 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8660 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8661 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8662 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8663 | } |
| 8664 | // Check if support of multiple SIMs is restricted by carrier |
| 8665 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8666 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8667 | } |
| 8668 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8669 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8670 | } |
| 8671 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8672 | /** |
| 8673 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8674 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8675 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8676 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8677 | * @param numOfSims number of active sims we want to switch to |
| 8678 | */ |
| 8679 | @Override |
| 8680 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8681 | if (numOfSims == 1) { |
| 8682 | enforceModifyPermission(); |
| 8683 | } else { |
| 8684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8685 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8686 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8687 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8688 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8689 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8690 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8691 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8692 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8693 | return; |
| 8694 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8695 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8696 | } finally { |
| 8697 | Binder.restoreCallingIdentity(identity); |
| 8698 | } |
| 8699 | } |
| 8700 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8701 | @Override |
| 8702 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8703 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8704 | Phone phone = getPhone(subId); |
| 8705 | if (phone == null) { |
| 8706 | return false; |
| 8707 | } |
| 8708 | final long identity = Binder.clearCallingIdentity(); |
| 8709 | try { |
| 8710 | UiccCard uiccCard = phone.getUiccCard(); |
| 8711 | if (uiccCard == null) { |
| 8712 | return false; |
| 8713 | } |
| 8714 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8715 | if (uiccProfile == null) { |
| 8716 | return false; |
| 8717 | } |
| 8718 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8719 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8720 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8721 | } |
| 8722 | return false; |
| 8723 | } finally { |
| 8724 | Binder.restoreCallingIdentity(identity); |
| 8725 | } |
| 8726 | } |
| 8727 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8728 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8729 | * Get whether making changes to modem configurations will trigger reboot. |
| 8730 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8731 | */ |
| 8732 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8733 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8734 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8735 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8736 | mApp, subId, callingPackage, callingFeatureId, |
| 8737 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8738 | return false; |
| 8739 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8740 | final long identity = Binder.clearCallingIdentity(); |
| 8741 | try { |
| 8742 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(identity); |
| 8745 | } |
| 8746 | } |
| 8747 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8748 | private void updateModemStateMetrics() { |
| 8749 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8750 | // TODO: check the state for each modem if the api is ready. |
| 8751 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8752 | } |
| 8753 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8754 | @Override |
| 8755 | public int[] getSlotsMapping() { |
| 8756 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8757 | |
| 8758 | final long identity = Binder.clearCallingIdentity(); |
| 8759 | try { |
| 8760 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8761 | // All logical slots should have a mapping to a physical slot. |
| 8762 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8763 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8764 | for (int i = 0; i < slotInfos.length; i++) { |
| 8765 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8766 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8767 | } |
| 8768 | } |
| 8769 | return logicalSlotsMapping; |
| 8770 | } finally { |
| 8771 | Binder.restoreCallingIdentity(identity); |
| 8772 | } |
| 8773 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8774 | |
| 8775 | /** |
| 8776 | * Get the IRadio HAL Version |
| 8777 | */ |
| 8778 | @Override |
| 8779 | public int getRadioHalVersion() { |
| 8780 | Phone phone = getDefaultPhone(); |
| 8781 | if (phone == null) return -1; |
| 8782 | HalVersion hv = phone.getHalVersion(); |
| 8783 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8784 | return hv.major * 100 + hv.minor; |
| 8785 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8786 | |
| 8787 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8788 | * Get the current calling package name. |
| 8789 | * @return the current calling package name |
| 8790 | */ |
| 8791 | @Override |
| 8792 | public String getCurrentPackageName() { |
| 8793 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8794 | } |
| 8795 | |
| 8796 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8797 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8798 | * corresponding network requests on a subId. |
| 8799 | * |
| 8800 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8801 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8802 | * 2) APN is un-metered for this subscription, or |
| 8803 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8804 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8805 | * |
| 8806 | * @return whether data is allowed for a apn type. |
| 8807 | * |
| 8808 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8809 | */ |
| 8810 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8811 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8812 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8813 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8814 | |
| 8815 | // Now that all security checks passes, perform the operation as ourselves. |
| 8816 | final long identity = Binder.clearCallingIdentity(); |
| 8817 | try { |
| 8818 | Phone phone = getPhone(subId); |
| 8819 | if (phone == null) return false; |
| 8820 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8821 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8822 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8823 | } finally { |
| 8824 | Binder.restoreCallingIdentity(identity); |
| 8825 | } |
| 8826 | } |
| 8827 | |
| 8828 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8829 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8830 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8831 | |
| 8832 | // Now that all security checks passes, perform the operation as ourselves. |
| 8833 | final long identity = Binder.clearCallingIdentity(); |
| 8834 | try { |
| 8835 | Phone phone = getPhone(subId); |
| 8836 | if (phone == null) return true; // By default return true. |
| 8837 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8838 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8839 | } finally { |
| 8840 | Binder.restoreCallingIdentity(identity); |
| 8841 | } |
| 8842 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8843 | |
| 8844 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8845 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8846 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8847 | enforceModifyPermission(); |
| 8848 | long token = Binder.clearCallingIdentity(); |
| 8849 | try { |
| 8850 | Phone phone = getPhone(subscriptionId); |
| 8851 | if (phone == null) { |
| 8852 | try { |
| 8853 | if (resultCallback != null) { |
| 8854 | resultCallback.accept(false); |
| 8855 | } |
| 8856 | } catch (RemoteException e) { |
| 8857 | // ignore |
| 8858 | } |
| 8859 | return; |
| 8860 | } |
| 8861 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8862 | Pair.create(specifiers, (x) -> { |
| 8863 | try { |
| 8864 | if (resultCallback != null) { |
| 8865 | resultCallback.accept(x); |
| 8866 | } |
| 8867 | } catch (RemoteException e) { |
| 8868 | // ignore |
| 8869 | } |
| 8870 | }); |
| 8871 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8872 | } finally { |
| 8873 | Binder.restoreCallingIdentity(token); |
| 8874 | } |
| 8875 | } |
| 8876 | |
| 8877 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8878 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8879 | TelephonyPermissions |
| 8880 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8881 | mApp, subId, "getSystemSelectionChannels"); |
| 8882 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8883 | final long identity = Binder.clearCallingIdentity(); |
| 8884 | try { |
| 8885 | List<RadioAccessSpecifier> specifiers = |
| 8886 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8887 | null, subId, workSource); |
| 8888 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8889 | return specifiers; |
| 8890 | } finally { |
| 8891 | Binder.restoreCallingIdentity(identity); |
| 8892 | } |
| 8893 | } |
| 8894 | |
| 8895 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8896 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8897 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8898 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8899 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8900 | if (iccRecords == null) { |
| 8901 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8902 | return false; |
| 8903 | } |
| 8904 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8905 | } |
| 8906 | |
| 8907 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8908 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8909 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8910 | if (callingPackage == null) { |
| 8911 | callingPackage = getCurrentPackageName(); |
| 8912 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8913 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8914 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8915 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8916 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8917 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8918 | } |
| 8919 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8920 | Intent intent = new Intent(); |
| 8921 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8922 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8923 | // Bring up choose default SMS subscription dialog right now |
| 8924 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8925 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8926 | mApp.startActivity(intent); |
| 8927 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8928 | |
| 8929 | @Override |
| 8930 | public String getMmsUAProfUrl(int subId) { |
| 8931 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8932 | final long identity = Binder.clearCallingIdentity(); |
| 8933 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8934 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8935 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8936 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8937 | return carrierUAProfUrl; |
| 8938 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8939 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8940 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8941 | } finally { |
| 8942 | Binder.restoreCallingIdentity(identity); |
| 8943 | } |
| 8944 | } |
| 8945 | |
| 8946 | @Override |
| 8947 | public String getMmsUserAgent(int subId) { |
| 8948 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8949 | final long identity = Binder.clearCallingIdentity(); |
| 8950 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8951 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8952 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8953 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8954 | return carrierUserAgent; |
| 8955 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8956 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8957 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8958 | } finally { |
| 8959 | Binder.restoreCallingIdentity(identity); |
| 8960 | } |
| 8961 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8962 | |
| 8963 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8964 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8965 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8966 | |
| 8967 | final long identity = Binder.clearCallingIdentity(); |
| 8968 | try { |
| 8969 | Phone phone = getPhone(subscriptionId); |
| 8970 | if (phone == null) return false; |
| 8971 | |
| 8972 | switch (policy) { |
| 8973 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8974 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8975 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8976 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8977 | default: |
| 8978 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8979 | } |
| 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | @Override |
| 8986 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8987 | boolean enabled) { |
| 8988 | enforceModifyPermission(); |
| 8989 | |
| 8990 | final long identity = Binder.clearCallingIdentity(); |
| 8991 | try { |
| 8992 | Phone phone = getPhone(subscriptionId); |
| 8993 | if (phone == null) return; |
| 8994 | |
| 8995 | switch (policy) { |
| 8996 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8997 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8998 | break; |
| 8999 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9000 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9001 | break; |
| 9002 | default: |
| 9003 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9004 | } |
| 9005 | } finally { |
| 9006 | Binder.restoreCallingIdentity(identity); |
| 9007 | } |
| 9008 | } |
| 9009 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9010 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9011 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9012 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9013 | * otherwise. |
| 9014 | */ |
| 9015 | @Override |
| 9016 | public void setCepEnabled(boolean isCepEnabled) { |
| 9017 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9018 | |
| 9019 | final long identity = Binder.clearCallingIdentity(); |
| 9020 | try { |
| 9021 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9022 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9023 | Phone defaultPhone = phone.getImsPhone(); |
| 9024 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9025 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9026 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9027 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9028 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9029 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9030 | + imsPhone.getMsisdn()); |
| 9031 | } |
| 9032 | } |
| 9033 | } finally { |
| 9034 | Binder.restoreCallingIdentity(identity); |
| 9035 | } |
| 9036 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9037 | |
| 9038 | /** |
| 9039 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9040 | * |
| 9041 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9042 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9043 | * before being read. |
| 9044 | */ |
| 9045 | @Override |
| 9046 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9047 | isCompressed) { |
| 9048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9049 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9050 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9051 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9052 | } |
| 9053 | if (!isImsAvailableOnDevice()) { |
| 9054 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9055 | "IMS not available on device."); |
| 9056 | } |
| 9057 | |
| 9058 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9059 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9060 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9061 | } finally { |
| 9062 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9063 | } |
| 9064 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9065 | |
| 9066 | @Override |
| 9067 | public boolean isIccLockEnabled(int subId) { |
| 9068 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9069 | |
| 9070 | // Now that all security checks passes, perform the operation as ourselves. |
| 9071 | final long identity = Binder.clearCallingIdentity(); |
| 9072 | try { |
| 9073 | Phone phone = getPhone(subId); |
| 9074 | if (phone != null && phone.getIccCard() != null) { |
| 9075 | return phone.getIccCard().getIccLockEnabled(); |
| 9076 | } else { |
| 9077 | return false; |
| 9078 | } |
| 9079 | } finally { |
| 9080 | Binder.restoreCallingIdentity(identity); |
| 9081 | } |
| 9082 | } |
| 9083 | |
| 9084 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9085 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9086 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9087 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9088 | * three cases: |
| 9089 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9090 | * successfully. |
| 9091 | * - Positive number and zero for remaining password attempts. |
| 9092 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9093 | * |
| 9094 | */ |
| 9095 | @Override |
| 9096 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9097 | enforceModifyPermission(); |
| 9098 | |
| 9099 | Phone phone = getPhone(subId); |
| 9100 | if (phone == null) { |
| 9101 | return 0; |
| 9102 | } |
| 9103 | // Now that all security checks passes, perform the operation as ourselves. |
| 9104 | final long identity = Binder.clearCallingIdentity(); |
| 9105 | try { |
| 9106 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9107 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9108 | return attemptsRemaining; |
| 9109 | |
| 9110 | } catch (Exception e) { |
| 9111 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9112 | } finally { |
| 9113 | Binder.restoreCallingIdentity(identity); |
| 9114 | } |
| 9115 | return 0; |
| 9116 | } |
| 9117 | |
| 9118 | /** |
| 9119 | * Change the ICC password used in ICC pin lock. |
| 9120 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9121 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9122 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9123 | * - Positive number and zero for remaining password attempts. |
| 9124 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9125 | * |
| 9126 | */ |
| 9127 | @Override |
| 9128 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9129 | enforceModifyPermission(); |
| 9130 | |
| 9131 | Phone phone = getPhone(subId); |
| 9132 | if (phone == null) { |
| 9133 | return 0; |
| 9134 | } |
| 9135 | // Now that all security checks passes, perform the operation as ourselves. |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
| 9138 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9139 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9140 | return attemptsRemaining; |
| 9141 | |
| 9142 | } catch (Exception e) { |
| 9143 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9144 | } finally { |
| 9145 | Binder.restoreCallingIdentity(identity); |
| 9146 | } |
| 9147 | return 0; |
| 9148 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9149 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9150 | /** |
| 9151 | * Request for receiving user activity notification |
| 9152 | */ |
| 9153 | @Override |
| 9154 | public void requestUserActivityNotification() { |
| 9155 | if (!mNotifyUserActivity.get() |
| 9156 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9157 | mNotifyUserActivity.set(true); |
| 9158 | } |
| 9159 | } |
| 9160 | |
| 9161 | /** |
| 9162 | * Called when userActivity is signalled in the power manager. |
| 9163 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9164 | */ |
| 9165 | @Override |
| 9166 | public void userActivity() { |
| 9167 | // *************************************** |
| 9168 | // * Inherited from PhoneWindowManager * |
| 9169 | // *************************************** |
| 9170 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9171 | // WITH ITS LOCKS HELD. |
| 9172 | // |
| 9173 | // This code must be VERY careful about the locks |
| 9174 | // it acquires. |
| 9175 | // In fact, the current code acquires way too many, |
| 9176 | // and probably has lurking deadlocks. |
| 9177 | |
| 9178 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9179 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9180 | } |
| 9181 | |
| 9182 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9183 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9184 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9185 | } |
| 9186 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9187 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9188 | @Override |
| 9189 | public boolean canConnectTo5GInDsdsMode() { |
| 9190 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9191 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9192 | |
| 9193 | @Override |
| 9194 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9195 | String callingFeatureId) { |
| 9196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9197 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9198 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9199 | } |
| 9200 | |
| 9201 | Phone phone = getPhone(subId); |
| 9202 | if (phone == null) { |
| 9203 | throw new RuntimeException("phone is not available"); |
| 9204 | } |
| 9205 | // Now that all security checks passes, perform the operation as ourselves. |
| 9206 | final long identity = Binder.clearCallingIdentity(); |
| 9207 | try { |
| 9208 | return phone.getEquivalentHomePlmns(); |
| 9209 | } finally { |
| 9210 | Binder.restoreCallingIdentity(identity); |
| 9211 | } |
| 9212 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9213 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9214 | @Override |
| 9215 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9216 | UaSecurityProtocolIdentifier securityProtocol, |
| 9217 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9218 | throws RemoteException { |
| 9219 | enforceModifyPermission(); |
| 9220 | if (DBG) { |
| 9221 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9222 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9223 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9224 | } |
| 9225 | |
| 9226 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9227 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9228 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9229 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9230 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9231 | if (callback != null) { |
| 9232 | try { |
| 9233 | callback.onAuthenticationFailure( |
| 9234 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9235 | } catch (RemoteException exception) { |
| 9236 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9237 | } |
| 9238 | return; |
| 9239 | } |
| 9240 | } |
| 9241 | |
| 9242 | final long token = Binder.clearCallingIdentity(); |
| 9243 | try { |
| 9244 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9245 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9246 | forceBootStrapping, callback)); |
| 9247 | } finally { |
| 9248 | Binder.restoreCallingIdentity(token); |
| 9249 | } |
| 9250 | } |
| 9251 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9252 | /** |
| 9253 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9254 | * requested radio power state will actually be set. See {@link |
| 9255 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9256 | * |
| 9257 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9258 | * @param enable {@code true} if trying to turn radio on. |
| 9259 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9260 | * false}. |
| 9261 | */ |
| 9262 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9263 | Phone phone = getPhone(subId); |
| 9264 | if (phone != null) { |
| 9265 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9266 | return true; |
| 9267 | } |
| 9268 | return false; |
| 9269 | } |
| 9270 | |
| 9271 | private int handleDataThrottlingRequest(int subId, |
| 9272 | DataThrottlingRequest dataThrottlingRequest) { |
| 9273 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9274 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9275 | if (!setRadioPowerForThermal(subId, true)) { |
| 9276 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9277 | } |
| 9278 | |
| 9279 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9280 | |
| 9281 | int thermalMitigationResult = |
| 9282 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9283 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9284 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9285 | } |
| 9286 | return thermalMitigationResult; |
| 9287 | } |
| 9288 | |
| 9289 | /** |
| 9290 | * Thermal mitigation request to control functionalities at modem. |
| 9291 | * |
| 9292 | * @param subId the id of the subscription. |
| 9293 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9294 | * |
| 9295 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9296 | */ |
| 9297 | @Override |
| 9298 | @ThermalMitigationResult |
| 9299 | public int sendThermalMitigationRequest( |
| 9300 | int subId, |
| 9301 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9302 | enforceModifyPermission(); |
| 9303 | |
| 9304 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9305 | final long identity = Binder.clearCallingIdentity(); |
| 9306 | |
| 9307 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9308 | try { |
| 9309 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9310 | switch (thermalMitigationAction) { |
| 9311 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9312 | thermalMitigationResult = |
| 9313 | handleDataThrottlingRequest(subId, |
| 9314 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9315 | break; |
| 9316 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9317 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9318 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9319 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9320 | } |
| 9321 | |
| 9322 | // Ensure that radio is on. If not able to power on due to phone being |
| 9323 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9324 | if (!setRadioPowerForThermal(subId, true)) { |
| 9325 | thermalMitigationResult = |
| 9326 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9327 | break; |
| 9328 | } |
| 9329 | |
| 9330 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9331 | false); |
| 9332 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9333 | break; |
| 9334 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9335 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9336 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9337 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9338 | } |
| 9339 | |
| 9340 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9341 | if (registry != null) { |
| 9342 | TelephonyConnectionService service = |
| 9343 | registry.getTelephonyConnectionService(); |
| 9344 | Phone phone = getPhone(subId); |
| 9345 | if (phone == null) { |
| 9346 | thermalMitigationResult = |
| 9347 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9348 | break; |
| 9349 | } |
| 9350 | |
| 9351 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9352 | != TelephonyManager.CALL_STATE_IDLE |
| 9353 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9354 | || (service != null && service.isEmergencyCallPending())) { |
| 9355 | String errorMessage = "Phone state is not valid. call state = " |
| 9356 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9357 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9358 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9359 | errorMessage += service == null |
| 9360 | ? " TelephonyConnectionService is null" |
| 9361 | : " isEmergencyCallPending = " |
| 9362 | + service.isEmergencyCallPending(); |
| 9363 | Log.e(LOG_TAG, errorMessage); |
| 9364 | thermalMitigationResult = |
| 9365 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9366 | break; |
| 9367 | } |
| 9368 | } else { |
| 9369 | thermalMitigationResult = |
| 9370 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9371 | break; |
| 9372 | } |
| 9373 | |
| 9374 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9375 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9376 | if (!setRadioPowerForThermal(subId, false)) { |
| 9377 | thermalMitigationResult = |
| 9378 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9379 | break; |
| 9380 | } |
| 9381 | thermalMitigationResult = |
| 9382 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9383 | break; |
| 9384 | default: |
| 9385 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9386 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9387 | } |
| 9388 | } catch (IllegalArgumentException e) { |
| 9389 | throw e; |
| 9390 | } catch (Exception e) { |
| 9391 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9392 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9393 | } finally { |
| 9394 | Binder.restoreCallingIdentity(identity); |
| 9395 | } |
| 9396 | |
| 9397 | if (DBG) { |
| 9398 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9399 | + thermalMitigationResult); |
| 9400 | } |
| 9401 | |
| 9402 | return thermalMitigationResult; |
| 9403 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9404 | |
| 9405 | /** |
| 9406 | * Set the GbaService Package Name that Telephony will bind to. |
| 9407 | * |
| 9408 | * @param subId The sim that the GbaService is associated with. |
| 9409 | * @param packageName The name of the package to be replaced with. |
| 9410 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9411 | */ |
| 9412 | @Override |
| 9413 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9414 | enforceModifyPermission(); |
| 9415 | |
| 9416 | final long identity = Binder.clearCallingIdentity(); |
| 9417 | try { |
| 9418 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9419 | } finally { |
| 9420 | Binder.restoreCallingIdentity(identity); |
| 9421 | } |
| 9422 | } |
| 9423 | |
| 9424 | /** |
| 9425 | * Return the package name of the currently bound GbaService. |
| 9426 | * |
| 9427 | * @param subId The sim that the GbaService is associated with. |
| 9428 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9429 | */ |
| 9430 | @Override |
| 9431 | public String getBoundGbaService(int subId) { |
| 9432 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9433 | |
| 9434 | final long identity = Binder.clearCallingIdentity(); |
| 9435 | try { |
| 9436 | return getGbaManager(subId).getServicePackage(); |
| 9437 | } finally { |
| 9438 | Binder.restoreCallingIdentity(identity); |
| 9439 | } |
| 9440 | } |
| 9441 | |
| 9442 | /** |
| 9443 | * Set the release time for telephony to unbind GbaService. |
| 9444 | * |
| 9445 | * @param subId The sim that the GbaService is associated with. |
| 9446 | * @param interval The release time to unbind GbaService by millisecond. |
| 9447 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9448 | */ |
| 9449 | @Override |
| 9450 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9451 | enforceModifyPermission(); |
| 9452 | |
| 9453 | final long identity = Binder.clearCallingIdentity(); |
| 9454 | try { |
| 9455 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9456 | } finally { |
| 9457 | Binder.restoreCallingIdentity(identity); |
| 9458 | } |
| 9459 | } |
| 9460 | |
| 9461 | /** |
| 9462 | * Return the release time for telephony to unbind GbaService. |
| 9463 | * |
| 9464 | * @param subId The sim that the GbaService is associated with. |
| 9465 | * @return The release time to unbind GbaService by millisecond. |
| 9466 | */ |
| 9467 | @Override |
| 9468 | public int getGbaReleaseTime(int subId) { |
| 9469 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9470 | |
| 9471 | final long identity = Binder.clearCallingIdentity(); |
| 9472 | try { |
| 9473 | return getGbaManager(subId).getReleaseTime(); |
| 9474 | } finally { |
| 9475 | Binder.restoreCallingIdentity(identity); |
| 9476 | } |
| 9477 | } |
| 9478 | |
| 9479 | private GbaManager getGbaManager(int subId) { |
| 9480 | GbaManager instance = GbaManager.getInstance(subId); |
| 9481 | if (instance == null) { |
| 9482 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9483 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9484 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9485 | } |
| 9486 | return instance; |
| 9487 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9488 | |
| 9489 | /** |
| 9490 | * indicate whether the device and the carrier can support |
| 9491 | * RCS VoLTE single registration. |
| 9492 | */ |
| 9493 | @Override |
| 9494 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9495 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9496 | |
| 9497 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9498 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9499 | } |
| 9500 | |
| 9501 | final long identity = Binder.clearCallingIdentity(); |
| 9502 | try { |
| 9503 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9504 | if (rpm != null) { |
| 9505 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9506 | } |
| 9507 | return false; |
| 9508 | } finally { |
| 9509 | Binder.restoreCallingIdentity(identity); |
| 9510 | } |
| 9511 | } |
| 9512 | |
| 9513 | /** |
| 9514 | * Register RCS provisioning callback. |
| 9515 | */ |
| 9516 | @Override |
| 9517 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9518 | IRcsConfigCallback callback) { |
| 9519 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9520 | |
| 9521 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9522 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9523 | } |
| 9524 | if (!isImsAvailableOnDevice()) { |
| 9525 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9526 | "IMS not available on device."); |
| 9527 | } |
| 9528 | |
| 9529 | final long identity = Binder.clearCallingIdentity(); |
| 9530 | try { |
| 9531 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9532 | .addRcsProvisioningCallbackForSubscription(callback, subId); |
| 9533 | } catch (ImsException e) { |
| 9534 | throw new ServiceSpecificException(e.getCode()); |
| 9535 | } finally { |
| 9536 | Binder.restoreCallingIdentity(identity); |
| 9537 | } |
| 9538 | } |
| 9539 | |
| 9540 | /** |
| 9541 | * Unregister RCS provisioning callback. |
| 9542 | */ |
| 9543 | @Override |
| 9544 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9545 | IRcsConfigCallback callback) { |
| 9546 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9547 | |
| 9548 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9549 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9550 | } |
| 9551 | if (!isImsAvailableOnDevice()) { |
| 9552 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9553 | "IMS not available on device."); |
| 9554 | } |
| 9555 | |
| 9556 | final long identity = Binder.clearCallingIdentity(); |
| 9557 | try { |
| 9558 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9559 | .removeRcsProvisioningCallbackForSubscription(callback, subId); |
| 9560 | } catch (ImsException e) { |
| 9561 | Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId |
| 9562 | + "is inactive, ignoring unregister."); |
| 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | /** |
| 9569 | * trigger RCS reconfiguration. |
| 9570 | */ |
| 9571 | public void triggerRcsReconfiguration(int subId) { |
| 9572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9573 | mApp, subId, "triggerRcsReconfiguration"); |
| 9574 | |
| 9575 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9576 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9577 | } |
| 9578 | if (!isImsAvailableOnDevice()) { |
| 9579 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9580 | "IMS not available on device."); |
| 9581 | } |
| 9582 | |
| 9583 | final long identity = Binder.clearCallingIdentity(); |
| 9584 | try { |
| 9585 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9586 | } finally { |
| 9587 | Binder.restoreCallingIdentity(identity); |
| 9588 | } |
| 9589 | } |
| 9590 | |
| 9591 | /** |
| 9592 | * Provide the client configuration parameters of the RCS application. |
| 9593 | */ |
| 9594 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9596 | mApp, subId, "setRcsClientConfiguration"); |
| 9597 | |
| 9598 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9599 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9600 | } |
| 9601 | if (!isImsAvailableOnDevice()) { |
| 9602 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9603 | "IMS not available on device."); |
| 9604 | } |
| 9605 | |
| 9606 | final long identity = Binder.clearCallingIdentity(); |
| 9607 | |
| 9608 | try { |
| 9609 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9610 | if (configBinder == null) { |
| 9611 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9612 | } else { |
| 9613 | configBinder.setRcsClientConfiguration(rcc); |
| 9614 | } |
| 9615 | } catch (RemoteException e) { |
| 9616 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9617 | } finally { |
| 9618 | Binder.restoreCallingIdentity(identity); |
| 9619 | } |
| 9620 | } |
| 9621 | |
| 9622 | /** |
| 9623 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9624 | */ |
| 9625 | @Override |
| 9626 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9628 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9629 | enforceModifyPermission(); |
| 9630 | |
| 9631 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9632 | : Boolean.parseBoolean(enabledStr); |
| 9633 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9634 | } |
| 9635 | |
| 9636 | /** |
| 9637 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9638 | */ |
| 9639 | @Override |
| 9640 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9641 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9642 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9643 | } |
| 9644 | |
| 9645 | /** |
| 9646 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9647 | */ |
| 9648 | @Override |
| 9649 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9650 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9651 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9652 | enforceModifyPermission(); |
| 9653 | |
| 9654 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9655 | : Boolean.parseBoolean(enabledStr); |
| 9656 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9657 | subId, enabled); |
| 9658 | } |
| 9659 | |
| 9660 | /** |
| 9661 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9662 | */ |
| 9663 | @Override |
| 9664 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9665 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9666 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9667 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame^] | 9668 | |
| 9669 | /** |
| 9670 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9671 | * their mobile plan. |
| 9672 | */ |
| 9673 | @Override |
| 9674 | public String getMobileProvisioningUrl() { |
| 9675 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9676 | final long identity = Binder.clearCallingIdentity(); |
| 9677 | try { |
| 9678 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9679 | } finally { |
| 9680 | Binder.restoreCallingIdentity(identity); |
| 9681 | } |
| 9682 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9683 | } |