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 | |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 24 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 25 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 26 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 27 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 28 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 29 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 55 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 68 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 71 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 72 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 73 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 74 | import android.telephony.CellIdentityCdma; |
| 75 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 77 | import android.telephony.CellInfoGsm; |
| 78 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 79 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 80 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 81 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 82 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 83 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 84 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 85 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 86 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 87 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 89 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 90 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 91 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 94 | import android.telephony.SignalStrengthUpdateRequest; |
| 95 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 97 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 100 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 101 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 102 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 103 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 104 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 105 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 106 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 107 | import android.telephony.data.ApnSetting; |
| 108 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 109 | import android.telephony.gba.GbaAuthRequest; |
| 110 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 111 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 113 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 114 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 121 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 127 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 128 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 131 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 132 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 133 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 134 | import com.android.ims.rcs.uce.eab.EabUtil; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RIL; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 173 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 187 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 189 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 191 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 194 | import com.android.services.telephony.TelecomAccountRegistry; |
| 195 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 196 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 197 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 198 | import java.io.FileDescriptor; |
| 199 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 202 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 203 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 204 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 205 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 207 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 208 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 210 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 211 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Implementation of the ITelephony interface. |
| 215 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 216 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 218 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 219 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 220 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | |
| 222 | // Message codes used with mMainThreadHandler |
| 223 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 224 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 225 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | private static final int CMD_OPEN_CHANNEL = 9; |
| 227 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 228 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 229 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 230 | private static final int CMD_NV_READ_ITEM = 13; |
| 231 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 232 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 233 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 234 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 235 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 236 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 237 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 238 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 239 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 240 | private static final int CMD_SEND_ENVELOPE = 25; |
| 241 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 242 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 243 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 244 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 245 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 246 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 247 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 248 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 249 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 250 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 251 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 253 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 254 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 255 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 256 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 257 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 258 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 259 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 260 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 261 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 262 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 263 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 264 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 265 | private static final int CMD_SWITCH_SLOTS = 50; |
| 266 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 268 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 269 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 270 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 271 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 272 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 273 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 274 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 275 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 276 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 277 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 278 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 279 | private static final int CMD_MODEM_REBOOT = 64; |
| 280 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 281 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 282 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 283 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 284 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 285 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 286 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 287 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 288 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 289 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 290 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 291 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 292 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 293 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 294 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 295 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 296 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 297 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 298 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 299 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 300 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 301 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 302 | private static final int CMD_GET_CALL_WAITING = 87; |
| 303 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 304 | private static final int CMD_SET_CALL_WAITING = 89; |
| 305 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 306 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 307 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 308 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 309 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 311 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 312 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 313 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 314 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 315 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 316 | private static final int CMD_SET_SIM_POWER = 101; |
| 317 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 319 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 320 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 321 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 322 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 323 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 324 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 326 | // Parameters of select command. |
| 327 | private static final int SELECT_COMMAND = 0xA4; |
| 328 | private static final int SELECT_P1 = 0x04; |
| 329 | private static final int SELECT_P2 = 0; |
| 330 | private static final int SELECT_P3 = 0x10; |
| 331 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | /** The singleton instance. */ |
| 333 | private static PhoneInterfaceManager sInstance; |
| 334 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 335 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 336 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 337 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 338 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 339 | private AppOpsManager mAppOps; |
| 340 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 341 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 342 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 343 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 345 | /** User Activity */ |
| 346 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 347 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 348 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 349 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 350 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 351 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 352 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 353 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 354 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 355 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 356 | // String to store multi SIM allowed |
| 357 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 358 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 359 | // The AID of ISD-R. |
| 360 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 361 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 362 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 363 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 364 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 365 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 366 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 367 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 368 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 369 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 370 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 371 | */ |
| 372 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 373 | "reset_network_erase_modem_config_enabled"; |
| 374 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 375 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 376 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 377 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 378 | * A request object to use for transmitting data to an ICC. |
| 379 | */ |
| 380 | private static final class IccAPDUArgument { |
| 381 | public int channel, cla, command, p1, p2, p3; |
| 382 | public String data; |
| 383 | |
| 384 | public IccAPDUArgument(int channel, int cla, int command, |
| 385 | int p1, int p2, int p3, String data) { |
| 386 | this.channel = channel; |
| 387 | this.cla = cla; |
| 388 | this.command = command; |
| 389 | this.p1 = p1; |
| 390 | this.p2 = p2; |
| 391 | this.p3 = p3; |
| 392 | this.data = data; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 397 | * A request object to use for transmitting data to an ICC. |
| 398 | */ |
| 399 | private static final class ManualNetworkSelectionArgument { |
| 400 | public OperatorInfo operatorInfo; |
| 401 | public boolean persistSelection; |
| 402 | |
| 403 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 404 | this.operatorInfo = operatorInfo; |
| 405 | this.persistSelection = persistSelection; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 411 | * request after sending. The main thread will notify the request when it is complete. |
| 412 | */ |
| 413 | private static final class MainThreadRequest { |
| 414 | /** The argument to use for the request */ |
| 415 | public Object argument; |
| 416 | /** The result of the request that is run on the main thread */ |
| 417 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 418 | // The subscriber id that this request applies to. Defaults to |
| 419 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 420 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 422 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 423 | public Phone phone; |
| 424 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 425 | public WorkSource workSource; |
| 426 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | public MainThreadRequest(Object argument) { |
| 428 | this.argument = argument; |
| 429 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 430 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 431 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 432 | this.argument = argument; |
| 433 | if (phone != null) { |
| 434 | this.phone = phone; |
| 435 | } |
| 436 | this.workSource = workSource; |
| 437 | } |
| 438 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 439 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 440 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 441 | if (subId != null) { |
| 442 | this.subId = subId; |
| 443 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 444 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 445 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 448 | private static final class IncomingThirdPartyCallArgs { |
| 449 | public final ComponentName component; |
| 450 | public final String callId; |
| 451 | public final String callerDisplayName; |
| 452 | |
| 453 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 454 | String callerDisplayName) { |
| 455 | this.component = component; |
| 456 | this.callId = callId; |
| 457 | this.callerDisplayName = callerDisplayName; |
| 458 | } |
| 459 | } |
| 460 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | /** |
| 462 | * A handler that processes messages on the main thread in the phone process. Since many |
| 463 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 464 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 465 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 466 | * on, which will be notified when the operation completes and will contain the result of the |
| 467 | * request. |
| 468 | * |
| 469 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 470 | * note that request.result must be set to something non-null for the calling thread to |
| 471 | * unblock. |
| 472 | */ |
| 473 | private final class MainThreadHandler extends Handler { |
| 474 | @Override |
| 475 | public void handleMessage(Message msg) { |
| 476 | MainThreadRequest request; |
| 477 | Message onCompleted; |
| 478 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 479 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 481 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | |
| 483 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 484 | case CMD_HANDLE_USSD_REQUEST: { |
| 485 | request = (MainThreadRequest) msg.obj; |
| 486 | final Phone phone = getPhoneFromRequest(request); |
| 487 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 488 | String ussdRequest = ussdObject.first; |
| 489 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 490 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 491 | if (!isUssdApiAllowed(request.subId)) { |
| 492 | // Carrier does not support use of this API, return failure. |
| 493 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 494 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 495 | Bundle returnData = new Bundle(); |
| 496 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 497 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 498 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | request.result = true; |
| 500 | notifyRequester(request); |
| 501 | return; |
| 502 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 503 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | try { |
| 505 | request.result = phone != null |
| 506 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 507 | } catch (CallStateException cse) { |
| 508 | request.result = false; |
| 509 | } |
| 510 | // Wake up the requesting thread |
| 511 | notifyRequester(request); |
| 512 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 515 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 517 | final Phone phone = getPhoneFromRequest(request); |
| 518 | request.result = phone != null ? |
| 519 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 520 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 527 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 529 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | if (uiccCard == null) { |
| 531 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 532 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 536 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 539 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | break; |
| 543 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | ar = (AsyncResult) msg.obj; |
| 546 | request = (MainThreadRequest) ar.userObj; |
| 547 | if (ar.exception == null && ar.result != null) { |
| 548 | request.result = ar.result; |
| 549 | } else { |
| 550 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 551 | if (ar.result == null) { |
| 552 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 553 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 555 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | } else { |
| 557 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 558 | } |
| 559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 564 | request = (MainThreadRequest) msg.obj; |
| 565 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | if (uiccCard == null) { |
| 568 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | } else { |
| 572 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 573 | request); |
| 574 | uiccCard.iccTransmitApduBasicChannel( |
| 575 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 576 | iccArgument.p3, iccArgument.data, onCompleted); |
| 577 | } |
| 578 | break; |
| 579 | |
| 580 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 581 | ar = (AsyncResult) msg.obj; |
| 582 | request = (MainThreadRequest) ar.userObj; |
| 583 | if (ar.exception == null && ar.result != null) { |
| 584 | request.result = ar.result; |
| 585 | } else { |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 587 | if (ar.result == null) { |
| 588 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 589 | } else if (ar.exception instanceof CommandException) { |
| 590 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 591 | ar.exception); |
| 592 | } else { |
| 593 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 594 | } |
| 595 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
| 599 | case CMD_EXCHANGE_SIM_IO: |
| 600 | request = (MainThreadRequest) msg.obj; |
| 601 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 602 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | if (uiccCard == null) { |
| 604 | loge("iccExchangeSimIO: No UICC"); |
| 605 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | } else { |
| 608 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 609 | request); |
| 610 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 611 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 612 | iccArgument.data, onCompleted); |
| 613 | } |
| 614 | break; |
| 615 | |
| 616 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 617 | ar = (AsyncResult) msg.obj; |
| 618 | request = (MainThreadRequest) ar.userObj; |
| 619 | if (ar.exception == null && ar.result != null) { |
| 620 | request.result = ar.result; |
| 621 | } else { |
| 622 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | case CMD_SEND_ENVELOPE: |
| 628 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 629 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | if (uiccCard == null) { |
| 631 | loge("sendEnvelopeWithStatus: No UICC"); |
| 632 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | } else { |
| 635 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 636 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 637 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case EVENT_SEND_ENVELOPE_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 647 | if (ar.result == null) { |
| 648 | loge("sendEnvelopeWithStatus: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 654 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 657 | break; |
| 658 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | case CMD_OPEN_CHANNEL: |
| 660 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 661 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 662 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | if (uiccCard == null) { |
| 664 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 665 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 666 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | } else { |
| 669 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 670 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 671 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EVENT_OPEN_CHANNEL_DONE: |
| 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | int[] result = (int[]) ar.result; |
| 681 | int channelId = result[0]; |
| 682 | byte[] selectResponse = null; |
| 683 | if (result.length > 1) { |
| 684 | selectResponse = new byte[result.length - 1]; |
| 685 | for (int i = 1; i < result.length; ++i) { |
| 686 | selectResponse[i - 1] = (byte) result[i]; |
| 687 | } |
| 688 | } |
| 689 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 690 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | if (ar.result == null) { |
| 693 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | if (ar.exception != null) { |
| 696 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 697 | } |
| 698 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 699 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 700 | if (ar.exception instanceof CommandException) { |
| 701 | CommandException.Error error = |
| 702 | ((CommandException) (ar.exception)).getCommandError(); |
| 703 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 704 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 705 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 706 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 710 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 712 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 713 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case CMD_CLOSE_CHANNEL: |
| 717 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 718 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | if (uiccCard == null) { |
| 720 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 721 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | } else { |
| 724 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 725 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 726 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 731 | break; |
| 732 | |
| 733 | case CMD_NV_READ_ITEM: |
| 734 | request = (MainThreadRequest) msg.obj; |
| 735 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 736 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 737 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | ar = (AsyncResult) msg.obj; |
| 742 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | if (ar.exception == null && ar.result != null) { |
| 744 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | request.result = ""; |
| 747 | if (ar.result == null) { |
| 748 | loge("nvReadItem: Empty response"); |
| 749 | } else if (ar.exception instanceof CommandException) { |
| 750 | loge("nvReadItem: CommandException: " + |
| 751 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 752 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 756 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 757 | break; |
| 758 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | case CMD_NV_WRITE_ITEM: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 762 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 763 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 764 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_NV_WRITE_ITEM_DONE: |
| 768 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 769 | break; |
| 770 | |
| 771 | case CMD_NV_WRITE_CDMA_PRL: |
| 772 | request = (MainThreadRequest) msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 778 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 779 | break; |
| 780 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 781 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 783 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 788 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 791 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 792 | request = (MainThreadRequest) msg.obj; |
| 793 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 794 | request); |
| 795 | Phone phone = getPhoneFromRequest(request); |
| 796 | if (phone != null) { |
| 797 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 798 | } else { |
| 799 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 800 | request.result = false; |
| 801 | notifyRequester(request); |
| 802 | } |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 807 | ar = (AsyncResult) msg.obj; |
| 808 | request = (MainThreadRequest) ar.userObj; |
| 809 | if (ar.exception == null && ar.result != null) { |
| 810 | request.result = ar.result; |
| 811 | } else { |
| 812 | // request.result must be set to something non-null |
| 813 | // for the calling thread to unblock |
| 814 | if (request.result != null) { |
| 815 | request.result = ar.result; |
| 816 | } else { |
| 817 | request.result = false; |
| 818 | } |
| 819 | if (ar.result == null) { |
| 820 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 821 | } else if (ar.exception instanceof CommandException) { |
| 822 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 823 | + ar.exception); |
| 824 | } else { |
| 825 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 826 | } |
| 827 | } |
| 828 | notifyRequester(request); |
| 829 | break; |
| 830 | |
| 831 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 832 | request = (MainThreadRequest) msg.obj; |
| 833 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 834 | Phone phone = getPhoneFromRequest(request); |
| 835 | if (phone != null) { |
| 836 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 837 | request.workSource); |
| 838 | } else { |
| 839 | loge("enableNrDualConnectivity: No phone object"); |
| 840 | request.result = |
| 841 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 842 | notifyRequester(request); |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null) { |
| 851 | request.result = |
| 852 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 853 | } else { |
| 854 | request.result = |
| 855 | TelephonyManager |
| 856 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 857 | if (ar.exception instanceof CommandException) { |
| 858 | CommandException.Error error = |
| 859 | ((CommandException) (ar.exception)).getCommandError(); |
| 860 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 861 | request.result = |
| 862 | TelephonyManager |
| 863 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 864 | } |
| 865 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 866 | + ar.exception); |
| 867 | } else { |
| 868 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 869 | } |
| 870 | } |
| 871 | notifyRequester(request); |
| 872 | break; |
| 873 | } |
| 874 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 875 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 876 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 877 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 878 | request); |
| 879 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 882 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 883 | ar = (AsyncResult) msg.obj; |
| 884 | request = (MainThreadRequest) ar.userObj; |
| 885 | if (ar.exception == null && ar.result != null) { |
| 886 | request.result = ar.result; // Integer |
| 887 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 888 | // request.result must be set to something non-null |
| 889 | // for the calling thread to unblock |
| 890 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 891 | if (ar.result == null) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 892 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 893 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 894 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 895 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | } else { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 897 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 898 | } |
| 899 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 900 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | break; |
| 902 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 903 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 904 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 905 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 906 | request); |
| 907 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 908 | (Pair<Integer, Long>) request.argument; |
| 909 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 910 | reasonWithNetworkTypes.first, |
| 911 | reasonWithNetworkTypes.second, |
| 912 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 913 | break; |
| 914 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 915 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 916 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 919 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 920 | request = (MainThreadRequest)msg.obj; |
| 921 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 922 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 923 | break; |
| 924 | |
| 925 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 926 | ar = (AsyncResult)msg.obj; |
| 927 | request = (MainThreadRequest)ar.userObj; |
| 928 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 929 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 930 | break; |
| 931 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 932 | case CMD_SET_VOICEMAIL_NUMBER: |
| 933 | request = (MainThreadRequest) msg.obj; |
| 934 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 935 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 936 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 937 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 938 | break; |
| 939 | |
| 940 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 941 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 942 | break; |
| 943 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 944 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 945 | request = (MainThreadRequest) msg.obj; |
| 946 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 947 | request); |
| 948 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 949 | break; |
| 950 | |
| 951 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 952 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 953 | break; |
| 954 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 955 | case CMD_PERFORM_NETWORK_SCAN: |
| 956 | request = (MainThreadRequest) msg.obj; |
| 957 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 958 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 959 | break; |
| 960 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 961 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 962 | request = (MainThreadRequest) msg.obj; |
| 963 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 965 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 966 | request.argument; |
| 967 | int callForwardingReason = args.first; |
| 968 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 969 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 970 | } |
| 971 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 972 | ar = (AsyncResult) msg.obj; |
| 973 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | TelephonyManager.CallForwardingInfoCallback callback = |
| 975 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 976 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 977 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 979 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 980 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 981 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 982 | // any service for voice call. |
| 983 | if ((callForwardInfo.serviceClass |
| 984 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | callForwardingInfo = new CallForwardingInfo(true, |
| 986 | callForwardInfo.reason, |
| 987 | callForwardInfo.number, |
| 988 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 989 | break; |
| 990 | } |
| 991 | } |
| 992 | // Didn't find a call forward info for voice call. |
| 993 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 994 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 995 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 996 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 997 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 998 | } else { |
| 999 | if (ar.result == null) { |
| 1000 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1001 | } |
| 1002 | if (ar.exception != null) { |
| 1003 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1004 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1005 | int errorCode = TelephonyManager |
| 1006 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1007 | if (ar.exception instanceof CommandException) { |
| 1008 | CommandException.Error error = |
| 1009 | ((CommandException) (ar.exception)).getCommandError(); |
| 1010 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1011 | errorCode = TelephonyManager |
| 1012 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1013 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1014 | errorCode = TelephonyManager |
| 1015 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | } |
| 1017 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1019 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1020 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1022 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1023 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1024 | request = (MainThreadRequest) msg.obj; |
| 1025 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1026 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1027 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1029 | request.argument).first; |
| 1030 | request.phone.setCallForwardingOption( |
| 1031 | callForwardingInfoToSet.isEnabled() |
| 1032 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1033 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1034 | callForwardingInfoToSet.getReason(), |
| 1035 | callForwardingInfoToSet.getNumber(), |
| 1036 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1037 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1039 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | Consumer<Integer> callback = |
| 1044 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1045 | request.argument).second; |
| 1046 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1047 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1048 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1049 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | if (ar.exception instanceof CommandException) { |
| 1051 | CommandException.Error error = |
| 1052 | ((CommandException) (ar.exception)).getCommandError(); |
| 1053 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1054 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1055 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1057 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1058 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } |
| 1061 | callback.accept(errorCode); |
| 1062 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1063 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1065 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1067 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1069 | request = (MainThreadRequest) msg.obj; |
| 1070 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1071 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1072 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1074 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1079 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1080 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1081 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1082 | // Service Class is a bit mask per 3gpp 27.007. |
| 1083 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1084 | if (callForwardResults.length > 1 |
| 1085 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1087 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1088 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1089 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1090 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1092 | } |
| 1093 | } else { |
| 1094 | if (ar.result == null) { |
| 1095 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1096 | } |
| 1097 | if (ar.exception != null) { |
| 1098 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1099 | } |
| 1100 | if (ar.exception instanceof CommandException) { |
| 1101 | CommandException.Error error = |
| 1102 | ((CommandException) (ar.exception)).getCommandError(); |
| 1103 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1104 | callForwardingStatus = |
| 1105 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1106 | } |
| 1107 | } |
| 1108 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1110 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1112 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1114 | request = (MainThreadRequest) msg.obj; |
| 1115 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1117 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1118 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1120 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1121 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1122 | ar = (AsyncResult) msg.obj; |
| 1123 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1125 | Consumer<Integer> callback = |
| 1126 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1127 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1128 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | if (ar.exception instanceof CommandException) { |
| 1130 | CommandException.Error error = |
| 1131 | ((CommandException) (ar.exception)).getCommandError(); |
| 1132 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1133 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1134 | } else { |
| 1135 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1136 | } |
| 1137 | } else { |
| 1138 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1139 | } |
| 1140 | } else { |
| 1141 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1142 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1143 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1144 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1145 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1146 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1147 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1148 | ar = (AsyncResult) msg.obj; |
| 1149 | request = (MainThreadRequest) ar.userObj; |
| 1150 | CellNetworkScanResult cellScanResult; |
| 1151 | if (ar.exception == null && ar.result != null) { |
| 1152 | cellScanResult = new CellNetworkScanResult( |
| 1153 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1154 | (List<OperatorInfo>) ar.result); |
| 1155 | } else { |
| 1156 | if (ar.result == null) { |
| 1157 | loge("getCellNetworkScanResults: Empty response"); |
| 1158 | } |
| 1159 | if (ar.exception != null) { |
| 1160 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1161 | } |
| 1162 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1163 | if (ar.exception instanceof CommandException) { |
| 1164 | CommandException.Error error = |
| 1165 | ((CommandException) (ar.exception)).getCommandError(); |
| 1166 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1167 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1168 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1169 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1170 | } |
| 1171 | } |
| 1172 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1173 | } |
| 1174 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1175 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | |
| 1178 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1179 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1180 | ManualNetworkSelectionArgument selArg = |
| 1181 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1182 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1183 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1184 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1185 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1186 | break; |
| 1187 | |
| 1188 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1189 | ar = (AsyncResult) msg.obj; |
| 1190 | request = (MainThreadRequest) ar.userObj; |
| 1191 | if (ar.exception == null) { |
| 1192 | request.result = true; |
| 1193 | } else { |
| 1194 | request.result = false; |
| 1195 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1196 | } |
| 1197 | notifyRequester(request); |
| 1198 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1199 | break; |
| 1200 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1201 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1204 | if (defaultPhone != null) { |
| 1205 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1206 | } else { |
| 1207 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1208 | Bundle bundle = new Bundle(); |
| 1209 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1210 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1211 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1212 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1213 | break; |
| 1214 | |
| 1215 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1216 | ar = (AsyncResult) msg.obj; |
| 1217 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1218 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1219 | |
| 1220 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1221 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1222 | // Update the last modem activity info and the result of the request. |
| 1223 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1224 | if (isModemActivityInfoValid(info)) { |
| 1225 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1226 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1227 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1228 | .getTransmitTimeMillis(); |
| 1229 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1230 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1231 | } |
| 1232 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1233 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1234 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1235 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1236 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1237 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1238 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1239 | info.getReceiveTimeMillis() |
| 1240 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1241 | } |
| 1242 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1243 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1244 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1245 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1246 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1247 | } else { |
| 1248 | if (ar.result == null) { |
| 1249 | loge("queryModemActivityInfo: Empty response"); |
| 1250 | } else if (ar.exception instanceof CommandException) { |
| 1251 | loge("queryModemActivityInfo: CommandException: " + |
| 1252 | ar.exception); |
| 1253 | } else { |
| 1254 | loge("queryModemActivityInfo: Unknown exception"); |
| 1255 | } |
| 1256 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1257 | Bundle bundle = new Bundle(); |
| 1258 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1259 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1260 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1261 | break; |
| 1262 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1263 | case CMD_SET_ALLOWED_CARRIERS: |
| 1264 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1265 | CarrierRestrictionRules argument = |
| 1266 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1267 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1268 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1269 | break; |
| 1270 | |
| 1271 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1272 | ar = (AsyncResult) msg.obj; |
| 1273 | request = (MainThreadRequest) ar.userObj; |
| 1274 | if (ar.exception == null && ar.result != null) { |
| 1275 | request.result = ar.result; |
| 1276 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1277 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1278 | if (ar.exception instanceof CommandException) { |
| 1279 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1280 | CommandException.Error error = |
| 1281 | ((CommandException) (ar.exception)).getCommandError(); |
| 1282 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1283 | request.result = |
| 1284 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1285 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1286 | } else { |
| 1287 | loge("setAllowedCarriers: Unknown exception"); |
| 1288 | } |
| 1289 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1290 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1291 | break; |
| 1292 | |
| 1293 | case CMD_GET_ALLOWED_CARRIERS: |
| 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1296 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1297 | break; |
| 1298 | |
| 1299 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1300 | ar = (AsyncResult) msg.obj; |
| 1301 | request = (MainThreadRequest) ar.userObj; |
| 1302 | if (ar.exception == null && ar.result != null) { |
| 1303 | request.result = ar.result; |
| 1304 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1305 | request.result = new IllegalStateException( |
| 1306 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1307 | if (ar.result == null) { |
| 1308 | loge("getAllowedCarriers: Empty response"); |
| 1309 | } else if (ar.exception instanceof CommandException) { |
| 1310 | loge("getAllowedCarriers: CommandException: " + |
| 1311 | ar.exception); |
| 1312 | } else { |
| 1313 | loge("getAllowedCarriers: Unknown exception"); |
| 1314 | } |
| 1315 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1316 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1317 | break; |
| 1318 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1319 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1320 | ar = (AsyncResult) msg.obj; |
| 1321 | request = (MainThreadRequest) ar.userObj; |
| 1322 | if (ar.exception == null && ar.result != null) { |
| 1323 | request.result = ar.result; |
| 1324 | } else { |
| 1325 | request.result = new IllegalArgumentException( |
| 1326 | "Failed to retrieve Forbidden Plmns"); |
| 1327 | if (ar.result == null) { |
| 1328 | loge("getForbiddenPlmns: Empty response"); |
| 1329 | } else { |
| 1330 | loge("getForbiddenPlmns: Unknown exception"); |
| 1331 | } |
| 1332 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1333 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1334 | break; |
| 1335 | |
| 1336 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1337 | request = (MainThreadRequest) msg.obj; |
| 1338 | uiccCard = getUiccCardFromRequest(request); |
| 1339 | if (uiccCard == null) { |
| 1340 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1341 | request.result = new IllegalArgumentException( |
| 1342 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1343 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | Integer appType = (Integer) request.argument; |
| 1347 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1348 | if (uiccApp == null) { |
| 1349 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1350 | + appType); |
| 1351 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1352 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1353 | break; |
| 1354 | } else { |
| 1355 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1356 | + " specified type -- " + appType); |
| 1357 | } |
| 1358 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1359 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1360 | onCompleted); |
| 1361 | break; |
| 1362 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1363 | case CMD_SWITCH_SLOTS: |
| 1364 | request = (MainThreadRequest) msg.obj; |
| 1365 | int[] physicalSlots = (int[]) request.argument; |
| 1366 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1367 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1368 | break; |
| 1369 | |
| 1370 | case EVENT_SWITCH_SLOTS_DONE: |
| 1371 | ar = (AsyncResult) msg.obj; |
| 1372 | request = (MainThreadRequest) ar.userObj; |
| 1373 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1374 | notifyRequester(request); |
| 1375 | break; |
| 1376 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1377 | request = (MainThreadRequest) msg.obj; |
| 1378 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1379 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1380 | break; |
| 1381 | |
| 1382 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1383 | ar = (AsyncResult) msg.obj; |
| 1384 | request = (MainThreadRequest) ar.userObj; |
| 1385 | if (ar.exception != null) { |
| 1386 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1387 | } else { |
| 1388 | int mode = ((int[]) ar.result)[0]; |
| 1389 | if (mode == 0) { |
| 1390 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1391 | } else { |
| 1392 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1393 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1394 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1395 | notifyRequester(request); |
| 1396 | break; |
| 1397 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1398 | request = (MainThreadRequest) msg.obj; |
| 1399 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1400 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1401 | break; |
| 1402 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1403 | ar = (AsyncResult) msg.obj; |
| 1404 | request = (MainThreadRequest) ar.userObj; |
| 1405 | if (ar.exception != null) { |
| 1406 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1407 | } else { |
| 1408 | request.result = ((int[]) ar.result)[0]; |
| 1409 | } |
| 1410 | notifyRequester(request); |
| 1411 | break; |
| 1412 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1413 | request = (MainThreadRequest) msg.obj; |
| 1414 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1415 | int mode = (int) request.argument; |
| 1416 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1417 | break; |
| 1418 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1419 | ar = (AsyncResult) msg.obj; |
| 1420 | request = (MainThreadRequest) ar.userObj; |
| 1421 | request.result = ar.exception == null; |
| 1422 | notifyRequester(request); |
| 1423 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1424 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1425 | request = (MainThreadRequest) msg.obj; |
| 1426 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1427 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1428 | break; |
| 1429 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1430 | ar = (AsyncResult) msg.obj; |
| 1431 | request = (MainThreadRequest) ar.userObj; |
| 1432 | if (ar.exception != null) { |
| 1433 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1434 | } else { |
| 1435 | request.result = ((int[]) ar.result)[0]; |
| 1436 | } |
| 1437 | notifyRequester(request); |
| 1438 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1439 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1440 | request = (MainThreadRequest) msg.obj; |
| 1441 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1442 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1443 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1444 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
| 1449 | request.result = ar.exception == null; |
| 1450 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1451 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1452 | case CMD_GET_ALL_CELL_INFO: |
| 1453 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1454 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1455 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1456 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1457 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1458 | ar = (AsyncResult) msg.obj; |
| 1459 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1460 | // If a timeout occurs, the response will be null |
| 1461 | request.result = (ar.exception == null && ar.result != null) |
| 1462 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1463 | synchronized (request) { |
| 1464 | request.notifyAll(); |
| 1465 | } |
| 1466 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1467 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1468 | request = (MainThreadRequest) msg.obj; |
| 1469 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1470 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1471 | break; |
| 1472 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1473 | ar = (AsyncResult) msg.obj; |
| 1474 | request = (MainThreadRequest) ar.userObj; |
| 1475 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1476 | try { |
| 1477 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1478 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1479 | cb.onError( |
| 1480 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1481 | ar.exception.getClass().getName(), |
| 1482 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1483 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1484 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1485 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1486 | } else { |
| 1487 | // use the result as returned |
| 1488 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1489 | } |
| 1490 | } catch (RemoteException re) { |
| 1491 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1492 | } |
| 1493 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1494 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1495 | request = (MainThreadRequest) msg.obj; |
| 1496 | WorkSource ws = (WorkSource) request.argument; |
| 1497 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1498 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1500 | } |
| 1501 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1502 | ar = (AsyncResult) msg.obj; |
| 1503 | request = (MainThreadRequest) ar.userObj; |
| 1504 | if (ar.exception == null) { |
| 1505 | request.result = ar.result; |
| 1506 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1507 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1508 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1509 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | synchronized (request) { |
| 1513 | request.notifyAll(); |
| 1514 | } |
| 1515 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1516 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1517 | case CMD_MODEM_REBOOT: |
| 1518 | request = (MainThreadRequest) msg.obj; |
| 1519 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1520 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1521 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1522 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1523 | handleNullReturnEvent(msg, "rebootModem"); |
| 1524 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1525 | case CMD_REQUEST_ENABLE_MODEM: |
| 1526 | request = (MainThreadRequest) msg.obj; |
| 1527 | boolean enable = (boolean) request.argument; |
| 1528 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1529 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1530 | PhoneConfigurationManager.getInstance() |
| 1531 | .enablePhone(request.phone, enable, onCompleted); |
| 1532 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1533 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1534 | ar = (AsyncResult) msg.obj; |
| 1535 | request = (MainThreadRequest) ar.userObj; |
| 1536 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1537 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1538 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1539 | if ((boolean) request.result) { |
| 1540 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1541 | updateModemStateMetrics(); |
| 1542 | } else { |
| 1543 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1544 | + ar.exception); |
| 1545 | } |
| 1546 | notifyRequester(request); |
| 1547 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1548 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1549 | case CMD_GET_MODEM_STATUS: |
| 1550 | request = (MainThreadRequest) msg.obj; |
| 1551 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1552 | PhoneConfigurationManager.getInstance() |
| 1553 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1554 | break; |
| 1555 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1556 | ar = (AsyncResult) msg.obj; |
| 1557 | request = (MainThreadRequest) ar.userObj; |
| 1558 | int id = request.phone.getPhoneId(); |
| 1559 | if (ar.exception == null && ar.result != null) { |
| 1560 | request.result = ar.result; |
| 1561 | //update the cache as modem status has changed |
| 1562 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1563 | (boolean) request.result); |
| 1564 | } else { |
| 1565 | // Return true if modem status cannot be retrieved. For most cases, |
| 1566 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1567 | // and disable modem are not supported. Modem is always on. |
| 1568 | // TODO: this should be fixed in R to support a third |
| 1569 | // status UNKNOWN b/131631629 |
| 1570 | request.result = true; |
| 1571 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1572 | + ar.exception); |
| 1573 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1574 | notifyRequester(request); |
| 1575 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1576 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1577 | request = (MainThreadRequest) msg.obj; |
| 1578 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1579 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1580 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1581 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1582 | break; |
| 1583 | } |
| 1584 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1585 | ar = (AsyncResult) msg.obj; |
| 1586 | request = (MainThreadRequest) ar.userObj; |
| 1587 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1588 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1589 | args.second.accept(ar.exception == null); |
| 1590 | notifyRequester(request); |
| 1591 | break; |
| 1592 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1593 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1594 | request = (MainThreadRequest) msg.obj; |
| 1595 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1596 | Phone phone = getPhoneFromRequest(request); |
| 1597 | if (phone != null) { |
| 1598 | phone.getSystemSelectionChannels(onCompleted); |
| 1599 | } else { |
| 1600 | loge("getSystemSelectionChannels: No phone object"); |
| 1601 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1602 | notifyRequester(request); |
| 1603 | } |
| 1604 | break; |
| 1605 | } |
| 1606 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1607 | ar = (AsyncResult) msg.obj; |
| 1608 | request = (MainThreadRequest) ar.userObj; |
| 1609 | if (ar.exception == null && ar.result != null) { |
| 1610 | request.result = ar.result; |
| 1611 | } else { |
| 1612 | request.result = new IllegalArgumentException( |
| 1613 | "Failed to retrieve system selection channels"); |
| 1614 | if (ar.result == null) { |
| 1615 | loge("getSystemSelectionChannels: Empty response"); |
| 1616 | } else { |
| 1617 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1618 | } |
| 1619 | } |
| 1620 | notifyRequester(request); |
| 1621 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1622 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1623 | ar = (AsyncResult) msg.obj; |
| 1624 | request = (MainThreadRequest) ar.userObj; |
| 1625 | if (ar.exception == null && ar.result != null) { |
| 1626 | request.result = ar.result; |
| 1627 | } else { |
| 1628 | request.result = -1; |
| 1629 | loge("Failed to set Forbidden Plmns"); |
| 1630 | if (ar.result == null) { |
| 1631 | loge("setForbidenPlmns: Empty response"); |
| 1632 | } else if (ar.exception != null) { |
| 1633 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1634 | request.result = -1; |
| 1635 | } else { |
| 1636 | loge("setForbiddenPlmns: Unknown exception"); |
| 1637 | } |
| 1638 | } |
| 1639 | notifyRequester(request); |
| 1640 | break; |
| 1641 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1642 | request = (MainThreadRequest) msg.obj; |
| 1643 | uiccCard = getUiccCardFromRequest(request); |
| 1644 | if (uiccCard == null) { |
| 1645 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1646 | request.result = -1; |
| 1647 | notifyRequester(request); |
| 1648 | break; |
| 1649 | } |
| 1650 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1651 | (Pair<Integer, List<String>>) request.argument; |
| 1652 | appType = setFplmnsArgs.first; |
| 1653 | List<String> fplmns = setFplmnsArgs.second; |
| 1654 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1655 | if (uiccApp == null) { |
| 1656 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1657 | request.result = -1; |
| 1658 | loge("Failed to get UICC App"); |
| 1659 | notifyRequester(request); |
| 1660 | } else { |
| 1661 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1662 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1663 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1664 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1665 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1666 | case CMD_ERASE_MODEM_CONFIG: |
| 1667 | request = (MainThreadRequest) msg.obj; |
| 1668 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1669 | defaultPhone.eraseModemConfig(onCompleted); |
| 1670 | break; |
| 1671 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1672 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1673 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1674 | |
| 1675 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1676 | request = (MainThreadRequest) msg.obj; |
| 1677 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1678 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1679 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1680 | changed.first, changed.second, onCompleted); |
| 1681 | break; |
| 1682 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1683 | ar = (AsyncResult) msg.obj; |
| 1684 | request = (MainThreadRequest) ar.userObj; |
| 1685 | if (ar.exception == null) { |
| 1686 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1687 | // If the operation is successful, update the PIN storage |
| 1688 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1689 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1690 | UiccController.getInstance().getPinStorage() |
| 1691 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1692 | } else { |
| 1693 | request.result = msg.arg1; |
| 1694 | } |
| 1695 | notifyRequester(request); |
| 1696 | break; |
| 1697 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1698 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1701 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1702 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1703 | enabled.first, enabled.second, onCompleted); |
| 1704 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1705 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1706 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1707 | ar = (AsyncResult) msg.obj; |
| 1708 | request = (MainThreadRequest) ar.userObj; |
| 1709 | if (ar.exception == null) { |
| 1710 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1711 | // If the operation is successful, update the PIN storage |
| 1712 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1713 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1714 | if (enabled.first) { |
| 1715 | UiccController.getInstance().getPinStorage() |
| 1716 | .storePin(enabled.second, phoneId); |
| 1717 | } else { |
| 1718 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1719 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1720 | } else { |
| 1721 | request.result = msg.arg1; |
| 1722 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1723 | |
| 1724 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1725 | notifyRequester(request); |
| 1726 | break; |
| 1727 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1728 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1729 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1730 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1731 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1732 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1733 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1734 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1735 | |
| 1736 | case CMD_SET_DATA_THROTTLING: { |
| 1737 | request = (MainThreadRequest) msg.obj; |
| 1738 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1739 | DataThrottlingRequest dataThrottlingRequest = |
| 1740 | (DataThrottlingRequest) request.argument; |
| 1741 | Phone phone = getPhoneFromRequest(request); |
| 1742 | if (phone != null) { |
| 1743 | phone.setDataThrottling(onCompleted, |
| 1744 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1745 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1746 | } else { |
| 1747 | loge("setDataThrottling: No phone object"); |
| 1748 | request.result = |
| 1749 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1750 | notifyRequester(request); |
| 1751 | } |
| 1752 | |
| 1753 | break; |
| 1754 | } |
| 1755 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1756 | ar = (AsyncResult) msg.obj; |
| 1757 | request = (MainThreadRequest) ar.userObj; |
| 1758 | |
| 1759 | if (ar.exception == null) { |
| 1760 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1761 | } else if (ar.exception instanceof CommandException) { |
| 1762 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1763 | CommandException.Error error = |
| 1764 | ((CommandException) (ar.exception)).getCommandError(); |
| 1765 | |
| 1766 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1767 | request.result = TelephonyManager |
| 1768 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1769 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1770 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1771 | } else { |
| 1772 | request.result = |
| 1773 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1774 | } |
| 1775 | } else { |
| 1776 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1777 | } |
| 1778 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1779 | notifyRequester(request); |
| 1780 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1781 | |
| 1782 | case CMD_SET_SIM_POWER: { |
| 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1785 | request = (MainThreadRequest) msg.obj; |
| 1786 | int stateToSet = |
| 1787 | ((Pair<Integer, IIntegerConsumer>) |
| 1788 | request.argument).first; |
| 1789 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1790 | break; |
| 1791 | } |
| 1792 | case EVENT_SET_SIM_POWER_DONE: { |
| 1793 | ar = (AsyncResult) msg.obj; |
| 1794 | request = (MainThreadRequest) ar.userObj; |
| 1795 | IIntegerConsumer callback = |
| 1796 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1797 | if (ar.exception != null) { |
| 1798 | loge("setSimPower exception: " + ar.exception); |
| 1799 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1800 | .RESULT_ERROR_UNKNOWN; |
| 1801 | if (ar.exception instanceof CommandException) { |
| 1802 | CommandException.Error error = |
| 1803 | ((CommandException) (ar.exception)).getCommandError(); |
| 1804 | if (error == CommandException.Error.SIM_ERR) { |
| 1805 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1806 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1807 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1808 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1809 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1810 | } else { |
| 1811 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1812 | } |
| 1813 | } |
| 1814 | try { |
| 1815 | callback.accept(errorCode); |
| 1816 | } catch (RemoteException e) { |
| 1817 | // Ignore if the remote process is no longer available to call back. |
| 1818 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1819 | } |
| 1820 | } else { |
| 1821 | try { |
| 1822 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1823 | } catch (RemoteException e) { |
| 1824 | // Ignore if the remote process is no longer available to call back. |
| 1825 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1826 | } |
| 1827 | } |
| 1828 | break; |
| 1829 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1830 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1831 | request = (MainThreadRequest) msg.obj; |
| 1832 | |
| 1833 | final Phone phone = getPhoneFromRequest(request); |
| 1834 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1835 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1836 | notifyRequester(request); |
| 1837 | break; |
| 1838 | } |
| 1839 | |
| 1840 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1841 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1842 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1843 | request); |
| 1844 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1845 | request.subId, pair.first /*callingUid*/, |
| 1846 | pair.second /*request*/, onCompleted); |
| 1847 | break; |
| 1848 | } |
| 1849 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1850 | ar = (AsyncResult) msg.obj; |
| 1851 | request = (MainThreadRequest) ar.userObj; |
| 1852 | // request.result will be the exception of ar if present, true otherwise. |
| 1853 | // Be cautious not to leave result null which will wait() forever |
| 1854 | request.result = ar.exception != null ? ar.exception : true; |
| 1855 | notifyRequester(request); |
| 1856 | break; |
| 1857 | } |
| 1858 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1859 | request = (MainThreadRequest) msg.obj; |
| 1860 | |
| 1861 | Phone phone = getPhoneFromRequest(request); |
| 1862 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1863 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1864 | notifyRequester(request); |
| 1865 | break; |
| 1866 | } |
| 1867 | |
| 1868 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1869 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1870 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1871 | request); |
| 1872 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1873 | request.subId, pair.first /*callingUid*/, |
| 1874 | pair.second /*request*/, onCompleted); |
| 1875 | break; |
| 1876 | } |
| 1877 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1878 | ar = (AsyncResult) msg.obj; |
| 1879 | request = (MainThreadRequest) ar.userObj; |
| 1880 | request.result = ar.exception != null ? ar.exception : true; |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1884 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1885 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1886 | request = (MainThreadRequest) msg.obj; |
| 1887 | request.result = |
| 1888 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1889 | notifyRequester(request); |
| 1890 | break; |
| 1891 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1892 | default: |
| 1893 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1894 | break; |
| 1895 | } |
| 1896 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1897 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1898 | private void notifyRequester(MainThreadRequest request) { |
| 1899 | synchronized (request) { |
| 1900 | request.notifyAll(); |
| 1901 | } |
| 1902 | } |
| 1903 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1904 | private void handleNullReturnEvent(Message msg, String command) { |
| 1905 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1906 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1907 | if (ar.exception == null) { |
| 1908 | request.result = true; |
| 1909 | } else { |
| 1910 | request.result = false; |
| 1911 | if (ar.exception instanceof CommandException) { |
| 1912 | loge(command + ": CommandException: " + ar.exception); |
| 1913 | } else { |
| 1914 | loge(command + ": Unknown exception"); |
| 1915 | } |
| 1916 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1917 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | /** |
| 1922 | * Posts the specified command to be executed on the main thread, |
| 1923 | * waits for the request to complete, and returns the result. |
| 1924 | * @see #sendRequestAsync |
| 1925 | */ |
| 1926 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1927 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1928 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | /** |
| 1932 | * Posts the specified command to be executed on the main thread, |
| 1933 | * waits for the request to complete, and returns the result. |
| 1934 | * @see #sendRequestAsync |
| 1935 | */ |
| 1936 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1937 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1938 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | /** |
| 1942 | * Posts the specified command to be executed on the main thread, |
| 1943 | * waits for the request to complete, and returns the result. |
| 1944 | * @see #sendRequestAsync |
| 1945 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1946 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1947 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Posts the specified command to be executed on the main thread, |
| 1952 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1953 | * if not timeout or null otherwise. |
| 1954 | * @see #sendRequestAsync |
| 1955 | */ |
| 1956 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1957 | long timeoutInMs) { |
| 1958 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Posts the specified command to be executed on the main thread, |
| 1963 | * waits for the request to complete, and returns the result. |
| 1964 | * @see #sendRequestAsync |
| 1965 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1966 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1967 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * Posts the specified command to be executed on the main thread, |
| 1972 | * waits for the request to complete, and returns the result. |
| 1973 | * @see #sendRequestAsync |
| 1974 | */ |
| 1975 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1976 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1977 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1981 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1982 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1983 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1984 | * @see #sendRequestAsync |
| 1985 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1986 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1987 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1988 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1989 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1990 | } |
| 1991 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1992 | MainThreadRequest request = null; |
| 1993 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1994 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1995 | } else if (phone != null) { |
| 1996 | request = new MainThreadRequest(argument, phone, workSource); |
| 1997 | } else { |
| 1998 | request = new MainThreadRequest(argument, subId, workSource); |
| 1999 | } |
| 2000 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2002 | msg.sendToTarget(); |
| 2003 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2004 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2006 | if (timeoutInMs >= 0) { |
| 2007 | // Wait for at least timeoutInMs before returning null request result |
| 2008 | long now = SystemClock.elapsedRealtime(); |
| 2009 | long deadline = now + timeoutInMs; |
| 2010 | while (request == null && now < deadline) { |
| 2011 | try { |
| 2012 | request.wait(deadline - now); |
| 2013 | } catch (InterruptedException e) { |
| 2014 | // Do nothing, go back and check if request is completed or timeout |
| 2015 | } finally { |
| 2016 | now = SystemClock.elapsedRealtime(); |
| 2017 | } |
| 2018 | } |
| 2019 | } else { |
| 2020 | // Wait for the request to complete |
| 2021 | while (request.result == null) { |
| 2022 | try { |
| 2023 | request.wait(); |
| 2024 | } catch (InterruptedException e) { |
| 2025 | // Do nothing, go back and wait until the request is complete |
| 2026 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2030 | if (request.result == null) { |
| 2031 | Log.wtf(LOG_TAG, |
| 2032 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2033 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | return request.result; |
| 2035 | } |
| 2036 | |
| 2037 | /** |
| 2038 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2039 | * Posts the specified command to be executed on the main thread, and |
| 2040 | * returns immediately. |
| 2041 | * @see #sendRequest |
| 2042 | */ |
| 2043 | private void sendRequestAsync(int command) { |
| 2044 | mMainThreadHandler.sendEmptyMessage(command); |
| 2045 | } |
| 2046 | |
| 2047 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2048 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2049 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2050 | */ |
| 2051 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2052 | sendRequestAsync(command, argument, null, null); |
| 2053 | } |
| 2054 | |
| 2055 | /** |
| 2056 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2057 | * @see {@link #sendRequest(int,Object)} |
| 2058 | */ |
| 2059 | private void sendRequestAsync( |
| 2060 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2061 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2062 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2063 | msg.sendToTarget(); |
| 2064 | } |
| 2065 | |
| 2066 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2067 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2068 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2069 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2070 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | synchronized (PhoneInterfaceManager.class) { |
| 2072 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2073 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2074 | } else { |
| 2075 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2076 | } |
| 2077 | return sInstance; |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2082 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2085 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2086 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2088 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2089 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2090 | mTelephonySharedPreferences = |
| 2091 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2092 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2093 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2094 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2095 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2096 | publish(); |
| 2097 | } |
| 2098 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2099 | private Phone getDefaultPhone() { |
| 2100 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2101 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2102 | } |
| 2103 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2104 | private void publish() { |
| 2105 | if (DBG) log("publish: " + this); |
| 2106 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2107 | TelephonyFrameworkInitializer |
| 2108 | .getTelephonyServiceManager() |
| 2109 | .getTelephonyServiceRegisterer() |
| 2110 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2113 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2114 | if (request.phone != null) { |
| 2115 | return request.phone; |
| 2116 | } else { |
| 2117 | return getPhoneFromSubId(request.subId); |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | private Phone getPhoneFromSubId(int subId) { |
| 2122 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2123 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2124 | } |
| 2125 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2126 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2127 | Phone phone = getPhoneFromRequest(request); |
| 2128 | return phone == null ? null : |
| 2129 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2130 | } |
| 2131 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2132 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2133 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2134 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2135 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2136 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2137 | private void sendEraseModemConfig(Phone phone) { |
| 2138 | if (phone != null) { |
| 2139 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2140 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2141 | final long identity = Binder.clearCallingIdentity(); |
| 2142 | try { |
| 2143 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2144 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2145 | } finally { |
| 2146 | Binder.restoreCallingIdentity(identity); |
| 2147 | } |
| 2148 | } |
| 2149 | } |
| 2150 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2151 | private boolean isImsAvailableOnDevice() { |
| 2152 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2153 | if (pm == null) { |
| 2154 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2155 | // so do not throw error and allow. |
| 2156 | return true; |
| 2157 | } |
| 2158 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2159 | } |
| 2160 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2162 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2165 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | if (DBG) log("dial: " + number); |
| 2167 | // No permission check needed here: This is just a wrapper around the |
| 2168 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2169 | // the UI before it does anything. |
| 2170 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2171 | final long identity = Binder.clearCallingIdentity(); |
| 2172 | try { |
| 2173 | String url = createTelUrl(number); |
| 2174 | if (url == null) { |
| 2175 | return; |
| 2176 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2177 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2178 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2179 | PhoneConstants.State state = mCM.getState(subId); |
| 2180 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2181 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2182 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2183 | mApp.startActivity(intent); |
| 2184 | } |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2191 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2194 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | if (DBG) log("call: " + number); |
| 2196 | |
| 2197 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2198 | // need to do a permission check since we're calling startActivity() |
| 2199 | // from the context of the phone app. |
| 2200 | enforceCallPermission(); |
| 2201 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2202 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2203 | != AppOpsManager.MODE_ALLOWED) { |
| 2204 | return; |
| 2205 | } |
| 2206 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2207 | final long identity = Binder.clearCallingIdentity(); |
| 2208 | try { |
| 2209 | String url = createTelUrl(number); |
| 2210 | if (url == null) { |
| 2211 | return; |
| 2212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2214 | boolean isValid = false; |
| 2215 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2216 | if (slist != null) { |
| 2217 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2218 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2219 | isValid = true; |
| 2220 | break; |
| 2221 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2222 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2224 | if (!isValid) { |
| 2225 | return; |
| 2226 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2228 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2229 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2230 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2231 | mApp.startActivity(intent); |
| 2232 | } finally { |
| 2233 | Binder.restoreCallingIdentity(identity); |
| 2234 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2237 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2238 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2239 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2240 | } |
| 2241 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2242 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2243 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2244 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2245 | } |
| 2246 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2247 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2249 | |
| 2250 | final long identity = Binder.clearCallingIdentity(); |
| 2251 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2252 | Phone phone = getPhone(subId); |
| 2253 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2254 | checkSimPin.start(); |
| 2255 | return checkSimPin.unlockSim(null, pin); |
| 2256 | } finally { |
| 2257 | Binder.restoreCallingIdentity(identity); |
| 2258 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2261 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2263 | |
| 2264 | final long identity = Binder.clearCallingIdentity(); |
| 2265 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2266 | Phone phone = getPhone(subId); |
| 2267 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2268 | checkSimPuk.start(); |
| 2269 | return checkSimPuk.unlockSim(puk, pin); |
| 2270 | } finally { |
| 2271 | Binder.restoreCallingIdentity(identity); |
| 2272 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2276 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | * a synchronous one. |
| 2278 | */ |
| 2279 | private static class UnlockSim extends Thread { |
| 2280 | |
| 2281 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2282 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2283 | |
| 2284 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2285 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2286 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | |
| 2288 | // For replies from SimCard interface |
| 2289 | private Handler mHandler; |
| 2290 | |
| 2291 | // For async handler to identify request type |
| 2292 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2293 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2294 | UnlockSim(int phoneId, IccCard simCard) { |
| 2295 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2296 | mSimCard = simCard; |
| 2297 | } |
| 2298 | |
| 2299 | @Override |
| 2300 | public void run() { |
| 2301 | Looper.prepare(); |
| 2302 | synchronized (UnlockSim.this) { |
| 2303 | mHandler = new Handler() { |
| 2304 | @Override |
| 2305 | public void handleMessage(Message msg) { |
| 2306 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2307 | switch (msg.what) { |
| 2308 | case SUPPLY_PIN_COMPLETE: |
| 2309 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2310 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2311 | mRetryCount = msg.arg1; |
| 2312 | if (ar.exception != null) { |
| 2313 | if (ar.exception instanceof CommandException && |
| 2314 | ((CommandException)(ar.exception)).getCommandError() |
| 2315 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2316 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2317 | } //When UiccCardApp dispose,handle message and return exception |
| 2318 | else if (ar.exception instanceof CommandException && |
| 2319 | ((CommandException) (ar.exception)).getCommandError() |
| 2320 | == CommandException.Error.ABORTED) { |
| 2321 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2322 | } else { |
| 2323 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2324 | } |
| 2325 | } else { |
| 2326 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | mDone = true; |
| 2329 | UnlockSim.this.notifyAll(); |
| 2330 | } |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | }; |
| 2335 | UnlockSim.this.notifyAll(); |
| 2336 | } |
| 2337 | Looper.loop(); |
| 2338 | } |
| 2339 | |
| 2340 | /* |
| 2341 | * Use PIN or PUK to unlock SIM card |
| 2342 | * |
| 2343 | * If PUK is null, unlock SIM card with PIN |
| 2344 | * |
| 2345 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2346 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2347 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | |
| 2349 | while (mHandler == null) { |
| 2350 | try { |
| 2351 | wait(); |
| 2352 | } catch (InterruptedException e) { |
| 2353 | Thread.currentThread().interrupt(); |
| 2354 | } |
| 2355 | } |
| 2356 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2357 | |
| 2358 | if (puk == null) { |
| 2359 | mSimCard.supplyPin(pin, callback); |
| 2360 | } else { |
| 2361 | mSimCard.supplyPuk(puk, pin, callback); |
| 2362 | } |
| 2363 | |
| 2364 | while (!mDone) { |
| 2365 | try { |
| 2366 | Log.d(LOG_TAG, "wait for done"); |
| 2367 | wait(); |
| 2368 | } catch (InterruptedException e) { |
| 2369 | // Restore the interrupted status |
| 2370 | Thread.currentThread().interrupt(); |
| 2371 | } |
| 2372 | } |
| 2373 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2374 | int[] resultArray = new int[2]; |
| 2375 | resultArray[0] = mResult; |
| 2376 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2377 | |
| 2378 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2379 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2380 | } |
| 2381 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2382 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | } |
| 2384 | } |
| 2385 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2386 | /** |
| 2387 | * This method has been removed due to privacy and stability concerns. |
| 2388 | */ |
| 2389 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2391 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2392 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2395 | @Override |
| 2396 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2397 | mApp.getSystemService(AppOpsManager.class) |
| 2398 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2399 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2400 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2401 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2402 | // Callers targeting S have no business invoking this method. |
| 2403 | return; |
| 2404 | } |
| 2405 | |
| 2406 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2407 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2408 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2409 | .setCallingPackage(callingPackage) |
| 2410 | .setCallingFeatureId(null) |
| 2411 | .setCallingPid(Binder.getCallingPid()) |
| 2412 | .setCallingUid(Binder.getCallingUid()) |
| 2413 | .setMethod("updateServiceLocation") |
| 2414 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2415 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2416 | .build()); |
| 2417 | // Apps that lack location permission have no business calling this method; |
| 2418 | // however, because no permission was declared in the public API, denials must |
| 2419 | // all be "soft". |
| 2420 | switch (locationResult) { |
| 2421 | case DENIED_HARD: /* fall through */ |
| 2422 | case DENIED_SOFT: |
| 2423 | return; |
| 2424 | } |
| 2425 | |
| 2426 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2429 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2430 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2431 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2432 | } |
| 2433 | } finally { |
| 2434 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2438 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2439 | @Override |
| 2440 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2441 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2444 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2445 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2446 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2447 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2448 | callingFeatureId); |
| 2449 | } |
| 2450 | |
| 2451 | @Deprecated |
| 2452 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2453 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2454 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2455 | } |
| 2456 | |
| 2457 | @Override |
| 2458 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2459 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2461 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2462 | return false; |
| 2463 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | |
| 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
| 2467 | return isRadioOnForSubscriber(subId); |
| 2468 | } finally { |
| 2469 | Binder.restoreCallingIdentity(identity); |
| 2470 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | final long identity = Binder.clearCallingIdentity(); |
| 2475 | try { |
| 2476 | final Phone phone = getPhone(subId); |
| 2477 | if (phone != null) { |
| 2478 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2479 | } else { |
| 2480 | return false; |
| 2481 | } |
| 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
| 2487 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2488 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2490 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2491 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | |
| 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
| 2496 | final Phone phone = getPhone(subId); |
| 2497 | if (phone != null) { |
| 2498 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2499 | } |
| 2500 | } finally { |
| 2501 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2502 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2506 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2507 | } |
| 2508 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2509 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | final Phone phone = getPhone(subId); |
| 2515 | if (phone == null) { |
| 2516 | return false; |
| 2517 | } |
| 2518 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2519 | toggleRadioOnOffForSubscriber(subId); |
| 2520 | } |
| 2521 | return true; |
| 2522 | } finally { |
| 2523 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2526 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2527 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2528 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2529 | /* |
| 2530 | * If any of the Radios are available, it will need to be |
| 2531 | * shutdown. So return true if any Radio is available. |
| 2532 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | final long identity = Binder.clearCallingIdentity(); |
| 2534 | try { |
| 2535 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2536 | Phone phone = PhoneFactory.getPhone(i); |
| 2537 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2538 | } |
| 2539 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2540 | return false; |
| 2541 | } finally { |
| 2542 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2543 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2546 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2547 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | enforceModifyPermission(); |
| 2549 | |
| 2550 | final long identity = Binder.clearCallingIdentity(); |
| 2551 | try { |
| 2552 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2553 | logv("Shutting down Phone " + i); |
| 2554 | shutdownRadioUsingPhoneId(i); |
| 2555 | } |
| 2556 | } finally { |
| 2557 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2562 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2563 | if (phone != null && phone.isRadioAvailable()) { |
| 2564 | phone.shutdownRadio(); |
| 2565 | } |
| 2566 | } |
| 2567 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2569 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2570 | |
| 2571 | final long identity = Binder.clearCallingIdentity(); |
| 2572 | try { |
| 2573 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2574 | if (defaultPhone != null) { |
| 2575 | defaultPhone.setRadioPower(turnOn); |
| 2576 | return true; |
| 2577 | } else { |
| 2578 | loge("There's no default phone."); |
| 2579 | return false; |
| 2580 | } |
| 2581 | } finally { |
| 2582 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2583 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2586 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2587 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2588 | |
| 2589 | final long identity = Binder.clearCallingIdentity(); |
| 2590 | try { |
| 2591 | final Phone phone = getPhone(subId); |
| 2592 | if (phone != null) { |
| 2593 | phone.setRadioPower(turnOn); |
| 2594 | return true; |
| 2595 | } else { |
| 2596 | return false; |
| 2597 | } |
| 2598 | } finally { |
| 2599 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2600 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | } |
| 2602 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2603 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2604 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2605 | public boolean enableDataConnectivity() { |
| 2606 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | |
| 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2611 | final Phone phone = getPhone(subId); |
| 2612 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2613 | phone.getDataEnabledSettings().setDataEnabled( |
| 2614 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2615 | return true; |
| 2616 | } else { |
| 2617 | return false; |
| 2618 | } |
| 2619 | } finally { |
| 2620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2624 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2625 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2626 | public boolean disableDataConnectivity() { |
| 2627 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2628 | |
| 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2632 | final Phone phone = getPhone(subId); |
| 2633 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2634 | phone.getDataEnabledSettings().setDataEnabled( |
| 2635 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2636 | return true; |
| 2637 | } else { |
| 2638 | return false; |
| 2639 | } |
| 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2645 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2646 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | final long identity = Binder.clearCallingIdentity(); |
| 2648 | try { |
| 2649 | final Phone phone = getPhone(subId); |
| 2650 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2651 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2652 | } else { |
| 2653 | return false; |
| 2654 | } |
| 2655 | } finally { |
| 2656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2661 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2664 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2665 | enforceCallPermission(); |
| 2666 | |
| 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
| 2669 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2670 | return; |
| 2671 | } |
| 2672 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2673 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2674 | } finally { |
| 2675 | Binder.restoreCallingIdentity(identity); |
| 2676 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2677 | }; |
| 2678 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2679 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | |
| 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2685 | return false; |
| 2686 | } |
| 2687 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2694 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2697 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2698 | final long identity = Binder.clearCallingIdentity(); |
| 2699 | try { |
| 2700 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2701 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2702 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2703 | } finally { |
| 2704 | Binder.restoreCallingIdentity(identity); |
| 2705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2708 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2709 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2710 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2711 | } |
| 2712 | |
| 2713 | @Override |
| 2714 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2717 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | if (phone != null) { |
| 2719 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2720 | } else { |
| 2721 | return PhoneConstantConversions.convertDataState( |
| 2722 | PhoneConstants.DataState.DISCONNECTED); |
| 2723 | } |
| 2724 | } finally { |
| 2725 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | } |
| 2728 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2729 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2730 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2731 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2732 | } |
| 2733 | |
| 2734 | @Override |
| 2735 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2736 | final long identity = Binder.clearCallingIdentity(); |
| 2737 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2738 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2739 | if (phone != null) { |
| 2740 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2741 | } else { |
| 2742 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2743 | } |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2750 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2751 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2752 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2753 | |
| 2754 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2755 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2756 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2757 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2758 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2759 | .setCallingPid(Binder.getCallingPid()) |
| 2760 | .setCallingUid(Binder.getCallingUid()) |
| 2761 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2762 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2763 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2764 | .build()); |
| 2765 | switch (locationResult) { |
| 2766 | case DENIED_HARD: |
| 2767 | throw new SecurityException("Not allowed to access cell location"); |
| 2768 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2769 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2770 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2773 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | final long identity = Binder.clearCallingIdentity(); |
| 2775 | try { |
| 2776 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2777 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2778 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | } finally { |
| 2780 | Binder.restoreCallingIdentity(identity); |
| 2781 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2784 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2785 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2786 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2787 | // registered cell info, so return a NULL country instead. |
| 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2790 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2791 | // Get default phone in this case. |
| 2792 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2793 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2794 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2795 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2796 | if (phone == null) return ""; |
| 2797 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2798 | if (sst == null) return ""; |
| 2799 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2800 | if (lt == null) return ""; |
| 2801 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2802 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2803 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2804 | } finally { |
| 2805 | Binder.restoreCallingIdentity(identity); |
| 2806 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2809 | /** |
| 2810 | * This method was removed due to potential issues caused by performing partial |
| 2811 | * updates of service state, and lack of a credible use case. |
| 2812 | * |
| 2813 | * This has the ability to break the telephony implementation by disabling notification of |
| 2814 | * changes in device connectivity. DO NOT USE THIS! |
| 2815 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2816 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | public void enableLocationUpdates() { |
| 2818 | mApp.enforceCallingOrSelfPermission( |
| 2819 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2822 | /** |
| 2823 | * This method was removed due to potential issues caused by performing partial |
| 2824 | * updates of service state, and lack of a credible use case. |
| 2825 | * |
| 2826 | * This has the ability to break the telephony implementation by disabling notification of |
| 2827 | * changes in device connectivity. DO NOT USE THIS! |
| 2828 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2829 | @Override |
| 2830 | public void disableLocationUpdates() { |
| 2831 | mApp.enforceCallingOrSelfPermission( |
| 2832 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | @Override |
| 2836 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2837 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2838 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2839 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2840 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2841 | throw new SecurityException( |
| 2842 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2843 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2844 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2845 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2847 | return null; |
| 2848 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2849 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2850 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2852 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2853 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2854 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2855 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2856 | for (CellInfo ci : info) { |
| 2857 | if (ci instanceof CellInfoGsm) { |
| 2858 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2859 | } else if (ci instanceof CellInfoWcdma) { |
| 2860 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2861 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2863 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2866 | private List<CellInfo> getCachedCellInfo() { |
| 2867 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2868 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2869 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2870 | if (info != null) cellInfos.addAll(info); |
| 2871 | } |
| 2872 | return cellInfos; |
| 2873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2874 | |
| 2875 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2876 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2877 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2878 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2879 | |
| 2880 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2881 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2882 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2883 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2884 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2885 | .setCallingPid(Binder.getCallingPid()) |
| 2886 | .setCallingUid(Binder.getCallingUid()) |
| 2887 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2888 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2889 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2890 | .build()); |
| 2891 | switch (locationResult) { |
| 2892 | case DENIED_HARD: |
| 2893 | throw new SecurityException("Not allowed to access cell info"); |
| 2894 | case DENIED_SOFT: |
| 2895 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2898 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2899 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2900 | return getCachedCellInfo(); |
| 2901 | } |
| 2902 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2903 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2904 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2905 | final long identity = Binder.clearCallingIdentity(); |
| 2906 | try { |
| 2907 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2908 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2909 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2910 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | if (info != null) cellInfos.addAll(info); |
| 2912 | } |
| 2913 | return cellInfos; |
| 2914 | } finally { |
| 2915 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2916 | } |
| 2917 | } |
| 2918 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2919 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2920 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2921 | String callingFeatureId) { |
| 2922 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2923 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2927 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2928 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2929 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2930 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2931 | } |
| 2932 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2933 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2934 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2935 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2936 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2937 | |
| 2938 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2939 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2940 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2941 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2942 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2943 | .setCallingPid(Binder.getCallingPid()) |
| 2944 | .setCallingUid(Binder.getCallingUid()) |
| 2945 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2946 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2947 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2948 | .build()); |
| 2949 | switch (locationResult) { |
| 2950 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2951 | if (TelephonyPermissions |
| 2952 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2953 | // Safetynet logging for b/154934934 |
| 2954 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2955 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2956 | throw new SecurityException("Not allowed to access cell info"); |
| 2957 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2958 | if (TelephonyPermissions |
| 2959 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2960 | // Safetynet logging for b/154934934 |
| 2961 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2962 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2963 | try { |
| 2964 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2965 | } catch (RemoteException re) { |
| 2966 | // Drop without consequences |
| 2967 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2968 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2971 | |
| 2972 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2973 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2974 | |
| 2975 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2976 | } |
| 2977 | |
| 2978 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2979 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2980 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2981 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | |
| 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2985 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | } finally { |
| 2987 | Binder.restoreCallingIdentity(identity); |
| 2988 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | } |
| 2990 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2991 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2992 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2993 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2994 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2995 | return null; |
| 2996 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2997 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2998 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2999 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3000 | return null; |
| 3001 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | |
| 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | return phone.getImei(); |
| 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(identity); |
| 3008 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3012 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3013 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3014 | String tac = null; |
| 3015 | if (phone != null) { |
| 3016 | String imei = phone.getImei(); |
| 3017 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3018 | } |
| 3019 | return tac; |
| 3020 | } |
| 3021 | |
| 3022 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3023 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3024 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3025 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3026 | return null; |
| 3027 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3028 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3029 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3030 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3031 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3032 | return null; |
| 3033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3034 | |
| 3035 | final long identity = Binder.clearCallingIdentity(); |
| 3036 | try { |
| 3037 | return phone.getMeid(); |
| 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
| 3040 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3044 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3045 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3046 | String manufacturerCode = null; |
| 3047 | if (phone != null) { |
| 3048 | String meid = phone.getMeid(); |
| 3049 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3050 | } |
| 3051 | return manufacturerCode; |
| 3052 | } |
| 3053 | |
| 3054 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3055 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3056 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3057 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3058 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3059 | return null; |
| 3060 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3061 | int subId = phone.getSubId(); |
| 3062 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3063 | mApp, subId, callingPackage, callingFeatureId, |
| 3064 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3065 | return null; |
| 3066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3067 | |
| 3068 | final long identity = Binder.clearCallingIdentity(); |
| 3069 | try { |
| 3070 | return phone.getDeviceSvn(); |
| 3071 | } finally { |
| 3072 | Binder.restoreCallingIdentity(identity); |
| 3073 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3076 | @Override |
| 3077 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | final long identity = Binder.clearCallingIdentity(); |
| 3079 | try { |
| 3080 | final Phone phone = getPhone(subId); |
| 3081 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3082 | } finally { |
| 3083 | Binder.restoreCallingIdentity(identity); |
| 3084 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | @Override |
| 3088 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | final long identity = Binder.clearCallingIdentity(); |
| 3090 | try { |
| 3091 | final Phone phone = getPhone(subId); |
| 3092 | return phone == null ? null : phone.getCarrierName(); |
| 3093 | } finally { |
| 3094 | Binder.restoreCallingIdentity(identity); |
| 3095 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3096 | } |
| 3097 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3098 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3099 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3100 | final long identity = Binder.clearCallingIdentity(); |
| 3101 | try { |
| 3102 | final Phone phone = getPhone(subId); |
| 3103 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3104 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3105 | } finally { |
| 3106 | Binder.restoreCallingIdentity(identity); |
| 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3111 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
| 3114 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3115 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3116 | } finally { |
| 3117 | Binder.restoreCallingIdentity(identity); |
| 3118 | } |
| 3119 | } |
| 3120 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3121 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3122 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3123 | if (!isSubscriptionMccMnc) { |
| 3124 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3125 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3126 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3127 | if (phone == null) { |
| 3128 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3129 | } |
| 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
| 3132 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(identity); |
| 3135 | } |
| 3136 | } |
| 3137 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3138 | // |
| 3139 | // Internal helper methods. |
| 3140 | // |
| 3141 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3142 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3143 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3144 | * |
| 3145 | * @throws SecurityException if the caller does not have the required permission |
| 3146 | */ |
| 3147 | private void enforceModifyPermission() { |
| 3148 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3149 | } |
| 3150 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3151 | /** |
| 3152 | * Make sure the caller is system. |
| 3153 | * |
| 3154 | * @throws SecurityException if the caller is not system. |
| 3155 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3156 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3157 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3158 | throw new SecurityException("Caller must be system"); |
| 3159 | } |
| 3160 | } |
| 3161 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3162 | private void enforceActiveEmergencySessionPermission() { |
| 3163 | mApp.enforceCallingOrSelfPermission( |
| 3164 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3165 | } |
| 3166 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3167 | /** |
| 3168 | * Make sure the caller has the CALL_PHONE permission. |
| 3169 | * |
| 3170 | * @throws SecurityException if the caller does not have the required permission |
| 3171 | */ |
| 3172 | private void enforceCallPermission() { |
| 3173 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3174 | } |
| 3175 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3176 | private void enforceSettingsPermission() { |
| 3177 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3180 | private void enforceRebootPermission() { |
| 3181 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3182 | } |
| 3183 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3184 | private String createTelUrl(String number) { |
| 3185 | if (TextUtils.isEmpty(number)) { |
| 3186 | return null; |
| 3187 | } |
| 3188 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3189 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3192 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3193 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3194 | } |
| 3195 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3196 | private static void logv(String msg) { |
| 3197 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3198 | } |
| 3199 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3200 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3202 | } |
| 3203 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3204 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3206 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3209 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3210 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | final long identity = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3214 | if (phone == null) { |
| 3215 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3216 | } else { |
| 3217 | return phone.getPhoneType(); |
| 3218 | } |
| 3219 | } finally { |
| 3220 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3221 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | /** |
| 3225 | * Returns the CDMA ERI icon index to display |
| 3226 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3227 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3228 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3229 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3230 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3233 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3234 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3235 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3237 | mApp, subId, callingPackage, callingFeatureId, |
| 3238 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3239 | return -1; |
| 3240 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3241 | |
| 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
| 3244 | final Phone phone = getPhone(subId); |
| 3245 | if (phone != null) { |
| 3246 | return phone.getCdmaEriIconIndex(); |
| 3247 | } else { |
| 3248 | return -1; |
| 3249 | } |
| 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | /** |
| 3256 | * Returns the CDMA ERI icon mode, |
| 3257 | * 0 - ON |
| 3258 | * 1 - FLASHING |
| 3259 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3260 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3261 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3262 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3263 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3266 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3267 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3268 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3269 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3270 | mApp, subId, callingPackage, callingFeatureId, |
| 3271 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3272 | return -1; |
| 3273 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | |
| 3275 | final long identity = Binder.clearCallingIdentity(); |
| 3276 | try { |
| 3277 | final Phone phone = getPhone(subId); |
| 3278 | if (phone != null) { |
| 3279 | return phone.getCdmaEriIconMode(); |
| 3280 | } else { |
| 3281 | return -1; |
| 3282 | } |
| 3283 | } finally { |
| 3284 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | /** |
| 3289 | * Returns the CDMA ERI text, |
| 3290 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3291 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3292 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3293 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3294 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3297 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3298 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3299 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3300 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3301 | mApp, subId, callingPackage, callingFeatureId, |
| 3302 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3303 | return null; |
| 3304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3305 | |
| 3306 | final long identity = Binder.clearCallingIdentity(); |
| 3307 | try { |
| 3308 | final Phone phone = getPhone(subId); |
| 3309 | if (phone != null) { |
| 3310 | return phone.getCdmaEriText(); |
| 3311 | } else { |
| 3312 | return null; |
| 3313 | } |
| 3314 | } finally { |
| 3315 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3316 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3320 | * Returns the CDMA MDN. |
| 3321 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3322 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3323 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3325 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | |
| 3327 | final long identity = Binder.clearCallingIdentity(); |
| 3328 | try { |
| 3329 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3330 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | return phone.getLine1Number(); |
| 3332 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3333 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | return null; |
| 3335 | } |
| 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | /** |
| 3342 | * Returns the CDMA MIN. |
| 3343 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3344 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3345 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3347 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3348 | |
| 3349 | final long identity = Binder.clearCallingIdentity(); |
| 3350 | try { |
| 3351 | final Phone phone = getPhone(subId); |
| 3352 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3353 | return phone.getCdmaMin(); |
| 3354 | } else { |
| 3355 | return null; |
| 3356 | } |
| 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3359 | } |
| 3360 | } |
| 3361 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3362 | @Override |
| 3363 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3364 | INumberVerificationCallback callback, String callingPackage) { |
| 3365 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3366 | != PERMISSION_GRANTED) { |
| 3367 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3368 | } |
| 3369 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3370 | |
| 3371 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3372 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3373 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3374 | + "calling package: " + callingPackage |
| 3375 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | if (range == null) { |
| 3379 | throw new NullPointerException("Range must be non-null"); |
| 3380 | } |
| 3381 | |
| 3382 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3383 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3384 | |
| 3385 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3386 | } |
| 3387 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3388 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3389 | * Returns true if CDMA provisioning needs to run. |
| 3390 | */ |
| 3391 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | final long identity = Binder.clearCallingIdentity(); |
| 3393 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3394 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3395 | } finally { |
| 3396 | Binder.restoreCallingIdentity(identity); |
| 3397 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
| 3400 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3401 | * Sets the voice mail number of a given subId. |
| 3402 | */ |
| 3403 | @Override |
| 3404 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3405 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3406 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3411 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3412 | return success; |
| 3413 | } finally { |
| 3414 | Binder.restoreCallingIdentity(identity); |
| 3415 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3416 | } |
| 3417 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3418 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3419 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3420 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3421 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3422 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3423 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3424 | throw new SecurityException("caller must be system dialer"); |
| 3425 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3426 | |
| 3427 | final long identity = Binder.clearCallingIdentity(); |
| 3428 | try { |
| 3429 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3430 | if (phoneAccountHandle == null) { |
| 3431 | return null; |
| 3432 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3433 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3434 | } finally { |
| 3435 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3436 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3440 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3441 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3442 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3443 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3444 | mApp, subId, callingPackage, callingFeatureId, |
| 3445 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3446 | return null; |
| 3447 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3451 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(identity); |
| 3454 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3458 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3459 | VisualVoicemailSmsFilterSettings settings) { |
| 3460 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | |
| 3462 | final long identity = Binder.clearCallingIdentity(); |
| 3463 | try { |
| 3464 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3465 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3466 | } finally { |
| 3467 | Binder.restoreCallingIdentity(identity); |
| 3468 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3472 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3473 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | |
| 3475 | final long identity = Binder.clearCallingIdentity(); |
| 3476 | try { |
| 3477 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3478 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
| 3481 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3482 | } |
| 3483 | |
| 3484 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3485 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3486 | String callingPackage, int subId) { |
| 3487 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | |
| 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
| 3491 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3492 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(identity); |
| 3495 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3499 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3500 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3501 | |
| 3502 | final long identity = Binder.clearCallingIdentity(); |
| 3503 | try { |
| 3504 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3505 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3512 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3513 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3514 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3515 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3516 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3517 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3518 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3519 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3520 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3521 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3522 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3523 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3524 | * Sets the voice activation state of a given subId. |
| 3525 | */ |
| 3526 | @Override |
| 3527 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3529 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3530 | |
| 3531 | final long identity = Binder.clearCallingIdentity(); |
| 3532 | try { |
| 3533 | final Phone phone = getPhone(subId); |
| 3534 | if (phone != null) { |
| 3535 | phone.setVoiceActivationState(activationState); |
| 3536 | } else { |
| 3537 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3538 | } |
| 3539 | } finally { |
| 3540 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | /** |
| 3545 | * Sets the data activation state of a given subId. |
| 3546 | */ |
| 3547 | @Override |
| 3548 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3549 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3550 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | |
| 3552 | final long identity = Binder.clearCallingIdentity(); |
| 3553 | try { |
| 3554 | final Phone phone = getPhone(subId); |
| 3555 | if (phone != null) { |
| 3556 | phone.setDataActivationState(activationState); |
| 3557 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3558 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | } |
| 3560 | } finally { |
| 3561 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3562 | } |
| 3563 | } |
| 3564 | |
| 3565 | /** |
| 3566 | * Returns the voice activation state of a given subId. |
| 3567 | */ |
| 3568 | @Override |
| 3569 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3570 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3571 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3572 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3573 | final long identity = Binder.clearCallingIdentity(); |
| 3574 | try { |
| 3575 | if (phone != null) { |
| 3576 | return phone.getVoiceActivationState(); |
| 3577 | } else { |
| 3578 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3579 | } |
| 3580 | } finally { |
| 3581 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * Returns the data activation state of a given subId. |
| 3587 | */ |
| 3588 | @Override |
| 3589 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3590 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3591 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3592 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | if (phone != null) { |
| 3596 | return phone.getDataActivationState(); |
| 3597 | } else { |
| 3598 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3599 | } |
| 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3606 | * Returns the unread count of voicemails for a subId |
| 3607 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3608 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3609 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3610 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3612 | mApp, subId, callingPackage, callingFeatureId, |
| 3613 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3614 | return 0; |
| 3615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | final Phone phone = getPhone(subId); |
| 3619 | if (phone != null) { |
| 3620 | return phone.getVoiceMessageCount(); |
| 3621 | } else { |
| 3622 | return 0; |
| 3623 | } |
| 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3626 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3630 | * returns true, if the device is in a state where both voice and data |
| 3631 | * are supported simultaneously. This can change based on location or network condition. |
| 3632 | */ |
| 3633 | @Override |
| 3634 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3635 | final long identity = Binder.clearCallingIdentity(); |
| 3636 | try { |
| 3637 | final Phone phone = getPhone(subId); |
| 3638 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3639 | } finally { |
| 3640 | Binder.restoreCallingIdentity(identity); |
| 3641 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3645 | * Send the dialer code if called from the current default dialer or the caller has |
| 3646 | * carrier privilege. |
| 3647 | * @param inputCode The dialer code to send |
| 3648 | */ |
| 3649 | @Override |
| 3650 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3651 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3652 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3653 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3654 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3655 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3656 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3657 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | |
| 3660 | final long identity = Binder.clearCallingIdentity(); |
| 3661 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3662 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3666 | } |
| 3667 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3668 | @Override |
| 3669 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3670 | TelephonyPermissions |
| 3671 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3672 | mApp, subId, "getNetworkSelectionMode"); |
| 3673 | final long identity = Binder.clearCallingIdentity(); |
| 3674 | try { |
| 3675 | if (!isActiveSubscription(subId)) { |
| 3676 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3677 | } |
| 3678 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3679 | } finally { |
| 3680 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3681 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3684 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3685 | public boolean isInEmergencySmsMode() { |
| 3686 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3690 | if (phone.isInEmergencySmsMode()) { |
| 3691 | return true; |
| 3692 | } |
| 3693 | } |
| 3694 | } finally { |
| 3695 | Binder.restoreCallingIdentity(identity); |
| 3696 | } |
| 3697 | return false; |
| 3698 | } |
| 3699 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3700 | /** |
| 3701 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3702 | * @param subId The subscription to use to check the configuration. |
| 3703 | * @param c The callback that will be used to send the result. |
| 3704 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3705 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3706 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3707 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3708 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3709 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3710 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3711 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3712 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3713 | "IMS not available on device."); |
| 3714 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | final long token = Binder.clearCallingIdentity(); |
| 3716 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3717 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3718 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3719 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3720 | } catch (ImsException e) { |
| 3721 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3722 | } finally { |
| 3723 | Binder.restoreCallingIdentity(token); |
| 3724 | } |
| 3725 | } |
| 3726 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3727 | /** |
| 3728 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3729 | * @param subId The subscription to use to check the configuration. |
| 3730 | * @param c The callback that will be used to send the result. |
| 3731 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3732 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3733 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3734 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3735 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3736 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3737 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3738 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3739 | final long token = Binder.clearCallingIdentity(); |
| 3740 | try { |
| 3741 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3742 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3743 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3744 | } catch (ImsException e) { |
| 3745 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3746 | + "is inactive, ignoring unregister."); |
| 3747 | // If the subscription is no longer active, just return, since the callback |
| 3748 | // will already have been removed internally. |
| 3749 | } finally { |
| 3750 | Binder.restoreCallingIdentity(token); |
| 3751 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3754 | /** |
| 3755 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3756 | */ |
| 3757 | @Override |
| 3758 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3759 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3760 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3762 | "IMS not available on device."); |
| 3763 | } |
| 3764 | final long token = Binder.clearCallingIdentity(); |
| 3765 | try { |
| 3766 | Phone phone = getPhone(subId); |
| 3767 | if (phone == null) { |
| 3768 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3769 | + subId + "'"); |
| 3770 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3771 | } |
| 3772 | phone.getImsRegistrationState(regState -> { |
| 3773 | try { |
| 3774 | consumer.accept((regState == null) |
| 3775 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3776 | } catch (RemoteException e) { |
| 3777 | // Ignore if the remote process is no longer available to call back. |
| 3778 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3779 | } |
| 3780 | }); |
| 3781 | } finally { |
| 3782 | Binder.restoreCallingIdentity(token); |
| 3783 | } |
| 3784 | } |
| 3785 | |
| 3786 | /** |
| 3787 | * Get the transport type for the IMS service registration state. |
| 3788 | */ |
| 3789 | @Override |
| 3790 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3791 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3792 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3793 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3794 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3795 | "IMS not available on device."); |
| 3796 | } |
| 3797 | final long token = Binder.clearCallingIdentity(); |
| 3798 | try { |
| 3799 | Phone phone = getPhone(subId); |
| 3800 | if (phone == null) { |
| 3801 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3802 | + subId + "'"); |
| 3803 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3804 | } |
| 3805 | phone.getImsRegistrationTech(regTech -> { |
| 3806 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3807 | int regTechConverted = (regTech == null) |
| 3808 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3809 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3810 | regTechConverted); |
| 3811 | try { |
| 3812 | consumer.accept(regTechConverted); |
| 3813 | } catch (RemoteException e) { |
| 3814 | // Ignore if the remote process is no longer available to call back. |
| 3815 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3816 | } |
| 3817 | }); |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(token); |
| 3820 | } |
| 3821 | } |
| 3822 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3823 | /** |
| 3824 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3825 | * @param subId The subscription to use to check the configuration. |
| 3826 | * @param c The callback that will be used to send the result. |
| 3827 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3828 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3829 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3830 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3831 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3832 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3833 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3834 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3835 | "IMS not available on device."); |
| 3836 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3837 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3838 | final long token = Binder.clearCallingIdentity(); |
| 3839 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3840 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3841 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3842 | } catch (ImsException e) { |
| 3843 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(token); |
| 3846 | } |
| 3847 | } |
| 3848 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3849 | /** |
| 3850 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3851 | * @param subId The subscription to use to check the configuration. |
| 3852 | * @param c The callback that will be used to send the result. |
| 3853 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3855 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3856 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3857 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3858 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3859 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3860 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3861 | |
| 3862 | final long token = Binder.clearCallingIdentity(); |
| 3863 | try { |
| 3864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3865 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3866 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3867 | } catch (ImsException e) { |
| 3868 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3869 | + "is inactive, ignoring unregister."); |
| 3870 | // If the subscription is no longer active, just return, since the callback |
| 3871 | // will already have been removed internally. |
| 3872 | } finally { |
| 3873 | Binder.restoreCallingIdentity(token); |
| 3874 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3878 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3879 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3881 | final long token = Binder.clearCallingIdentity(); |
| 3882 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3883 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3885 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3886 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3887 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3888 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3889 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3890 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3891 | } finally { |
| 3892 | Binder.restoreCallingIdentity(token); |
| 3893 | } |
| 3894 | } |
| 3895 | |
| 3896 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3897 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3898 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3899 | final long token = Binder.clearCallingIdentity(); |
| 3900 | try { |
| 3901 | Phone phone = getPhone(subId); |
| 3902 | if (phone == null) return false; |
| 3903 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3904 | } catch (com.android.ims.ImsException e) { |
| 3905 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3906 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | } finally { |
| 3908 | Binder.restoreCallingIdentity(token); |
| 3909 | } |
| 3910 | } |
| 3911 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3912 | /** |
| 3913 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3914 | * subscription. |
| 3915 | * @param subId The subscription to use to check the configuration. |
| 3916 | * @param callback The callback that will be used to send the result. |
| 3917 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3918 | * @param transportType The transport type of the MmTelFeature capability. |
| 3919 | */ |
| 3920 | @Override |
| 3921 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3922 | int transportType) { |
| 3923 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3924 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3925 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3926 | "IMS not available on device."); |
| 3927 | } |
| 3928 | final long token = Binder.clearCallingIdentity(); |
| 3929 | try { |
| 3930 | int slotId = getSlotIndex(subId); |
| 3931 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3932 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3933 | + subId + "'"); |
| 3934 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3935 | } |
| 3936 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3937 | transportType, aBoolean -> { |
| 3938 | try { |
| 3939 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3940 | } catch (RemoteException e) { |
| 3941 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3942 | + "running. Ignore"); |
| 3943 | } |
| 3944 | }); |
| 3945 | } finally { |
| 3946 | Binder.restoreCallingIdentity(token); |
| 3947 | } |
| 3948 | } |
| 3949 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3950 | /** |
| 3951 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3952 | * @param subId The subscription to use to check the configuration. |
| 3953 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3954 | @Override |
| 3955 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3956 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3957 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3958 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3960 | final long token = Binder.clearCallingIdentity(); |
| 3961 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3962 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3964 | } catch (ImsException e) { |
| 3965 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(token); |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3972 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3974 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3978 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3980 | } catch (ImsException e) { |
| 3981 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
| 3984 | } |
| 3985 | } |
| 3986 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3987 | /** |
| 3988 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3989 | * @param subId The subscription to use to check the configuration. |
| 3990 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3991 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3992 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3993 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3994 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3998 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3999 | } catch (ImsException e) { |
| 4000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4007 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4009 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4013 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4014 | } catch (ImsException e) { |
| 4015 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4016 | } finally { |
| 4017 | Binder.restoreCallingIdentity(identity); |
| 4018 | } |
| 4019 | } |
| 4020 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4021 | /** |
| 4022 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4023 | * @param subId The subscription to use to check the configuration. |
| 4024 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4025 | @Override |
| 4026 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4027 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4028 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
| 4031 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4032 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4033 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4034 | } catch (ImsException e) { |
| 4035 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(identity); |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4042 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4044 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4045 | final long identity = Binder.clearCallingIdentity(); |
| 4046 | try { |
| 4047 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4048 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4049 | } catch (ImsException e) { |
| 4050 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4051 | } finally { |
| 4052 | Binder.restoreCallingIdentity(identity); |
| 4053 | } |
| 4054 | } |
| 4055 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4056 | /** |
| 4057 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4058 | * @param subId The subscription to use to check the configuration. |
| 4059 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4060 | @Override |
| 4061 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4062 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4063 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4067 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4068 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4069 | } catch (ImsException e) { |
| 4070 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
| 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4077 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4079 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4080 | final long identity = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4083 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4085 | } catch (ImsException e) { |
| 4086 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | @Override |
| 4093 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4095 | "setVoWiFiNonPersistent"); |
| 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4099 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4100 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4101 | } catch (ImsException e) { |
| 4102 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
| 4105 | } |
| 4106 | } |
| 4107 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4108 | /** |
| 4109 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4110 | * @param subId The subscription to use to check the configuration. |
| 4111 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4112 | @Override |
| 4113 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4114 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4115 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4119 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4121 | } catch (ImsException e) { |
| 4122 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4123 | } finally { |
| 4124 | Binder.restoreCallingIdentity(identity); |
| 4125 | } |
| 4126 | } |
| 4127 | |
| 4128 | @Override |
| 4129 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4131 | "setVoWiFiModeSetting"); |
| 4132 | final long identity = Binder.clearCallingIdentity(); |
| 4133 | try { |
| 4134 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4135 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4136 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4137 | } catch (ImsException e) { |
| 4138 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | @Override |
| 4145 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4146 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4147 | final long identity = Binder.clearCallingIdentity(); |
| 4148 | try { |
| 4149 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4150 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4151 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4152 | } catch (ImsException e) { |
| 4153 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4154 | } finally { |
| 4155 | Binder.restoreCallingIdentity(identity); |
| 4156 | } |
| 4157 | } |
| 4158 | |
| 4159 | @Override |
| 4160 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4162 | "setVoWiFiRoamingModeSetting"); |
| 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
| 4165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4166 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4167 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4168 | } catch (ImsException e) { |
| 4169 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4170 | } finally { |
| 4171 | Binder.restoreCallingIdentity(identity); |
| 4172 | } |
| 4173 | } |
| 4174 | |
| 4175 | @Override |
| 4176 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4178 | "setRttCapabilityEnabled"); |
| 4179 | final long identity = Binder.clearCallingIdentity(); |
| 4180 | try { |
| 4181 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4182 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4183 | } catch (ImsException e) { |
| 4184 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
| 4187 | } |
| 4188 | } |
| 4189 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4190 | /** |
| 4191 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4192 | * @param subId The subscription to use to check the configuration. |
| 4193 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | @Override |
| 4195 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4196 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4197 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4201 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4203 | } catch (ImsException e) { |
| 4204 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
| 4207 | } |
| 4208 | } |
| 4209 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4210 | @Override |
| 4211 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4212 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4215 | if (!isImsAvailableOnDevice()) { |
| 4216 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4217 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4218 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4219 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4220 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4221 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4222 | } catch (ImsException e) { |
| 4223 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4224 | } finally { |
| 4225 | Binder.restoreCallingIdentity(identity); |
| 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | @Override |
| 4230 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4231 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4232 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4233 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4234 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4235 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4236 | try { |
| 4237 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4238 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4239 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4240 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4241 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4242 | + "is inactive, ignoring unregister."); |
| 4243 | // If the subscription is no longer active, just return, since the callback will already |
| 4244 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(identity); |
| 4247 | } |
| 4248 | } |
| 4249 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4250 | |
| 4251 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4252 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4253 | message); |
| 4254 | } |
| 4255 | |
| 4256 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4257 | boolean isMmtelCapability) { |
| 4258 | Phone phone = getPhone(subId); |
| 4259 | if (phone == null) { |
| 4260 | loge("phone instance null for subid " + subId); |
| 4261 | return false; |
| 4262 | } |
| 4263 | if (isMmtelCapability) { |
| 4264 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4265 | return false; |
| 4266 | } |
| 4267 | } else { |
| 4268 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4269 | return false; |
| 4270 | } |
| 4271 | } |
| 4272 | return true; |
| 4273 | } |
| 4274 | |
| 4275 | @Override |
| 4276 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4277 | boolean isProvisioned) { |
| 4278 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4279 | |
| 4280 | final long identity = Binder.clearCallingIdentity(); |
| 4281 | try { |
| 4282 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4283 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4284 | return; |
| 4285 | } |
| 4286 | |
| 4287 | // this capability requires provisioning, route to the correct API. |
| 4288 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4289 | switch (capability) { |
| 4290 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4291 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4292 | ims.setEabProvisioned(isProvisioned); |
| 4293 | break; |
| 4294 | default: { |
| 4295 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4296 | + "rcs capability '" + capability + "', which does not require " |
| 4297 | + "provisioning."); |
| 4298 | } |
| 4299 | } |
| 4300 | } finally { |
| 4301 | Binder.restoreCallingIdentity(identity); |
| 4302 | } |
| 4303 | |
| 4304 | } |
| 4305 | |
| 4306 | |
| 4307 | @Override |
| 4308 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4309 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
| 4312 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4313 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4314 | return true; |
| 4315 | } |
| 4316 | |
| 4317 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4318 | switch (capability) { |
| 4319 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4320 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4321 | return ims.isEabProvisionedOnDevice(); |
| 4322 | |
| 4323 | default: { |
| 4324 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4325 | + "capability '" + capability + "', which does not require " |
| 4326 | + "provisioning."); |
| 4327 | } |
| 4328 | } |
| 4329 | |
| 4330 | } finally { |
| 4331 | Binder.restoreCallingIdentity(identity); |
| 4332 | } |
| 4333 | } |
| 4334 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4335 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4336 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4337 | boolean isProvisioned) { |
| 4338 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4339 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4340 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4341 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4342 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
| 4345 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4346 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4347 | return; |
| 4348 | } |
| 4349 | |
| 4350 | // this capability requires provisioning, route to the correct API. |
| 4351 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4352 | switch (capability) { |
| 4353 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4354 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4355 | ims.setVolteProvisioned(isProvisioned); |
| 4356 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4357 | ims.setWfcProvisioned(isProvisioned); |
| 4358 | } |
| 4359 | break; |
| 4360 | } |
| 4361 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4362 | // There is currently no difference in VT provisioning type. |
| 4363 | ims.setVtProvisioned(isProvisioned); |
| 4364 | break; |
| 4365 | } |
| 4366 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4367 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4368 | // change the capability of the feature instead if needed. |
| 4369 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4370 | == isProvisioned) { |
| 4371 | // No change in provisioning. |
| 4372 | return; |
| 4373 | } |
| 4374 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4375 | try { |
| 4376 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4377 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4378 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4379 | + ", Exception" + e.getMessage()); |
| 4380 | } |
| 4381 | break; |
| 4382 | } |
| 4383 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4384 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4385 | + "MmTel capability '" + capability + "', which does not require " |
| 4386 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | } finally { |
| 4391 | Binder.restoreCallingIdentity(identity); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | @Override |
| 4396 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4397 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4398 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4399 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4400 | } |
| 4401 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
| 4404 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4405 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4406 | return true; |
| 4407 | } |
| 4408 | |
| 4409 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4410 | switch (capability) { |
| 4411 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4412 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4413 | return ims.isVolteProvisionedOnDevice(); |
| 4414 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4415 | return ims.isWfcProvisionedOnDevice(); |
| 4416 | } |
| 4417 | // This should never happen, since we are checking tech above to make sure it |
| 4418 | // is either LTE or IWLAN. |
| 4419 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4420 | + "capability."); |
| 4421 | } |
| 4422 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4423 | // There is currently no difference in VT provisioning type. |
| 4424 | return ims.isVtProvisionedOnDevice(); |
| 4425 | } |
| 4426 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4427 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4428 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4429 | } |
| 4430 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4431 | throw new IllegalArgumentException( |
| 4432 | "Tried to get provisioning for MmTel capability '" + capability |
| 4433 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | @Override |
| 4443 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4444 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4445 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4446 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4447 | } |
| 4448 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4449 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4450 | return (provisionedBits & capability) > 0; |
| 4451 | } |
| 4452 | |
| 4453 | @Override |
| 4454 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4455 | boolean isProvisioned) { |
| 4456 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4457 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4458 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4459 | } |
| 4460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4461 | "setProvisioningStatusForCapability"); |
| 4462 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4463 | // If the current provisioning status for capability already matches isProvisioned, |
| 4464 | // do nothing. |
| 4465 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4466 | return; |
| 4467 | } |
| 4468 | if (isProvisioned) { |
| 4469 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4470 | } else { |
| 4471 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4472 | } |
| 4473 | } |
| 4474 | |
| 4475 | /** |
| 4476 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4477 | * technology. The bitfield should mirror the bitfield defined by |
| 4478 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4479 | */ |
| 4480 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4481 | String key = getMmTelProvisioningKey(subId, tech); |
| 4482 | // Default is no capabilities are provisioned. |
| 4483 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4484 | } |
| 4485 | |
| 4486 | /** |
| 4487 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4488 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4489 | * technology specified. |
| 4490 | * |
| 4491 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4492 | */ |
| 4493 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4494 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4495 | String key = getMmTelProvisioningKey(subId, tech); |
| 4496 | editor.putInt(key, newField); |
| 4497 | editor.commit(); |
| 4498 | } |
| 4499 | |
| 4500 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4501 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4502 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4503 | } |
| 4504 | |
| 4505 | /** |
| 4506 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4507 | * carrier associated with the subscription id. |
| 4508 | */ |
| 4509 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4510 | int capability) { |
| 4511 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4512 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4513 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4514 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4515 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4516 | false); |
| 4517 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4518 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4519 | |
| 4520 | // First check to make sure that the capability requires provisioning. |
| 4521 | switch (capability) { |
| 4522 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4523 | // intentional fallthrough |
| 4524 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4525 | if (requireVoiceVtProvisioning) { |
| 4526 | // Voice and Video requires provisioning |
| 4527 | return true; |
| 4528 | } |
| 4529 | break; |
| 4530 | } |
| 4531 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4532 | if (requireUtProvisioning) { |
| 4533 | // UT requires provisioning |
| 4534 | return true; |
| 4535 | } |
| 4536 | break; |
| 4537 | } |
| 4538 | } |
| 4539 | return false; |
| 4540 | } |
| 4541 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4542 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4543 | int capability) { |
| 4544 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4545 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4546 | |
| 4547 | boolean requireRcsProvisioning = c.getBoolean( |
| 4548 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4549 | |
| 4550 | // First check to make sure that the capability requires provisioning. |
| 4551 | switch (capability) { |
| 4552 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4553 | // intentional fallthrough |
| 4554 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4555 | if (requireRcsProvisioning) { |
| 4556 | // OPTION or PRESENCE requires provisioning |
| 4557 | return true; |
| 4558 | } |
| 4559 | break; |
| 4560 | } |
| 4561 | } |
| 4562 | return false; |
| 4563 | } |
| 4564 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4565 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4566 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4567 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4568 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4569 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4570 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4571 | final long identity = Binder.clearCallingIdentity(); |
| 4572 | try { |
| 4573 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4574 | int slotId = getSlotIndex(subId); |
| 4575 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4576 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4577 | + subId + "' for key:" + key); |
| 4578 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4579 | } |
| 4580 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4581 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4582 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4583 | + subId + "' for key:" + key); |
| 4584 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4585 | } finally { |
| 4586 | Binder.restoreCallingIdentity(identity); |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | @Override |
| 4591 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4592 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4593 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4594 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4595 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4596 | final long identity = Binder.clearCallingIdentity(); |
| 4597 | try { |
| 4598 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4599 | int slotId = getSlotIndex(subId); |
| 4600 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4601 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4602 | + subId + "' for key:" + key); |
| 4603 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4604 | } |
| 4605 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4606 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4607 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4608 | + subId + "' for key:" + key); |
| 4609 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4610 | } finally { |
| 4611 | Binder.restoreCallingIdentity(identity); |
| 4612 | } |
| 4613 | } |
| 4614 | |
| 4615 | @Override |
| 4616 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4617 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4618 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4619 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4621 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
| 4624 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4625 | int slotId = getSlotIndex(subId); |
| 4626 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4627 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4628 | + subId + "' for key:" + key); |
| 4629 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4630 | } |
| 4631 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4632 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4633 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4634 | + "' for key:" + key); |
| 4635 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4636 | } finally { |
| 4637 | Binder.restoreCallingIdentity(identity); |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | @Override |
| 4642 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4643 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4644 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4645 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4647 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4648 | final long identity = Binder.clearCallingIdentity(); |
| 4649 | try { |
| 4650 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4651 | int slotId = getSlotIndex(subId); |
| 4652 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4653 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4654 | + subId + "' for key:" + key); |
| 4655 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4656 | } |
| 4657 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4658 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4659 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4660 | + "' for key:" + key); |
| 4661 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(identity); |
| 4664 | } |
| 4665 | } |
| 4666 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4667 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4668 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4669 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4670 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4671 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4672 | } |
| 4673 | return slotId; |
| 4674 | } |
| 4675 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4676 | private int getSlotIndex(int subId) { |
| 4677 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4678 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4679 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4680 | } |
| 4681 | return slotId; |
| 4682 | } |
| 4683 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4684 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4685 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4686 | */ |
| 4687 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4688 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4689 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4690 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4691 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4692 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4693 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4694 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4695 | mApp, subId, callingPackage, callingFeatureId, |
| 4696 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4697 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4698 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | final Phone phone = getPhone(subId); |
| 4703 | if (phone != null) { |
| 4704 | return phone.getServiceState().getDataNetworkType(); |
| 4705 | } else { |
| 4706 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4707 | } |
| 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4710 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | /** |
| 4714 | * Returns the data network type |
| 4715 | */ |
| 4716 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4717 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4718 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4719 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | /** |
| 4723 | * Returns the data network type for a subId |
| 4724 | */ |
| 4725 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4726 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4727 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4729 | mApp, subId, callingPackage, callingFeatureId, |
| 4730 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4731 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4732 | } |
| 4733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4734 | final long identity = Binder.clearCallingIdentity(); |
| 4735 | try { |
| 4736 | final Phone phone = getPhone(subId); |
| 4737 | if (phone != null) { |
| 4738 | return phone.getServiceState().getDataNetworkType(); |
| 4739 | } else { |
| 4740 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4741 | } |
| 4742 | } finally { |
| 4743 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4748 | * Returns the Voice network type for a subId |
| 4749 | */ |
| 4750 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4751 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4752 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4753 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4754 | mApp, subId, callingPackage, callingFeatureId, |
| 4755 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4756 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4757 | } |
| 4758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
| 4761 | final Phone phone = getPhone(subId); |
| 4762 | if (phone != null) { |
| 4763 | return phone.getServiceState().getVoiceNetworkType(); |
| 4764 | } else { |
| 4765 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4766 | } |
| 4767 | } finally { |
| 4768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4770 | } |
| 4771 | |
| 4772 | /** |
| 4773 | * @return true if a ICC card is present |
| 4774 | */ |
| 4775 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4776 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4777 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4778 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4782 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4783 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4784 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4785 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | final long identity = Binder.clearCallingIdentity(); |
| 4787 | try { |
| 4788 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4789 | if (phone != null) { |
| 4790 | return phone.getIccCard().hasIccCard(); |
| 4791 | } else { |
| 4792 | return false; |
| 4793 | } |
| 4794 | } finally { |
| 4795 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4796 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4797 | } |
| 4798 | |
| 4799 | /** |
| 4800 | * Return if the current radio is LTE on CDMA. This |
| 4801 | * is a tri-state return value as for a period of time |
| 4802 | * the mode may be unknown. |
| 4803 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4804 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4805 | * @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] | 4806 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4807 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4808 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4809 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4810 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4811 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4814 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4815 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4816 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4817 | try { |
| 4818 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4819 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4820 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4821 | } |
| 4822 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4823 | final long identity = Binder.clearCallingIdentity(); |
| 4824 | try { |
| 4825 | final Phone phone = getPhone(subId); |
| 4826 | if (phone == null) { |
| 4827 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4828 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4829 | return TelephonyProperties.lte_on_cdma_device() |
| 4830 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4831 | } |
| 4832 | } finally { |
| 4833 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4834 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4835 | } |
| 4836 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4837 | /** |
| 4838 | * {@hide} |
| 4839 | * Returns Default subId, 0 in the case of single standby. |
| 4840 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4841 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4842 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4843 | } |
| 4844 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4845 | private int getSlotForDefaultSubscription() { |
| 4846 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4847 | } |
| 4848 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4849 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4850 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4851 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4852 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4853 | private boolean isActiveSubscription(int subId) { |
| 4854 | return mSubscriptionController.isActiveSubId(subId); |
| 4855 | } |
| 4856 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4857 | /** |
| 4858 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4859 | */ |
| 4860 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | final long identity = Binder.clearCallingIdentity(); |
| 4862 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4863 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4865 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | /** |
| 4872 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4873 | */ |
| 4874 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4875 | final long identity = Binder.clearCallingIdentity(); |
| 4876 | try { |
| 4877 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4878 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4879 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
| 4882 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4885 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4886 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4887 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4888 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4889 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4890 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4891 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4892 | if (phoneId == -1) { |
| 4893 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4894 | + " does not correspond to an active phone"); |
| 4895 | } |
| 4896 | return PhoneFactory.getPhone(phoneId); |
| 4897 | } |
| 4898 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4899 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4900 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4901 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4902 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4903 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4905 | if (DBG) { |
| 4906 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4907 | } |
| 4908 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4909 | p2); |
| 4910 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4911 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4912 | |
| 4913 | @Override |
| 4914 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4915 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4916 | enforceModifyPermission(); |
| 4917 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4918 | if (DBG) { |
| 4919 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4920 | } |
| 4921 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4922 | callingPackage, aid, p2); |
| 4923 | } |
| 4924 | |
| 4925 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4926 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
| 4929 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4930 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4931 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4932 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | if (bestComponent == null |
| 4934 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4935 | loge("The calling package is not allowed to access ISD-R."); |
| 4936 | throw new SecurityException( |
| 4937 | "The calling package is not allowed to access ISD-R."); |
| 4938 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4939 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4940 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4941 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4942 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4943 | null /* workSource */); |
| 4944 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | return response; |
| 4946 | } finally { |
| 4947 | Binder.restoreCallingIdentity(identity); |
| 4948 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4952 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4954 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4955 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4956 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4957 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4958 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4959 | @Override |
| 4960 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4961 | enforceModifyPermission(); |
| 4962 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4963 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4964 | channel); |
| 4965 | } |
| 4966 | |
| 4967 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | if (channel < 0) { |
| 4971 | return false; |
| 4972 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4973 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4974 | null /* workSource */); |
| 4975 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4976 | return success; |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4979 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4983 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4984 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4986 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4987 | if (DBG) { |
| 4988 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4989 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4990 | + p3 + " data=" + data); |
| 4991 | } |
| 4992 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4993 | command, p1, p2, p3, data); |
| 4994 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4995 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4996 | @Override |
| 4997 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4998 | int command, int p1, int p2, int p3, String data) { |
| 4999 | enforceModifyPermission(); |
| 5000 | if (DBG) { |
| 5001 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5002 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5003 | + p3 + " data=" + data); |
| 5004 | } |
| 5005 | return iccTransmitApduLogicalChannelWithPermission( |
| 5006 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5007 | data); |
| 5008 | } |
| 5009 | |
| 5010 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5011 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | final long identity = Binder.clearCallingIdentity(); |
| 5013 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5014 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5015 | return ""; |
| 5016 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5018 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5019 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5020 | null /* workSource */); |
| 5021 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5022 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5023 | // Append the returned status code to the end of the response payload. |
| 5024 | String s = Integer.toHexString( |
| 5025 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5026 | if (response.payload != null) { |
| 5027 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5028 | } |
| 5029 | return s; |
| 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5032 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5033 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5034 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5035 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5036 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5037 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5039 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5040 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5041 | if (DBG) { |
| 5042 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5043 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5044 | } |
| 5045 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5046 | cla, command, p1, p2, p3, data); |
| 5047 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5048 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5049 | @Override |
| 5050 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5051 | int command, int p1, int p2, int p3, String data) { |
| 5052 | enforceModifyPermission(); |
| 5053 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5054 | if (DBG) { |
| 5055 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5056 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5057 | + " data=" + data); |
| 5058 | } |
| 5059 | |
| 5060 | return iccTransmitApduBasicChannelWithPermission( |
| 5061 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5062 | p2, p3, data); |
| 5063 | } |
| 5064 | |
| 5065 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5066 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5067 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | final long identity = Binder.clearCallingIdentity(); |
| 5069 | try { |
| 5070 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5071 | && TextUtils.equals(ISDR_AID, data)) { |
| 5072 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5073 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5074 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5075 | if (bestComponent == null |
| 5076 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5077 | loge("The calling package is not allowed to select ISD-R."); |
| 5078 | throw new SecurityException( |
| 5079 | "The calling package is not allowed to select ISD-R."); |
| 5080 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5081 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5084 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5085 | null /* workSource */); |
| 5086 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5087 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5088 | // Append the returned status code to the end of the response payload. |
| 5089 | String s = Integer.toHexString( |
| 5090 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5091 | if (response.payload != null) { |
| 5092 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5093 | } |
| 5094 | return s; |
| 5095 | } finally { |
| 5096 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5097 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5098 | } |
| 5099 | |
| 5100 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5101 | 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] | 5102 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5104 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5106 | final long identity = Binder.clearCallingIdentity(); |
| 5107 | try { |
| 5108 | if (DBG) { |
| 5109 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5110 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5111 | } |
| 5112 | |
| 5113 | IccIoResult response = |
| 5114 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5115 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5116 | subId); |
| 5117 | |
| 5118 | if (DBG) { |
| 5119 | log("Exchange SIM_IO [R]" + response); |
| 5120 | } |
| 5121 | |
| 5122 | byte[] result = null; |
| 5123 | int length = 2; |
| 5124 | if (response.payload != null) { |
| 5125 | length = 2 + response.payload.length; |
| 5126 | result = new byte[length]; |
| 5127 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5128 | } else { |
| 5129 | result = new byte[length]; |
| 5130 | } |
| 5131 | |
| 5132 | result[length - 1] = (byte) response.sw2; |
| 5133 | result[length - 2] = (byte) response.sw1; |
| 5134 | return result; |
| 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5137 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5140 | /** |
| 5141 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5142 | * on a particular subscription |
| 5143 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5144 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5145 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5146 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5147 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5148 | return null; |
| 5149 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5150 | |
| 5151 | final long identity = Binder.clearCallingIdentity(); |
| 5152 | try { |
| 5153 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5154 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5155 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5156 | return null; |
| 5157 | } |
| 5158 | Object response = sendRequest( |
| 5159 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5160 | if (response instanceof String[]) { |
| 5161 | return (String[]) response; |
| 5162 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5163 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5165 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5166 | } finally { |
| 5167 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5168 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5169 | } |
| 5170 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5171 | /** |
| 5172 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5173 | * subscription. |
| 5174 | * |
| 5175 | * @param subId the id of the subscription. |
| 5176 | * @param appType the uicc app type, must be USIM or SIM. |
| 5177 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5178 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5179 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5180 | * @return number of fplmns that is successfully written to the SIM. |
| 5181 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5182 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5183 | String callingFeatureId) { |
| 5184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5185 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5186 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5187 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5188 | } |
| 5189 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5190 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5191 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5192 | } |
| 5193 | if (fplmns == null) { |
| 5194 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5195 | } |
| 5196 | for (String fplmn : fplmns) { |
| 5197 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5198 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5199 | } |
| 5200 | } |
| 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
| 5203 | Object response = sendRequest( |
| 5204 | CMD_SET_FORBIDDEN_PLMNS, |
| 5205 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5206 | subId); |
| 5207 | return (int) response; |
| 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
| 5210 | } |
| 5211 | } |
| 5212 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5213 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5214 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5215 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5216 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5218 | final long identity = Binder.clearCallingIdentity(); |
| 5219 | try { |
| 5220 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5221 | if (response.payload == null) { |
| 5222 | return ""; |
| 5223 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | // Append the returned status code to the end of the response payload. |
| 5226 | String s = Integer.toHexString( |
| 5227 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5228 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5229 | return s; |
| 5230 | } finally { |
| 5231 | Binder.restoreCallingIdentity(identity); |
| 5232 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5233 | } |
| 5234 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5235 | /** |
| 5236 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5237 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5238 | * |
| 5239 | * @param itemID the ID of the item to read |
| 5240 | * @return the NV item as a String, or null on error. |
| 5241 | */ |
| 5242 | @Override |
| 5243 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5244 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5246 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | |
| 5248 | final long identity = Binder.clearCallingIdentity(); |
| 5249 | try { |
| 5250 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5251 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5253 | return value; |
| 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5257 | } |
| 5258 | |
| 5259 | /** |
| 5260 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5261 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5262 | * |
| 5263 | * @param itemID the ID of the item to read |
| 5264 | * @param itemValue the value to write, as a String |
| 5265 | * @return true on success; false on any failure |
| 5266 | */ |
| 5267 | @Override |
| 5268 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5269 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5271 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5272 | |
| 5273 | final long identity = Binder.clearCallingIdentity(); |
| 5274 | try { |
| 5275 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5276 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5277 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5279 | return success; |
| 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
| 5282 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | /** |
| 5286 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5287 | * Used for device configuration by some CDMA operators. |
| 5288 | * |
| 5289 | * @param preferredRoamingList byte array containing the new PRL |
| 5290 | * @return true on success; false on any failure |
| 5291 | */ |
| 5292 | @Override |
| 5293 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5294 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5295 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | |
| 5297 | final long identity = Binder.clearCallingIdentity(); |
| 5298 | try { |
| 5299 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5300 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5301 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5302 | return success; |
| 5303 | } finally { |
| 5304 | Binder.restoreCallingIdentity(identity); |
| 5305 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5309 | * 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] | 5310 | * Used for device configuration by some CDMA operators. |
| 5311 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5312 | * @param slotIndex - device slot. |
| 5313 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5314 | * @return true on success; false on any failure |
| 5315 | */ |
| 5316 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5317 | public boolean resetModemConfig(int slotIndex) { |
| 5318 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5319 | if (phone != null) { |
| 5320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5321 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5323 | final long identity = Binder.clearCallingIdentity(); |
| 5324 | try { |
| 5325 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5326 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5327 | return success; |
| 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
| 5330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5332 | return false; |
| 5333 | } |
| 5334 | |
| 5335 | /** |
| 5336 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5337 | * |
| 5338 | * @param slotIndex - device slot. |
| 5339 | * |
| 5340 | * @return true on success; false on any failure |
| 5341 | */ |
| 5342 | @Override |
| 5343 | public boolean rebootModem(int slotIndex) { |
| 5344 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5345 | if (phone != null) { |
| 5346 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5347 | mApp, phone.getSubId(), "rebootModem"); |
| 5348 | |
| 5349 | final long identity = Binder.clearCallingIdentity(); |
| 5350 | try { |
| 5351 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5352 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5353 | return success; |
| 5354 | } finally { |
| 5355 | Binder.restoreCallingIdentity(identity); |
| 5356 | } |
| 5357 | } |
| 5358 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5359 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5360 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5361 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5362 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5363 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5364 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5365 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5366 | return new String[0]; |
| 5367 | } |
| 5368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5371 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | } finally { |
| 5373 | Binder.restoreCallingIdentity(identity); |
| 5374 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5375 | } |
| 5376 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5377 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5378 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5379 | * {@link #disableIms(int)}. |
| 5380 | * @param slotIndex device slot. |
| 5381 | */ |
| 5382 | public void resetIms(int slotIndex) { |
| 5383 | enforceModifyPermission(); |
| 5384 | |
| 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | try { |
| 5387 | if (mImsResolver == null) { |
| 5388 | // may happen if the does not support IMS. |
| 5389 | return; |
| 5390 | } |
| 5391 | mImsResolver.disableIms(slotIndex); |
| 5392 | mImsResolver.enableIms(slotIndex); |
| 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
| 5395 | } |
| 5396 | } |
| 5397 | |
| 5398 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5399 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5400 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5401 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5402 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5403 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | |
| 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5407 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5408 | // may happen if the device does not support IMS. |
| 5409 | return; |
| 5410 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5411 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | } finally { |
| 5413 | Binder.restoreCallingIdentity(identity); |
| 5414 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5418 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5419 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5420 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5421 | public void disableIms(int slotId) { |
| 5422 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5423 | |
| 5424 | final long identity = Binder.clearCallingIdentity(); |
| 5425 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5426 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5427 | // may happen if the device does not support IMS. |
| 5428 | return; |
| 5429 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5430 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | } finally { |
| 5432 | Binder.restoreCallingIdentity(identity); |
| 5433 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5437 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5438 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5439 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5440 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5441 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5442 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5443 | |
| 5444 | final long identity = Binder.clearCallingIdentity(); |
| 5445 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5446 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5447 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5448 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5449 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5450 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
| 5453 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5454 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5455 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5456 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5457 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5458 | @Override |
| 5459 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5460 | enforceModifyPermission(); |
| 5461 | |
| 5462 | final long identity = Binder.clearCallingIdentity(); |
| 5463 | try { |
| 5464 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5465 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5466 | } finally { |
| 5467 | Binder.restoreCallingIdentity(identity); |
| 5468 | } |
| 5469 | } |
| 5470 | |
| 5471 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5472 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5473 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5474 | */ |
| 5475 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5476 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | |
| 5478 | final long identity = Binder.clearCallingIdentity(); |
| 5479 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5480 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5481 | // may happen if the device does not support IMS. |
| 5482 | return null; |
| 5483 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5484 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
| 5487 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5490 | /** |
| 5491 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5492 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5493 | */ |
| 5494 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5495 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5496 | |
| 5497 | final long identity = Binder.clearCallingIdentity(); |
| 5498 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5499 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5500 | // may happen if the device does not support IMS. |
| 5501 | return null; |
| 5502 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5503 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | } finally { |
| 5505 | Binder.restoreCallingIdentity(identity); |
| 5506 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5507 | } |
| 5508 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5509 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5510 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5511 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5512 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5513 | * @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] | 5514 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5515 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5516 | * @param packageName The name of the package that the current configuration will be replaced |
| 5517 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5518 | * @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] | 5519 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5521 | int[] featureTypes, String packageName) { |
| 5522 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5523 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5525 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5526 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | final long identity = Binder.clearCallingIdentity(); |
| 5529 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5530 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5531 | // may happen if the device does not support IMS. |
| 5532 | return false; |
| 5533 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5534 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5535 | for (int featureType : featureTypes) { |
| 5536 | featureConfig.put(featureType, packageName); |
| 5537 | } |
| 5538 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5539 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5540 | } finally { |
| 5541 | Binder.restoreCallingIdentity(identity); |
| 5542 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5546 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5547 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5548 | * |
| 5549 | * This should only be used for testing. |
| 5550 | * |
| 5551 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5552 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5553 | */ |
| 5554 | @Override |
| 5555 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5556 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5557 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5558 | "clearCarrierImsServiceOverride"); |
| 5559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5560 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5561 | "clearCarrierImsServiceOverride"); |
| 5562 | |
| 5563 | final long identity = Binder.clearCallingIdentity(); |
| 5564 | try { |
| 5565 | if (mImsResolver == null) { |
| 5566 | // may happen if the device does not support IMS. |
| 5567 | return false; |
| 5568 | } |
| 5569 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5570 | } finally { |
| 5571 | Binder.restoreCallingIdentity(identity); |
| 5572 | } |
| 5573 | } |
| 5574 | |
| 5575 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5576 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5577 | * |
| 5578 | * @param slotId The slot that the ImsService is associated with. |
| 5579 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5580 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5581 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5582 | * @return the package name of the ImsService configuration. |
| 5583 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5584 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5585 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5586 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5587 | TelephonyPermissions |
| 5588 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5589 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5590 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5591 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5594 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5595 | // may happen if the device does not support IMS. |
| 5596 | return ""; |
| 5597 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5598 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5599 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5600 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5601 | } finally { |
| 5602 | Binder.restoreCallingIdentity(identity); |
| 5603 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5604 | } |
| 5605 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5606 | /** |
| 5607 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5608 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5609 | * @param callback A callback with an integer containing the |
| 5610 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5611 | */ |
| 5612 | @Override |
| 5613 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5614 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5615 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5616 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5617 | "IMS not available on device."); |
| 5618 | } |
| 5619 | final long token = Binder.clearCallingIdentity(); |
| 5620 | try { |
| 5621 | int slotId = getSlotIndex(subId); |
| 5622 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5623 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5624 | + subId + "'"); |
| 5625 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5626 | } |
| 5627 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5628 | try { |
| 5629 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5630 | } catch (RemoteException e) { |
| 5631 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5632 | + "Ignore"); |
| 5633 | } |
| 5634 | }); |
| 5635 | } finally { |
| 5636 | Binder.restoreCallingIdentity(token); |
| 5637 | } |
| 5638 | } |
| 5639 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5640 | /** |
| 5641 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5642 | */ |
| 5643 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5644 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | |
| 5646 | final long identity = Binder.clearCallingIdentity(); |
| 5647 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5648 | // NOTE: Before S, this method only set the default phone. |
| 5649 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5650 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5651 | phone.setImsRegistrationState(registered); |
| 5652 | } |
| 5653 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5654 | } finally { |
| 5655 | Binder.restoreCallingIdentity(identity); |
| 5656 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5657 | } |
| 5658 | |
| 5659 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5660 | * Set the network selection mode to automatic. |
| 5661 | * |
| 5662 | */ |
| 5663 | @Override |
| 5664 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5666 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | |
| 5668 | final long identity = Binder.clearCallingIdentity(); |
| 5669 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5670 | if (!isActiveSubscription(subId)) { |
| 5671 | return; |
| 5672 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5673 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5674 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5675 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | } finally { |
| 5677 | Binder.restoreCallingIdentity(identity); |
| 5678 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5681 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5682 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5683 | * |
| 5684 | * @param subId the id of the subscription. |
| 5685 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5686 | * the operator to attach to. |
| 5687 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5688 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5689 | * normal network selection next time. |
| 5690 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5691 | */ |
| 5692 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5693 | public boolean setNetworkSelectionModeManual( |
| 5694 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5696 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5697 | |
| 5698 | if (!isActiveSubscription(subId)) { |
| 5699 | return false; |
| 5700 | } |
| 5701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | final long identity = Binder.clearCallingIdentity(); |
| 5703 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5704 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5706 | if (DBG) { |
| 5707 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5708 | + " operator: " + operatorInfo); |
| 5709 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5711 | } finally { |
| 5712 | Binder.restoreCallingIdentity(identity); |
| 5713 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5714 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5715 | /** |
| 5716 | * Get the manual network selection |
| 5717 | * |
| 5718 | * @param subId the id of the subscription. |
| 5719 | * |
| 5720 | * @return the previously saved user selected PLMN |
| 5721 | */ |
| 5722 | @Override |
| 5723 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5724 | TelephonyPermissions |
| 5725 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5726 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5727 | |
| 5728 | final long identity = Binder.clearCallingIdentity(); |
| 5729 | try { |
| 5730 | if (!isActiveSubscription(subId)) { |
| 5731 | return ""; |
| 5732 | } |
| 5733 | |
| 5734 | final Phone phone = getPhone(subId); |
| 5735 | if (phone == null) { |
| 5736 | return ""; |
| 5737 | } |
| 5738 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5739 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5740 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
| 5743 | } |
| 5744 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5745 | |
| 5746 | /** |
| 5747 | * Scans for available networks. |
| 5748 | */ |
| 5749 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5750 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5751 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5752 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5753 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5754 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5755 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5756 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5757 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5758 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5759 | .setCallingPid(Binder.getCallingPid()) |
| 5760 | .setCallingUid(Binder.getCallingUid()) |
| 5761 | .setMethod("getCellNetworkScanResults") |
| 5762 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5763 | .build()); |
| 5764 | switch (locationResult) { |
| 5765 | case DENIED_HARD: |
| 5766 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5767 | case DENIED_SOFT: |
| 5768 | return null; |
| 5769 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5771 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | try { |
| 5773 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5774 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5776 | } finally { |
| 5777 | Binder.restoreCallingIdentity(identity); |
| 5778 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5779 | } |
| 5780 | |
| 5781 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5782 | * Get the call forwarding info, given the call forwarding reason. |
| 5783 | */ |
| 5784 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5785 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5786 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5787 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5788 | long identity = Binder.clearCallingIdentity(); |
| 5789 | try { |
| 5790 | if (DBG) { |
| 5791 | log("getCallForwarding: subId " + subId |
| 5792 | + " callForwardingReason" + callForwardingReason); |
| 5793 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5794 | |
| 5795 | Phone phone = getPhone(subId); |
| 5796 | if (phone == null) { |
| 5797 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5798 | callback.onError( |
| 5799 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5800 | } catch (RemoteException e) { |
| 5801 | // ignore |
| 5802 | } |
| 5803 | return; |
| 5804 | } |
| 5805 | |
| 5806 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5807 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5808 | @Override |
| 5809 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5810 | try { |
| 5811 | callback.onCallForwardingInfoAvailable(info); |
| 5812 | } catch (RemoteException e) { |
| 5813 | // ignore |
| 5814 | } |
| 5815 | } |
| 5816 | |
| 5817 | @Override |
| 5818 | public void onError(int error) { |
| 5819 | try { |
| 5820 | callback.onError(error); |
| 5821 | } catch (RemoteException e) { |
| 5822 | // ignore |
| 5823 | } |
| 5824 | } |
| 5825 | }); |
| 5826 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(identity); |
| 5829 | } |
| 5830 | } |
| 5831 | |
| 5832 | /** |
| 5833 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5834 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5835 | */ |
| 5836 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5837 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5838 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5839 | enforceModifyPermission(); |
| 5840 | long identity = Binder.clearCallingIdentity(); |
| 5841 | try { |
| 5842 | if (DBG) { |
| 5843 | log("setCallForwarding: subId " + subId |
| 5844 | + " callForwardingInfo" + callForwardingInfo); |
| 5845 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5846 | |
| 5847 | Phone phone = getPhone(subId); |
| 5848 | if (phone == null) { |
| 5849 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5850 | callback.accept( |
| 5851 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5852 | } catch (RemoteException e) { |
| 5853 | // ignore |
| 5854 | } |
| 5855 | return; |
| 5856 | } |
| 5857 | |
| 5858 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5859 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5860 | |
| 5861 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5862 | } finally { |
| 5863 | Binder.restoreCallingIdentity(identity); |
| 5864 | } |
| 5865 | } |
| 5866 | |
| 5867 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5868 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5869 | */ |
| 5870 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5871 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5872 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5873 | long identity = Binder.clearCallingIdentity(); |
| 5874 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5875 | |
| 5876 | Phone phone = getPhone(subId); |
| 5877 | if (phone == null) { |
| 5878 | try { |
| 5879 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5880 | } catch (RemoteException e) { |
| 5881 | // ignore |
| 5882 | } |
| 5883 | return; |
| 5884 | } |
| 5885 | |
| 5886 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5887 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5888 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5889 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5890 | } finally { |
| 5891 | Binder.restoreCallingIdentity(identity); |
| 5892 | } |
| 5893 | } |
| 5894 | |
| 5895 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5896 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5897 | */ |
| 5898 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5899 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5900 | enforceModifyPermission(); |
| 5901 | long identity = Binder.clearCallingIdentity(); |
| 5902 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5903 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5904 | |
| 5905 | Phone phone = getPhone(subId); |
| 5906 | if (phone == null) { |
| 5907 | try { |
| 5908 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5909 | } catch (RemoteException e) { |
| 5910 | // ignore |
| 5911 | } |
| 5912 | return; |
| 5913 | } |
| 5914 | |
| 5915 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5916 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5917 | |
| 5918 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5919 | } finally { |
| 5920 | Binder.restoreCallingIdentity(identity); |
| 5921 | } |
| 5922 | } |
| 5923 | |
| 5924 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5925 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5926 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5927 | * @param subId id of the subscription |
| 5928 | * @param request contains the radio access networks with bands/channels to scan |
| 5929 | * @param messenger callback messenger for scan results or errors |
| 5930 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5931 | * @return the id of the requested scan which can be used to stop the scan. |
| 5932 | */ |
| 5933 | @Override |
| 5934 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5935 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5937 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5938 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5939 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5940 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5941 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5942 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5943 | .setCallingPid(Binder.getCallingPid()) |
| 5944 | .setCallingUid(Binder.getCallingUid()) |
| 5945 | .setMethod("requestNetworkScan") |
| 5946 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5947 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5948 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5949 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5950 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5951 | if (e != null) { |
| 5952 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5953 | throw e; |
| 5954 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5955 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5956 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5957 | } |
| 5958 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5960 | int callingUid = Binder.getCallingUid(); |
| 5961 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5962 | final long identity = Binder.clearCallingIdentity(); |
| 5963 | try { |
| 5964 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5965 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5966 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5967 | } finally { |
| 5968 | Binder.restoreCallingIdentity(identity); |
| 5969 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5972 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5973 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5974 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5975 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5976 | boolean hasNetworkScanPermission = |
| 5977 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5978 | == PERMISSION_GRANTED; |
| 5979 | |
| 5980 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5981 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5982 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5983 | } |
| 5984 | |
| 5985 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5986 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5987 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5988 | return new SecurityException("Specific channels must not be" |
| 5989 | + " scanned without location access."); |
| 5990 | } |
| 5991 | } |
| 5992 | } |
| 5993 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5994 | return null; |
| 5995 | } |
| 5996 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5997 | /** |
| 5998 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5999 | * |
| 6000 | * @param subId id of the subscription |
| 6001 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6002 | */ |
| 6003 | @Override |
| 6004 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6006 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6008 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | final long identity = Binder.clearCallingIdentity(); |
| 6010 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6011 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | } finally { |
| 6013 | Binder.restoreCallingIdentity(identity); |
| 6014 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | /** |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6018 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6019 | * |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6020 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6021 | */ |
| 6022 | @Override |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6023 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6024 | TelephonyPermissions |
| 6025 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6026 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | |
| 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6030 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6031 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6032 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6033 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6034 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6035 | } finally { |
| 6036 | Binder.restoreCallingIdentity(identity); |
| 6037 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6041 | * Get the allowed network types for certain reason. |
| 6042 | * |
| 6043 | * @param subId the id of the subscription. |
| 6044 | * @param reason the reason the allowed network type change is taking place |
| 6045 | * @return the allowed network types. |
| 6046 | */ |
| 6047 | @Override |
| 6048 | public long getAllowedNetworkTypesForReason(int subId, |
| 6049 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6050 | TelephonyPermissions |
| 6051 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6052 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6053 | final long identity = Binder.clearCallingIdentity(); |
| 6054 | try { |
| 6055 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6056 | } finally { |
| 6057 | Binder.restoreCallingIdentity(identity); |
| 6058 | } |
| 6059 | } |
| 6060 | |
| 6061 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6062 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6063 | * @param subId subscription id of the sim card |
| 6064 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6065 | * This can be passed following states |
| 6066 | * <ol> |
| 6067 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6068 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6069 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6070 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6071 | * </ol> |
| 6072 | * @return operation result. |
| 6073 | */ |
| 6074 | @Override |
| 6075 | public int setNrDualConnectivityState(int subId, |
| 6076 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6078 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame^] | 6079 | if (isRadioInterfaceCapabilitySupported( |
| 6080 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6081 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6082 | } |
| 6083 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6084 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6088 | nrDualConnectivityState, subId, |
| 6089 | workSource); |
| 6090 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6091 | return result; |
| 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
| 6095 | } |
| 6096 | |
| 6097 | /** |
| 6098 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6099 | * @return true if dual connectivity is enabled else false |
| 6100 | */ |
| 6101 | @Override |
| 6102 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6103 | TelephonyPermissions |
| 6104 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6105 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame^] | 6106 | if (isRadioInterfaceCapabilitySupported( |
| 6107 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6108 | return false; |
| 6109 | } |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6110 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6111 | final long identity = Binder.clearCallingIdentity(); |
| 6112 | try { |
| 6113 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6114 | null, subId, workSource); |
| 6115 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6116 | return isEnabled; |
| 6117 | } finally { |
| 6118 | Binder.restoreCallingIdentity(identity); |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6123 | * get carrier bandwidth per primary and secondary carrier |
| 6124 | * @param subId subscription id of the sim card |
| 6125 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6126 | */ |
| 6127 | @Override |
| 6128 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6129 | TelephonyPermissions |
| 6130 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6131 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6132 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6133 | final long identity = Binder.clearCallingIdentity(); |
| 6134 | try { |
| 6135 | CarrierBandwidth carrierBandwidth = |
| 6136 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6137 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6138 | return carrierBandwidth; |
| 6139 | } finally { |
| 6140 | Binder.restoreCallingIdentity(identity); |
| 6141 | } |
| 6142 | } |
| 6143 | |
| 6144 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6145 | * Set the allowed network types of the device and |
| 6146 | * provide the reason triggering the allowed network change. |
| 6147 | * |
| 6148 | * @param subId the id of the subscription. |
| 6149 | * @param reason the reason the allowed network type change is taking place |
| 6150 | * @param allowedNetworkTypes the allowed network types. |
| 6151 | * @return true on success; false on any failure. |
| 6152 | */ |
| 6153 | @Override |
| 6154 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6155 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6156 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6158 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6159 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6160 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6161 | return false; |
| 6162 | } |
| 6163 | |
| 6164 | if (DBG) { |
| 6165 | log("setAllowedNetworkTypesForReason: " + reason |
| 6166 | + " value: " + allowedNetworkTypes); |
| 6167 | } |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6168 | final long identity = Binder.clearCallingIdentity(); |
| 6169 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6170 | Boolean success = (Boolean) sendRequest( |
| 6171 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6172 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6173 | |
| 6174 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6175 | return success; |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6176 | } finally { |
| 6177 | Binder.restoreCallingIdentity(identity); |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6182 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6183 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6184 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6185 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6186 | * @hide |
| 6187 | */ |
| 6188 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6189 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6190 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6191 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6192 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6193 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6194 | if (phone != null) { |
| 6195 | return phone.hasMatchedTetherApnSetting(); |
| 6196 | } else { |
| 6197 | return false; |
| 6198 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6201 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6202 | } |
| 6203 | |
| 6204 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6205 | * Enable or disable always reporting signal strength changes from radio. |
| 6206 | * |
| 6207 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6208 | */ |
| 6209 | @Override |
| 6210 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6211 | enforceModifyPermission(); |
| 6212 | enforceSystemCaller(); |
| 6213 | |
| 6214 | final long identity = Binder.clearCallingIdentity(); |
| 6215 | final Phone phone = getPhone(subId); |
| 6216 | try { |
| 6217 | if (phone != null) { |
| 6218 | if (DBG) { |
| 6219 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6220 | + " isEnable=" + isEnable); |
| 6221 | } |
| 6222 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6223 | } else { |
| 6224 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6225 | + subId); |
| 6226 | } |
| 6227 | } finally { |
| 6228 | Binder.restoreCallingIdentity(identity); |
| 6229 | } |
| 6230 | } |
| 6231 | |
| 6232 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6233 | * Get the user enabled state of Mobile Data. |
| 6234 | * |
| 6235 | * TODO: remove and use isUserDataEnabled. |
| 6236 | * This can't be removed now because some vendor codes |
| 6237 | * calls through ITelephony directly while they should |
| 6238 | * use TelephonyManager. |
| 6239 | * |
| 6240 | * @return true on enabled |
| 6241 | */ |
| 6242 | @Override |
| 6243 | public boolean getDataEnabled(int subId) { |
| 6244 | return isUserDataEnabled(subId); |
| 6245 | } |
| 6246 | |
| 6247 | /** |
| 6248 | * Get whether mobile data is enabled per user setting. |
| 6249 | * |
| 6250 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6251 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6252 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6253 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6254 | * |
| 6255 | * @return {@code true} if data is enabled else {@code false} |
| 6256 | */ |
| 6257 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6258 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6259 | try { |
| 6260 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6261 | null); |
| 6262 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6264 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6265 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6266 | |
| 6267 | final long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
| 6269 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6270 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6271 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6272 | if (phone != null) { |
| 6273 | boolean retVal = phone.isUserDataEnabled(); |
| 6274 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6275 | return retVal; |
| 6276 | } else { |
| 6277 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6278 | return false; |
| 6279 | } |
| 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6282 | } |
| 6283 | } |
| 6284 | |
| 6285 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6286 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6287 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6288 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6289 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6290 | * @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] | 6291 | */ |
| 6292 | @Override |
| 6293 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6294 | try { |
| 6295 | try { |
| 6296 | mApp.enforceCallingOrSelfPermission( |
| 6297 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6298 | null); |
| 6299 | } catch (Exception e) { |
| 6300 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6301 | "isDataEnabled"); |
| 6302 | } |
| 6303 | } catch (Exception e) { |
| 6304 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6305 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | |
| 6307 | final long identity = Binder.clearCallingIdentity(); |
| 6308 | try { |
| 6309 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6310 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6311 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6312 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6313 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6314 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6315 | return retVal; |
| 6316 | } else { |
| 6317 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6318 | return false; |
| 6319 | } |
| 6320 | } finally { |
| 6321 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6322 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6323 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6324 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6325 | /** |
| 6326 | * Check if data is enabled for a specific reason |
| 6327 | * @param subId Subscription index |
| 6328 | * @param reason the reason the data enable change is taking place |
| 6329 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6330 | */ |
| 6331 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6332 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6333 | @TelephonyManager.DataEnabledReason int reason) { |
| 6334 | try { |
| 6335 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6336 | null); |
| 6337 | } catch (Exception e) { |
| 6338 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6339 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6340 | } |
| 6341 | |
| 6342 | |
| 6343 | final long identity = Binder.clearCallingIdentity(); |
| 6344 | try { |
| 6345 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6346 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6347 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6348 | + " reason=" + reason); |
| 6349 | } |
| 6350 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6351 | if (phone != null) { |
| 6352 | boolean retVal; |
| 6353 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6354 | retVal = phone.isUserDataEnabled(); |
| 6355 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6356 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6357 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6358 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6359 | return retVal; |
| 6360 | } else { |
| 6361 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6362 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6363 | + subId + " retVal=false"); |
| 6364 | } |
| 6365 | return false; |
| 6366 | } |
| 6367 | } finally { |
| 6368 | Binder.restoreCallingIdentity(identity); |
| 6369 | } |
| 6370 | } |
| 6371 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6372 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6373 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6374 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6375 | // Skip the check if it's one of these special uids |
| 6376 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6377 | } |
| 6378 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6379 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6380 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6381 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6382 | || subController == null) return privilegeFromSim; |
| 6383 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6384 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6385 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6386 | |
| 6387 | final long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6389 | int subId = phone.getSubId(); |
| 6390 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6391 | // A test override is in place for the privileges for this subId, so don't try to |
| 6392 | // read the subscription privileges. |
| 6393 | return privilegeFromSim; |
| 6394 | } |
| 6395 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6396 | SubscriptionManager subManager = (SubscriptionManager) |
| 6397 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6398 | for (String pkg : packages) { |
| 6399 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6400 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6401 | } |
| 6402 | } |
| 6403 | return privilegeFromSim; |
| 6404 | } finally { |
| 6405 | Binder.restoreCallingIdentity(identity); |
| 6406 | } |
| 6407 | } |
| 6408 | |
| 6409 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6410 | String pkgName) { |
| 6411 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6412 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6413 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6414 | || subController == null) return privilegeFromSim; |
| 6415 | |
| 6416 | final long identity = Binder.clearCallingIdentity(); |
| 6417 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6418 | int subId = phone.getSubId(); |
| 6419 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6420 | // A test override is in place for the privileges for this subId, so don't try to |
| 6421 | // read the subscription privileges. |
| 6422 | return privilegeFromSim; |
| 6423 | } |
| 6424 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6425 | SubscriptionManager subManager = (SubscriptionManager) |
| 6426 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6427 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6428 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
| 6431 | } |
| 6432 | } |
| 6433 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6434 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6435 | public int getCarrierPrivilegeStatus(int subId) { |
| 6436 | final Phone phone = getPhone(subId); |
| 6437 | if (phone == null) { |
| 6438 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6439 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6440 | } |
| 6441 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6442 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6443 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6444 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6445 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6446 | |
| 6447 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6448 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6449 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6450 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6451 | |
| 6452 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6453 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6454 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6455 | final Phone phone = getPhone(subId); |
| 6456 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6457 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6458 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6459 | } |
| 6460 | UiccProfile profile = |
| 6461 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6462 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6463 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6464 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6465 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6466 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6467 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6468 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6472 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6473 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6474 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6478 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6479 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6480 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6481 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6482 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6483 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6484 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6485 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
| 6488 | @Override |
| 6489 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6490 | if (TextUtils.isEmpty(pkgName)) |
| 6491 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6492 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6493 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6494 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6495 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6496 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6497 | continue; |
| 6498 | } |
| 6499 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6500 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6501 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6502 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6503 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6504 | break; |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6509 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6510 | |
| 6511 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6512 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6513 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6514 | loge("phoneId " + phoneId + " is not valid."); |
| 6515 | return null; |
| 6516 | } |
| 6517 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6518 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6519 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6520 | return null ; |
| 6521 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6522 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6523 | } |
| 6524 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6525 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6526 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6527 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6528 | List<String> privilegedPackages = new ArrayList<>(); |
| 6529 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6530 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6531 | // has UICC in that slot. |
| 6532 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6533 | if (card.hasCarrierPrivilegeRules()) { |
| 6534 | if (packages == null) { |
| 6535 | // Only check packages in user 0 for now |
| 6536 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6537 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6538 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6539 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6540 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6541 | } |
| 6542 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6543 | PackageInfo pkgInfo = packages.get(p); |
| 6544 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6545 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6546 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6547 | privilegedPackages.add(pkgInfo.packageName); |
| 6548 | } |
| 6549 | } |
| 6550 | } |
| 6551 | } |
| 6552 | return privilegedPackages; |
| 6553 | } |
| 6554 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6555 | @Override |
| 6556 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6557 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6558 | |
| 6559 | final long identity = Binder.clearCallingIdentity(); |
| 6560 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6561 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6562 | try { |
| 6563 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6564 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6565 | } |
| 6566 | } finally { |
| 6567 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6568 | } |
| 6569 | return privilegedPackages; |
| 6570 | } |
| 6571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6572 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6573 | final Phone phone = getPhone(subId); |
| 6574 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6575 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6576 | return null; |
| 6577 | } |
| 6578 | String iccId = card.getIccId(); |
| 6579 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6580 | return null; |
| 6581 | } |
| 6582 | return iccId; |
| 6583 | } |
| 6584 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6585 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6586 | public void setCallComposerStatus(int subId, int status) { |
| 6587 | enforceModifyPermission(); |
| 6588 | |
| 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | Phone phone = getPhone(subId); |
| 6592 | if (phone != null) { |
| 6593 | Phone defaultPhone = phone.getImsPhone(); |
| 6594 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6595 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6596 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6597 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6598 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6599 | } |
| 6600 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6601 | } catch (ImsException e) { |
| 6602 | throw new ServiceSpecificException(e.getCode()); |
| 6603 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6604 | Binder.restoreCallingIdentity(identity); |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | @Override |
| 6609 | public int getCallComposerStatus(int subId) { |
| 6610 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6611 | |
| 6612 | final long identity = Binder.clearCallingIdentity(); |
| 6613 | try { |
| 6614 | Phone phone = getPhone(subId); |
| 6615 | if (phone != null) { |
| 6616 | Phone defaultPhone = phone.getImsPhone(); |
| 6617 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6618 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6619 | return imsPhone.getCallComposerStatus(); |
| 6620 | } |
| 6621 | } |
| 6622 | } finally { |
| 6623 | Binder.restoreCallingIdentity(identity); |
| 6624 | } |
| 6625 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6626 | } |
| 6627 | |
| 6628 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6629 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6630 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6631 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6632 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6634 | final long identity = Binder.clearCallingIdentity(); |
| 6635 | try { |
| 6636 | final String iccId = getIccId(subId); |
| 6637 | final Phone phone = getPhone(subId); |
| 6638 | if (phone == null) { |
| 6639 | return false; |
| 6640 | } |
| 6641 | final String subscriberId = phone.getSubscriberId(); |
| 6642 | |
| 6643 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6644 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6645 | + subscriberId + " to " + number); |
| 6646 | } |
| 6647 | |
| 6648 | if (TextUtils.isEmpty(iccId)) { |
| 6649 | return false; |
| 6650 | } |
| 6651 | |
| 6652 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6653 | |
| 6654 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6655 | if (alphaTag == null) { |
| 6656 | editor.remove(alphaTagPrefKey); |
| 6657 | } else { |
| 6658 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6659 | } |
| 6660 | |
| 6661 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6662 | // track all merged IMSIs based on line number |
| 6663 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6664 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6665 | if (number == null) { |
| 6666 | editor.remove(numberPrefKey); |
| 6667 | editor.remove(subscriberPrefKey); |
| 6668 | } else { |
| 6669 | editor.putString(numberPrefKey, number); |
| 6670 | editor.putString(subscriberPrefKey, subscriberId); |
| 6671 | } |
| 6672 | |
| 6673 | editor.commit(); |
| 6674 | return true; |
| 6675 | } finally { |
| 6676 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6677 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6678 | } |
| 6679 | |
| 6680 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6681 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6682 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6683 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6685 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6686 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6687 | return null; |
| 6688 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6690 | final long identity = Binder.clearCallingIdentity(); |
| 6691 | try { |
| 6692 | String iccId = getIccId(subId); |
| 6693 | if (iccId != null) { |
| 6694 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6695 | if (DBG_MERGE) { |
| 6696 | log("getLine1NumberForDisplay returning " |
| 6697 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6698 | } |
| 6699 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6700 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6701 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6702 | return null; |
| 6703 | } finally { |
| 6704 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6705 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6706 | } |
| 6707 | |
| 6708 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6709 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6710 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6712 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6713 | return null; |
| 6714 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6715 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6716 | final long identity = Binder.clearCallingIdentity(); |
| 6717 | try { |
| 6718 | String iccId = getIccId(subId); |
| 6719 | if (iccId != null) { |
| 6720 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6721 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6722 | } |
| 6723 | return null; |
| 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6726 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6727 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6728 | |
| 6729 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6730 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6731 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6732 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6733 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6734 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6735 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6736 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6737 | return null; |
| 6738 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6739 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6740 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6741 | // the process, where TelephonyManager was instantiated. |
| 6742 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6745 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6747 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6748 | |
| 6749 | // Figure out what subscribers are currently active |
| 6750 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6751 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6752 | // Only consider subs which match the current subId |
| 6753 | // This logic can be simplified. See b/131189269 for progress. |
| 6754 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6755 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6756 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6757 | |
| 6758 | // First pass, find a number override for an active subscriber |
| 6759 | String mergeNumber = null; |
| 6760 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6761 | for (String key : prefs.keySet()) { |
| 6762 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6763 | final String subscriberId = (String) prefs.get(key); |
| 6764 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6765 | final String iccId = key.substring( |
| 6766 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6767 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6768 | mergeNumber = (String) prefs.get(numberKey); |
| 6769 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6770 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | + " for active subscriber " + subscriberId); |
| 6772 | } |
| 6773 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6774 | break; |
| 6775 | } |
| 6776 | } |
| 6777 | } |
| 6778 | } |
| 6779 | |
| 6780 | // Shortcut when no active merged subscribers |
| 6781 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6782 | return null; |
| 6783 | } |
| 6784 | |
| 6785 | // Second pass, find all subscribers under that line override |
| 6786 | final ArraySet<String> result = new ArraySet<>(); |
| 6787 | for (String key : prefs.keySet()) { |
| 6788 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6789 | final String number = (String) prefs.get(key); |
| 6790 | if (mergeNumber.equals(number)) { |
| 6791 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6792 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6793 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6794 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6795 | result.add(subscriberId); |
| 6796 | } |
| 6797 | } |
| 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6802 | Arrays.sort(resultArray); |
| 6803 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6804 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6806 | } |
| 6807 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6808 | } finally { |
| 6809 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6810 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6814 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6815 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6816 | |
| 6817 | final long identity = Binder.clearCallingIdentity(); |
| 6818 | try { |
| 6819 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6820 | TelephonyManager.class); |
| 6821 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6822 | if (subscriberId == null) { |
| 6823 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6824 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6825 | + subId); |
| 6826 | } |
| 6827 | return null; |
| 6828 | } |
| 6829 | |
| 6830 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6831 | .getSubscriptionInfo(subId); |
| 6832 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6833 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6834 | if (groupUuid == null) { |
| 6835 | return new String[]{subscriberId}; |
| 6836 | } |
| 6837 | |
| 6838 | // Get all subscriberIds from the group. |
| 6839 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6840 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6841 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6842 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6843 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6844 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6845 | if (subscriberId != null) { |
| 6846 | mergedSubscriberIds.add(subscriberId); |
| 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(identity); |
| 6853 | |
| 6854 | } |
| 6855 | } |
| 6856 | |
| 6857 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6858 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6859 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6860 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | |
| 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | final Phone phone = getPhone(subId); |
| 6865 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6866 | } finally { |
| 6867 | Binder.restoreCallingIdentity(identity); |
| 6868 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6869 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6870 | |
| 6871 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6872 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6873 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6874 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6875 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6876 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6877 | |
| 6878 | final long identity = Binder.clearCallingIdentity(); |
| 6879 | try { |
| 6880 | final Phone phone = getPhone(subId); |
| 6881 | if (phone == null) { |
| 6882 | return false; |
| 6883 | } |
| 6884 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6885 | cdmaNonRoamingList); |
| 6886 | } finally { |
| 6887 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6888 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6892 | @Deprecated |
| 6893 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6894 | enforceModifyPermission(); |
| 6895 | |
| 6896 | int returnValue = 0; |
| 6897 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6898 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6899 | if(result.exception == null) { |
| 6900 | if (result.result != null) { |
| 6901 | byte[] responseData = (byte[])(result.result); |
| 6902 | if(responseData.length > oemResp.length) { |
| 6903 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6904 | responseData.length + "bytes. Buffer Size is " + |
| 6905 | oemResp.length + "bytes."); |
| 6906 | } |
| 6907 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6908 | returnValue = responseData.length; |
| 6909 | } |
| 6910 | } else { |
| 6911 | CommandException ex = (CommandException) result.exception; |
| 6912 | returnValue = ex.getCommandError().ordinal(); |
| 6913 | if(returnValue > 0) returnValue *= -1; |
| 6914 | } |
| 6915 | } catch (RuntimeException e) { |
| 6916 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6917 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6918 | if(returnValue > 0) returnValue *= -1; |
| 6919 | } |
| 6920 | |
| 6921 | return returnValue; |
| 6922 | } |
| 6923 | |
| 6924 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6925 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6926 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6927 | try { |
| 6928 | TelephonyPermissions |
| 6929 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6930 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6931 | } catch (SecurityException e) { |
| 6932 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6933 | throw e; |
| 6934 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6935 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6936 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6937 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6938 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6939 | final long identity = Binder.clearCallingIdentity(); |
| 6940 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6941 | TelephonyPermissions |
| 6942 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6943 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6944 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6945 | } finally { |
| 6946 | Binder.restoreCallingIdentity(identity); |
| 6947 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6948 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6949 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6950 | |
| 6951 | @Override |
| 6952 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6953 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6954 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 | |
| 6956 | final long identity = Binder.clearCallingIdentity(); |
| 6957 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6958 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6959 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6960 | } finally { |
| 6961 | Binder.restoreCallingIdentity(identity); |
| 6962 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6966 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6967 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6968 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6969 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6970 | return false; |
| 6971 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6973 | final long identity = Binder.clearCallingIdentity(); |
| 6974 | try { |
| 6975 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6976 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6977 | // In the long run, we may instead need to check if there exists a connection service |
| 6978 | // which can support video calling. |
| 6979 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6980 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6981 | return imsManager.isVtEnabledByPlatform() |
| 6982 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6983 | && imsManager.isVtEnabledByUser(); |
| 6984 | } finally { |
| 6985 | Binder.restoreCallingIdentity(identity); |
| 6986 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6987 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6988 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6989 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6990 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6991 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6993 | mApp, subId, callingPackage, callingFeatureId, |
| 6994 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | return false; |
| 6996 | } |
| 6997 | |
| 6998 | final long identity = Binder.clearCallingIdentity(); |
| 6999 | try { |
| 7000 | CarrierConfigManager configManager = |
| 7001 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7002 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7004 | } finally { |
| 7005 | Binder.restoreCallingIdentity(identity); |
| 7006 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7007 | } |
| 7008 | |
| 7009 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7010 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7012 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7013 | return false; |
| 7014 | } |
| 7015 | |
| 7016 | final long identity = Binder.clearCallingIdentity(); |
| 7017 | try { |
| 7018 | CarrierConfigManager configManager = |
| 7019 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7020 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7021 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7022 | } finally { |
| 7023 | Binder.restoreCallingIdentity(identity); |
| 7024 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7025 | } |
| 7026 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7027 | @Override |
| 7028 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7029 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7030 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7031 | } |
| 7032 | |
| 7033 | @Override |
| 7034 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | final long identity = Binder.clearCallingIdentity(); |
| 7036 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7037 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | } finally { |
| 7039 | Binder.restoreCallingIdentity(identity); |
| 7040 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7041 | } |
| 7042 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7043 | /** |
| 7044 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7045 | * support for the feature and device firmware support. |
| 7046 | * |
| 7047 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7048 | */ |
| 7049 | @Override |
| 7050 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7051 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7052 | final Phone phone = getPhone(subscriptionId); |
| 7053 | if (phone == null) { |
| 7054 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7055 | return false; |
| 7056 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7058 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7060 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7061 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7062 | return isCarrierSupported && isDeviceSupported; |
| 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
| 7065 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7066 | } |
| 7067 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7068 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7069 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7070 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7071 | * 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] | 7072 | */ |
| 7073 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7074 | final long identity = Binder.clearCallingIdentity(); |
| 7075 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7076 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7077 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7078 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7079 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7080 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7081 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
| 7084 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7085 | } |
| 7086 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7087 | @Deprecated |
| 7088 | @Override |
| 7089 | public String getDeviceId(String callingPackage) { |
| 7090 | return getDeviceIdWithFeature(callingPackage, null); |
| 7091 | } |
| 7092 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7093 | /** |
| 7094 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7095 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7096 | * |
| 7097 | * <p>Requires Permission: |
| 7098 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7099 | */ |
| 7100 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7101 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7102 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7103 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7104 | return null; |
| 7105 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7106 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7107 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7108 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7109 | return null; |
| 7110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7111 | |
| 7112 | final long identity = Binder.clearCallingIdentity(); |
| 7113 | try { |
| 7114 | return phone.getDeviceId(); |
| 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
| 7117 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7118 | } |
| 7119 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7120 | /** |
| 7121 | * {@hide} |
| 7122 | * Returns the IMS Registration Status on a particular subid |
| 7123 | * |
| 7124 | * @param subId |
| 7125 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7126 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7127 | Phone phone = getPhone(subId); |
| 7128 | if (phone != null) { |
| 7129 | return phone.isImsRegistered(); |
| 7130 | } else { |
| 7131 | return false; |
| 7132 | } |
| 7133 | } |
| 7134 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7135 | @Override |
| 7136 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | final long identity = Binder.clearCallingIdentity(); |
| 7138 | try { |
| 7139 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7143 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7144 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7145 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7146 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7147 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7149 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7150 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7151 | } |
| 7152 | final long identity = Binder.clearCallingIdentity(); |
| 7153 | try { |
| 7154 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7155 | } finally { |
| 7156 | Binder.restoreCallingIdentity(identity); |
| 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7161 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7162 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7163 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7164 | final long identity = Binder.clearCallingIdentity(); |
| 7165 | try { |
| 7166 | Phone phone = getPhone(subscriptionId); |
| 7167 | if (phone == null) { |
| 7168 | return null; |
| 7169 | } |
| 7170 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7171 | } finally { |
| 7172 | Binder.restoreCallingIdentity(identity); |
| 7173 | } |
| 7174 | } |
| 7175 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7176 | /** |
| 7177 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7178 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7179 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | Phone phone = getPhone(subId); |
| 7183 | if (phone != null) { |
| 7184 | return phone.isWifiCallingEnabled(); |
| 7185 | } else { |
| 7186 | return false; |
| 7187 | } |
| 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7190 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7191 | } |
| 7192 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7193 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7194 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7195 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7196 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7197 | final long identity = Binder.clearCallingIdentity(); |
| 7198 | try { |
| 7199 | Phone phone = getPhone(subId); |
| 7200 | if (phone != null) { |
| 7201 | return phone.isVideoEnabled(); |
| 7202 | } else { |
| 7203 | return false; |
| 7204 | } |
| 7205 | } finally { |
| 7206 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7207 | } |
| 7208 | } |
| 7209 | |
| 7210 | /** |
| 7211 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7212 | * defined in {@link ImsRegistrationImplBase}. |
| 7213 | */ |
| 7214 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7215 | final long identity = Binder.clearCallingIdentity(); |
| 7216 | try { |
| 7217 | Phone phone = getPhone(subId); |
| 7218 | if (phone != null) { |
| 7219 | return phone.getImsRegistrationTech(); |
| 7220 | } else { |
| 7221 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7222 | } |
| 7223 | } finally { |
| 7224 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7225 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7226 | } |
| 7227 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7228 | @Override |
| 7229 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7230 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7231 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7232 | return; |
| 7233 | } |
| 7234 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7235 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7236 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7237 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7238 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7239 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7240 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7241 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7242 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7243 | setAllowedNetworkTypesForReason(subId, |
| 7244 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7245 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7246 | setAllowedNetworkTypesForReason(subId, |
| 7247 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7248 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7249 | setAllowedNetworkTypesForReason(subId, |
| 7250 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7251 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7252 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7253 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7254 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7255 | // There has been issues when Sms raw table somehow stores orphan |
| 7256 | // fragments. They lead to garbled message when new fragments come |
| 7257 | // in and combined with those stale ones. In case this happens again, |
| 7258 | // user can reset all network settings which will clean up this table. |
| 7259 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7260 | // Clean up IMS settings as well here. |
| 7261 | int slotId = getSlotIndex(subId); |
| 7262 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7263 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7264 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7265 | |
| 7266 | // Erase modem config if erase modem on network setting is enabled. |
| 7267 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7268 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7269 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7270 | sendEraseModemConfig(getDefaultPhone()); |
| 7271 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7272 | } finally { |
| 7273 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7274 | } |
| 7275 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7276 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7277 | private void cleanUpSmsRawTable(Context context) { |
| 7278 | ContentResolver resolver = context.getContentResolver(); |
| 7279 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7280 | resolver.delete(uri, null, null); |
| 7281 | } |
| 7282 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7283 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7284 | public String getSimLocaleForSubscriber(int subId) { |
| 7285 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7286 | final Phone phone = getPhone(subId); |
| 7287 | if (phone == null) { |
| 7288 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7289 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7293 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7294 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7295 | if (info == null) { |
| 7296 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7297 | return null; |
| 7298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7299 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7300 | // preferences (EF-PL and EF-LI)... |
| 7301 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7303 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7304 | if (localeFromDefaultSim != null) { |
| 7305 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7306 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7307 | + localeFromDefaultSim); |
| 7308 | return localeFromDefaultSim.toLanguageTag(); |
| 7309 | } else { |
| 7310 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7311 | } |
| 7312 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7313 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7314 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7315 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7316 | // the SIM and carrier preferences does not include a country we add the country |
| 7317 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7318 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7320 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7321 | return mccLocale.toLanguageTag(); |
| 7322 | } |
| 7323 | |
| 7324 | if (DBG) log("No locale found - returning null"); |
| 7325 | return null; |
| 7326 | } finally { |
| 7327 | Binder.restoreCallingIdentity(identity); |
| 7328 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7329 | } |
| 7330 | |
| 7331 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7332 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7333 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7334 | } |
| 7335 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7336 | /** |
| 7337 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7338 | */ |
| 7339 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7340 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7341 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7342 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7343 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7344 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7345 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7346 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7347 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7348 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7349 | * representing the state of the modem. |
| 7350 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7351 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7352 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7353 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7354 | */ |
| 7355 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7356 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7357 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7358 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7359 | |
| 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7362 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7363 | } finally { |
| 7364 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7365 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7366 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7367 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7368 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7369 | // less than total activity duration. |
| 7370 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7371 | if (info == null) { |
| 7372 | return false; |
| 7373 | } |
| 7374 | int activityDurationMs = |
| 7375 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7376 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7377 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7378 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7379 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7380 | } |
| 7381 | return (info.isValid() |
| 7382 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7383 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7384 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7385 | && (totalTxTimeMs <= activityDurationMs)); |
| 7386 | } |
| 7387 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7388 | /** |
| 7389 | * {@hide} |
| 7390 | * Returns the service state information on specified subscription. |
| 7391 | */ |
| 7392 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7393 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7394 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7395 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7396 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7397 | return null; |
| 7398 | } |
| 7399 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7400 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7401 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7402 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7403 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7404 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7405 | .setCallingPid(Binder.getCallingPid()) |
| 7406 | .setCallingUid(Binder.getCallingUid()) |
| 7407 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7408 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7409 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7410 | .build()); |
| 7411 | |
| 7412 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7413 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7414 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7415 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7416 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7417 | .setCallingPid(Binder.getCallingPid()) |
| 7418 | .setCallingUid(Binder.getCallingUid()) |
| 7419 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7420 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7421 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7422 | .build()); |
| 7423 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7424 | boolean hasFinePermission = |
| 7425 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7426 | boolean hasCoarsePermission = |
| 7427 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7429 | final long identity = Binder.clearCallingIdentity(); |
| 7430 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7431 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7432 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7433 | Rlog.d(LOG_TAG, |
| 7434 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7435 | return null; |
| 7436 | } |
| 7437 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | final Phone phone = getPhone(subId); |
| 7439 | if (phone == null) { |
| 7440 | return null; |
| 7441 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7442 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7443 | ServiceState ss = phone.getServiceState(); |
| 7444 | |
| 7445 | // Scrub out the location info in ServiceState depending on what level of access |
| 7446 | // the caller has. |
| 7447 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7448 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7449 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | } finally { |
| 7451 | Binder.restoreCallingIdentity(identity); |
| 7452 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7453 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7454 | |
| 7455 | /** |
| 7456 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7457 | * |
| 7458 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7459 | * voicemail ringtone. |
| 7460 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7461 | * PhoneAccount. |
| 7462 | */ |
| 7463 | @Override |
| 7464 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | final long identity = Binder.clearCallingIdentity(); |
| 7466 | try { |
| 7467 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7468 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7469 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7473 | } finally { |
| 7474 | Binder.restoreCallingIdentity(identity); |
| 7475 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7476 | } |
| 7477 | |
| 7478 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7479 | * Sets the per-account voicemail ringtone. |
| 7480 | * |
| 7481 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7482 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7483 | * |
| 7484 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7485 | * voicemail ringtone. |
| 7486 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7487 | * PhoneAccount. |
| 7488 | */ |
| 7489 | @Override |
| 7490 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7491 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7492 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7493 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7494 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7495 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7497 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7498 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7499 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | |
| 7501 | final long identity = Binder.clearCallingIdentity(); |
| 7502 | try { |
| 7503 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7504 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7505 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | } |
| 7507 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7508 | } finally { |
| 7509 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7510 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7511 | } |
| 7512 | |
| 7513 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7514 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7515 | * |
| 7516 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7517 | * voicemail vibration setting. |
| 7518 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7519 | */ |
| 7520 | @Override |
| 7521 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | final long identity = Binder.clearCallingIdentity(); |
| 7523 | try { |
| 7524 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7525 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7526 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7528 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7533 | } |
| 7534 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7535 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7536 | * Sets the per-account voicemail vibration. |
| 7537 | * |
| 7538 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7539 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7540 | * |
| 7541 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7542 | * voicemail vibration setting. |
| 7543 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7544 | * specific PhoneAccount. |
| 7545 | */ |
| 7546 | @Override |
| 7547 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7548 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7549 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7550 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7551 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7552 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7554 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7555 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7556 | } |
| 7557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | final long identity = Binder.clearCallingIdentity(); |
| 7559 | try { |
| 7560 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7561 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7562 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7563 | } |
| 7564 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7565 | } finally { |
| 7566 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7567 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7568 | } |
| 7569 | |
| 7570 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7571 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7572 | * |
| 7573 | * @throws SecurityException if the caller does not have the required permission |
| 7574 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7575 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7576 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7577 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7581 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7582 | * permission. |
| 7583 | * |
| 7584 | * @throws SecurityException if the caller does not have the required permission |
| 7585 | */ |
| 7586 | private void enforceSendSmsPermission() { |
| 7587 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7588 | } |
| 7589 | |
| 7590 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7591 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7592 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7593 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7594 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7595 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | final long identity = Binder.clearCallingIdentity(); |
| 7597 | try { |
| 7598 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7599 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | if (componentName == null) { |
| 7601 | throw new SecurityException( |
| 7602 | "Caller not current active visual voicemail package[null]"); |
| 7603 | } |
| 7604 | String vvmPackage = componentName.getPackageName(); |
| 7605 | if (!callingPackage.equals(vvmPackage)) { |
| 7606 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7607 | + vvmPackage + "]"); |
| 7608 | } |
| 7609 | } finally { |
| 7610 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7611 | } |
| 7612 | } |
| 7613 | |
| 7614 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7615 | * Return the application ID for the app type. |
| 7616 | * |
| 7617 | * @param subId the subscription ID that this request applies to. |
| 7618 | * @param appType the uicc app type. |
| 7619 | * @return Application ID for specificied app type, or null if no uicc. |
| 7620 | */ |
| 7621 | @Override |
| 7622 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7623 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7624 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | |
| 7626 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7627 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7628 | if (phone == null) { |
| 7629 | return null; |
| 7630 | } |
| 7631 | String aid = null; |
| 7632 | try { |
| 7633 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7634 | .getApplicationByType(appType).getAid(); |
| 7635 | } catch (Exception e) { |
| 7636 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7637 | } |
| 7638 | return aid; |
| 7639 | } finally { |
| 7640 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7641 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7642 | } |
| 7643 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7644 | /** |
| 7645 | * Return the Electronic Serial Number. |
| 7646 | * |
| 7647 | * @param subId the subscription ID that this request applies to. |
| 7648 | * @return ESN or null if error. |
| 7649 | */ |
| 7650 | @Override |
| 7651 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7652 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7653 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | |
| 7655 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7656 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7657 | if (phone == null) { |
| 7658 | return null; |
| 7659 | } |
| 7660 | String esn = null; |
| 7661 | try { |
| 7662 | esn = phone.getEsn(); |
| 7663 | } catch (Exception e) { |
| 7664 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7665 | } |
| 7666 | return esn; |
| 7667 | } finally { |
| 7668 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7669 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7672 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7673 | * Return the Preferred Roaming List Version. |
| 7674 | * |
| 7675 | * @param subId the subscription ID that this request applies to. |
| 7676 | * @return PRLVersion or null if error. |
| 7677 | */ |
| 7678 | @Override |
| 7679 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7680 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7681 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7682 | |
| 7683 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7684 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7685 | if (phone == null) { |
| 7686 | return null; |
| 7687 | } |
| 7688 | String cdmaPrlVersion = null; |
| 7689 | try { |
| 7690 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7691 | } catch (Exception e) { |
| 7692 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7693 | } |
| 7694 | return cdmaPrlVersion; |
| 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7697 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7698 | } |
| 7699 | |
| 7700 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7701 | * Get snapshot of Telephony histograms |
| 7702 | * @return List of Telephony histograms |
| 7703 | * @hide |
| 7704 | */ |
| 7705 | @Override |
| 7706 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7707 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7708 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7709 | |
| 7710 | final long identity = Binder.clearCallingIdentity(); |
| 7711 | try { |
| 7712 | return RIL.getTelephonyRILTimingHistograms(); |
| 7713 | } finally { |
| 7714 | Binder.restoreCallingIdentity(identity); |
| 7715 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7716 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7717 | |
| 7718 | /** |
| 7719 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7720 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7721 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7722 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7723 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7724 | * @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] | 7725 | */ |
| 7726 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7727 | @TelephonyManager.SetCarrierRestrictionResult |
| 7728 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7729 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7730 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7731 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7732 | if (carrierRestrictionRules == null) { |
| 7733 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7734 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7735 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7736 | final long identity = Binder.clearCallingIdentity(); |
| 7737 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7738 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7739 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7740 | } finally { |
| 7741 | Binder.restoreCallingIdentity(identity); |
| 7742 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | /** |
| 7746 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7747 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7748 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7749 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7750 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7751 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7752 | */ |
| 7753 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7754 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7755 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7756 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7760 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7761 | if (response instanceof CarrierRestrictionRules) { |
| 7762 | return (CarrierRestrictionRules) response; |
| 7763 | } |
| 7764 | // Response is an Exception of some kind, |
| 7765 | // which is signalled to the user as a NULL retval |
| 7766 | return null; |
| 7767 | } catch (Exception e) { |
| 7768 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7769 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
| 7772 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7773 | } |
| 7774 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7775 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7776 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7777 | * @param subId the subscription ID that this action applies to. |
| 7778 | * @param enabled control enable or disable radio. |
| 7779 | * {@hide} |
| 7780 | */ |
| 7781 | @Override |
| 7782 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7783 | enforceModifyPermission(); |
| 7784 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | |
| 7786 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7787 | if (phone == null) { |
| 7788 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7789 | return; |
| 7790 | } |
| 7791 | try { |
| 7792 | phone.carrierActionSetRadioEnabled(enabled); |
| 7793 | } catch (Exception e) { |
| 7794 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7795 | } finally { |
| 7796 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7797 | } |
| 7798 | } |
| 7799 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7800 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7801 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7802 | * network status based on which carrier apps could apply actions accordingly, |
| 7803 | * enable/disable default url handler for example. |
| 7804 | * |
| 7805 | * @param subId the subscription ID that this action applies to. |
| 7806 | * @param report control start/stop reporting the default network status. |
| 7807 | * {@hide} |
| 7808 | */ |
| 7809 | @Override |
| 7810 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7811 | enforceModifyPermission(); |
| 7812 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7813 | |
| 7814 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7815 | if (phone == null) { |
| 7816 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7817 | return; |
| 7818 | } |
| 7819 | try { |
| 7820 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7821 | } catch (Exception e) { |
| 7822 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7823 | } finally { |
| 7824 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
| 7828 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7829 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7830 | * @param subId the subscription ID that this action applies to. |
| 7831 | * {@hide} |
| 7832 | */ |
| 7833 | @Override |
| 7834 | public void carrierActionResetAll(int subId) { |
| 7835 | enforceModifyPermission(); |
| 7836 | final Phone phone = getPhone(subId); |
| 7837 | if (phone == null) { |
| 7838 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7839 | return; |
| 7840 | } |
| 7841 | try { |
| 7842 | phone.carrierActionResetAll(); |
| 7843 | } catch (Exception e) { |
| 7844 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7845 | } |
| 7846 | } |
| 7847 | |
| 7848 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7849 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7850 | * bug report is being generated. |
| 7851 | */ |
| 7852 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7853 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7854 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7855 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7856 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7857 | + Binder.getCallingPid() |
| 7858 | + ", uid=" + Binder.getCallingUid() |
| 7859 | + "without permission " |
| 7860 | + android.Manifest.permission.DUMP); |
| 7861 | return; |
| 7862 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7863 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7864 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7865 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7866 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7867 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7868 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7869 | @NonNull String[] args) { |
| 7870 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7871 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7872 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7873 | } |
| 7874 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7875 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7876 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7877 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7878 | * @param reason the reason the data enable change is taking place |
| 7879 | * @param enabled True if enabling the data, otherwise disabling. |
| 7880 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7881 | */ |
| 7882 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7883 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7884 | boolean enabled) { |
| 7885 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7886 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7887 | try { |
| 7888 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7889 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7890 | } catch (SecurityException se) { |
| 7891 | enforceModifyPermission(); |
| 7892 | } |
| 7893 | } else { |
| 7894 | enforceModifyPermission(); |
| 7895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7896 | |
| 7897 | final long identity = Binder.clearCallingIdentity(); |
| 7898 | try { |
| 7899 | Phone phone = getPhone(subId); |
| 7900 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7901 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7902 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7903 | } else { |
| 7904 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7906 | } |
| 7907 | } finally { |
| 7908 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7909 | } |
| 7910 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7911 | |
| 7912 | /** |
| 7913 | * Get Client request stats |
| 7914 | * @return List of Client Request Stats |
| 7915 | * @hide |
| 7916 | */ |
| 7917 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7918 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7919 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7920 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7921 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7922 | return null; |
| 7923 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7924 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7925 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7926 | final long identity = Binder.clearCallingIdentity(); |
| 7927 | try { |
| 7928 | if (phone != null) { |
| 7929 | return phone.getClientRequestStats(); |
| 7930 | } |
| 7931 | |
| 7932 | return null; |
| 7933 | } finally { |
| 7934 | Binder.restoreCallingIdentity(identity); |
| 7935 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7938 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7939 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7940 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7941 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7942 | |
| 7943 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7944 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7945 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7946 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7947 | * @param state State of SIM (power down, power up, pass through) |
| 7948 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7949 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7950 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7951 | * |
| 7952 | **/ |
| 7953 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7954 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7955 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7956 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7957 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7958 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7960 | final long identity = Binder.clearCallingIdentity(); |
| 7961 | try { |
| 7962 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7963 | phone.setSimPowerState(state, null, workSource); |
| 7964 | } |
| 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
| 7967 | } |
| 7968 | } |
| 7969 | |
| 7970 | /** |
| 7971 | * Set SIM card power state. |
| 7972 | * |
| 7973 | * @param slotIndex SIM slot id. |
| 7974 | * @param state State of SIM (power down, power up, pass through) |
| 7975 | * @param callback callback to trigger after success or failure |
| 7976 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7977 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7978 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7979 | * |
| 7980 | **/ |
| 7981 | @Override |
| 7982 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7983 | IIntegerConsumer callback) { |
| 7984 | enforceModifyPermission(); |
| 7985 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7986 | |
| 7987 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7988 | |
| 7989 | final long identity = Binder.clearCallingIdentity(); |
| 7990 | try { |
| 7991 | if (phone != null) { |
| 7992 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7993 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7994 | } |
| 7995 | } finally { |
| 7996 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7997 | } |
| 7998 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7999 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8000 | private boolean isUssdApiAllowed(int subId) { |
| 8001 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8002 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8003 | if (configManager == null) { |
| 8004 | return false; |
| 8005 | } |
| 8006 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8007 | if (pb == null) { |
| 8008 | return false; |
| 8009 | } |
| 8010 | return pb.getBoolean( |
| 8011 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8012 | } |
| 8013 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8014 | /** |
| 8015 | * Check if phone is in emergency callback mode |
| 8016 | * @return true if phone is in emergency callback mode |
| 8017 | * @param subId sub id |
| 8018 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8019 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8020 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8021 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8022 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8023 | |
| 8024 | final long identity = Binder.clearCallingIdentity(); |
| 8025 | try { |
| 8026 | if (phone != null) { |
| 8027 | return phone.isInEcm(); |
| 8028 | } else { |
| 8029 | return false; |
| 8030 | } |
| 8031 | } finally { |
| 8032 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8033 | } |
| 8034 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8035 | |
| 8036 | /** |
| 8037 | * Get the current signal strength information for the given subscription. |
| 8038 | * Because this information is not updated when the device is in a low power state |
| 8039 | * it should not be relied-upon to be current. |
| 8040 | * @param subId Subscription index |
| 8041 | * @return the most recent cached signal strength info from the modem |
| 8042 | */ |
| 8043 | @Override |
| 8044 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8045 | final long identity = Binder.clearCallingIdentity(); |
| 8046 | try { |
| 8047 | Phone p = getPhone(subId); |
| 8048 | if (p == null) { |
| 8049 | return null; |
| 8050 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8052 | return p.getSignalStrength(); |
| 8053 | } finally { |
| 8054 | Binder.restoreCallingIdentity(identity); |
| 8055 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8056 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8057 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8058 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8059 | * Get the current modem radio state for the given slot. |
| 8060 | * @param slotIndex slot index. |
| 8061 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8062 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8063 | * @return the current radio power state from the modem |
| 8064 | */ |
| 8065 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8066 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8067 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8068 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8069 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8070 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8071 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8072 | } |
| 8073 | |
| 8074 | final long identity = Binder.clearCallingIdentity(); |
| 8075 | try { |
| 8076 | return phone.getRadioPowerState(); |
| 8077 | } finally { |
| 8078 | Binder.restoreCallingIdentity(identity); |
| 8079 | } |
| 8080 | } |
| 8081 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8082 | } |
| 8083 | |
| 8084 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8085 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8086 | * |
| 8087 | * <p>Requires one of the following permissions: |
| 8088 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8089 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8090 | * privileges. |
| 8091 | * |
| 8092 | * @param subId subscription id |
| 8093 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8094 | * {@code false}. |
| 8095 | */ |
| 8096 | @Override |
| 8097 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8098 | try { |
| 8099 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8100 | null); |
| 8101 | } catch (Exception e) { |
| 8102 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8103 | mApp, subId, "isDataRoamingEnabled"); |
| 8104 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8105 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8106 | boolean isEnabled = false; |
| 8107 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8108 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8109 | Phone phone = getPhone(subId); |
| 8110 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8111 | } finally { |
| 8112 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8113 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8114 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8115 | } |
| 8116 | |
| 8117 | |
| 8118 | /** |
| 8119 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8120 | * |
| 8121 | * <p> Requires permission: |
| 8122 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8123 | * privileges. |
| 8124 | * |
| 8125 | * @param subId subscription id |
| 8126 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8131 | mApp, subId, "setDataRoamingEnabled"); |
| 8132 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8133 | final long identity = Binder.clearCallingIdentity(); |
| 8134 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8135 | Phone phone = getPhone(subId); |
| 8136 | if (phone != null) { |
| 8137 | phone.setDataRoamingEnabled(isEnabled); |
| 8138 | } |
| 8139 | } finally { |
| 8140 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8141 | } |
| 8142 | } |
| 8143 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8144 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8145 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8146 | TelephonyPermissions |
| 8147 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8148 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8149 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8150 | boolean isAllowed = true; |
| 8151 | final long identity = Binder.clearCallingIdentity(); |
| 8152 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8153 | Phone phone = getPhone(subId); |
| 8154 | if (phone != null) { |
| 8155 | isAllowed = phone.isCspPlmnEnabled(); |
| 8156 | } |
| 8157 | } finally { |
| 8158 | Binder.restoreCallingIdentity(identity); |
| 8159 | } |
| 8160 | return isAllowed; |
| 8161 | } |
| 8162 | |
| 8163 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8164 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8165 | // Verify that tha callingPackage belongs to the calling UID |
| 8166 | mApp.getSystemService(AppOpsManager.class) |
| 8167 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8168 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8169 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8170 | try { |
| 8171 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8172 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8173 | } catch (SecurityException e) { |
| 8174 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8175 | // has carrier privileges on an active UICC |
| 8176 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8177 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8178 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8179 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8180 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8181 | |
| 8182 | final long identity = Binder.clearCallingIdentity(); |
| 8183 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8184 | UiccController uiccController = UiccController.getInstance(); |
| 8185 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8186 | if (hasReadPermission) { |
| 8187 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8188 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8189 | |
| 8190 | // Remove private info if the caller doesn't have access |
| 8191 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8192 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8193 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8194 | // is available |
| 8195 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8196 | if (card == null || card.getUiccProfile() == null) { |
| 8197 | // assume no access if the card or profile is unavailable |
| 8198 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8199 | continue; |
| 8200 | } |
| 8201 | UiccProfile profile = card.getUiccProfile(); |
| 8202 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8203 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8204 | filteredInfos.add(cardInfo); |
| 8205 | } else { |
| 8206 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8207 | } |
| 8208 | } |
| 8209 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8210 | } finally { |
| 8211 | Binder.restoreCallingIdentity(identity); |
| 8212 | } |
| 8213 | } |
| 8214 | |
| 8215 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8216 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8217 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8219 | final long identity = Binder.clearCallingIdentity(); |
| 8220 | try { |
| 8221 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8222 | if (slots == null) { |
| 8223 | Rlog.i(LOG_TAG, "slots is null."); |
| 8224 | return null; |
| 8225 | } |
| 8226 | |
| 8227 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8228 | for (int i = 0; i < slots.length; i++) { |
| 8229 | UiccSlot slot = slots[i]; |
| 8230 | if (slot == null) { |
| 8231 | continue; |
| 8232 | } |
| 8233 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8234 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8235 | UiccCard card = slot.getUiccCard(); |
| 8236 | if (card != null) { |
| 8237 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8238 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8239 | cardId = slot.getEid(); |
| 8240 | if (TextUtils.isEmpty(cardId)) { |
| 8241 | cardId = slot.getIccId(); |
| 8242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | } |
| 8244 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8245 | if (cardId != null) { |
| 8246 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8247 | // if cardId is an EID, it's all digits so this is fine |
| 8248 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8249 | } |
| 8250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | int cardState = 0; |
| 8252 | switch (slot.getCardState()) { |
| 8253 | case CARDSTATE_ABSENT: |
| 8254 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8255 | break; |
| 8256 | case CARDSTATE_PRESENT: |
| 8257 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8258 | break; |
| 8259 | case CARDSTATE_ERROR: |
| 8260 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8261 | break; |
| 8262 | case CARDSTATE_RESTRICTED: |
| 8263 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8264 | break; |
| 8265 | default: |
| 8266 | break; |
| 8267 | |
| 8268 | } |
| 8269 | |
| 8270 | infos[i] = new UiccSlotInfo( |
| 8271 | slot.isActive(), |
| 8272 | slot.isEuicc(), |
| 8273 | cardId, |
| 8274 | cardState, |
| 8275 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8276 | slot.isExtendedApduSupported(), |
| 8277 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8278 | } |
| 8279 | return infos; |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8282 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | @Override |
| 8286 | public boolean switchSlots(int[] physicalSlots) { |
| 8287 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8288 | |
| 8289 | final long identity = Binder.clearCallingIdentity(); |
| 8290 | try { |
| 8291 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8292 | } finally { |
| 8293 | Binder.restoreCallingIdentity(identity); |
| 8294 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8295 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8296 | |
| 8297 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8298 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8299 | final long identity = Binder.clearCallingIdentity(); |
| 8300 | try { |
| 8301 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
| 8304 | } |
| 8305 | } |
| 8306 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8307 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8308 | * A test API to reload the UICC profile. |
| 8309 | * |
| 8310 | * <p>Requires that the calling app has permission |
| 8311 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8312 | * @hide |
| 8313 | */ |
| 8314 | @Override |
| 8315 | public void refreshUiccProfile(int subId) { |
| 8316 | enforceModifyPermission(); |
| 8317 | |
| 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | try { |
| 8320 | Phone phone = getPhone(subId); |
| 8321 | if (phone == null) { |
| 8322 | return; |
| 8323 | } |
| 8324 | UiccCard uiccCard = phone.getUiccCard(); |
| 8325 | if (uiccCard == null) { |
| 8326 | return; |
| 8327 | } |
| 8328 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8329 | if (uiccProfile == null) { |
| 8330 | return; |
| 8331 | } |
| 8332 | uiccProfile.refresh(); |
| 8333 | } finally { |
| 8334 | Binder.restoreCallingIdentity(identity); |
| 8335 | } |
| 8336 | } |
| 8337 | |
| 8338 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8339 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8340 | */ |
| 8341 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8342 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8343 | } |
| 8344 | |
| 8345 | /** |
| 8346 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8347 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8348 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8349 | */ |
| 8350 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8351 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8352 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8353 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8354 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8355 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8356 | return isDataRoamingEnabled; |
| 8357 | } |
| 8358 | |
| 8359 | /** |
| 8360 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8361 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8362 | */ |
| 8363 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8364 | List<Integer> list = TelephonyProperties.default_network(); |
| 8365 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8366 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8367 | return list.get(phoneId); |
| 8368 | } |
| 8369 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8370 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8371 | |
| 8372 | @Override |
| 8373 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8374 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8375 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8376 | |
| 8377 | final long identity = Binder.clearCallingIdentity(); |
| 8378 | try { |
| 8379 | final Phone phone = getPhone(subId); |
| 8380 | if (phone == null) { |
| 8381 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8382 | return; |
| 8383 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8384 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8385 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8386 | if (carrierPrivilegeRules == null) { |
| 8387 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8388 | } else { |
| 8389 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8390 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | } finally { |
| 8392 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8393 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8394 | } |
| 8395 | |
| 8396 | @Override |
| 8397 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8398 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8399 | |
| 8400 | final long identity = Binder.clearCallingIdentity(); |
| 8401 | try { |
| 8402 | final Phone phone = getPhone(subId); |
| 8403 | if (phone == null) { |
| 8404 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8405 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8406 | } |
| 8407 | return phone.getCarrierIdListVersion(); |
| 8408 | } finally { |
| 8409 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8410 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8411 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8412 | |
| 8413 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8414 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8415 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8416 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8417 | mApp, subId, callingPackage, callingFeatureId, |
| 8418 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8419 | return -1; |
| 8420 | } |
| 8421 | |
| 8422 | final long identity = Binder.clearCallingIdentity(); |
| 8423 | try { |
| 8424 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8425 | } finally { |
| 8426 | Binder.restoreCallingIdentity(identity); |
| 8427 | } |
| 8428 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8429 | |
| 8430 | @Override |
| 8431 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8432 | TelephonyPermissions |
| 8433 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8434 | mApp, subId, "getCdmaRoamingMode"); |
| 8435 | |
| 8436 | final long identity = Binder.clearCallingIdentity(); |
| 8437 | try { |
| 8438 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8439 | } finally { |
| 8440 | Binder.restoreCallingIdentity(identity); |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | @Override |
| 8445 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8447 | mApp, subId, "setCdmaRoamingMode"); |
| 8448 | |
| 8449 | final long identity = Binder.clearCallingIdentity(); |
| 8450 | try { |
| 8451 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8452 | } finally { |
| 8453 | Binder.restoreCallingIdentity(identity); |
| 8454 | } |
| 8455 | } |
| 8456 | |
| 8457 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8458 | public int getCdmaSubscriptionMode(int subId) { |
| 8459 | TelephonyPermissions |
| 8460 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8461 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8462 | |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
| 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8472 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8474 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8475 | |
| 8476 | final long identity = Binder.clearCallingIdentity(); |
| 8477 | try { |
| 8478 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8479 | } finally { |
| 8480 | Binder.restoreCallingIdentity(identity); |
| 8481 | } |
| 8482 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8483 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8484 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8485 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8486 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8488 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8489 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8490 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8491 | } |
| 8492 | final long identity = Binder.clearCallingIdentity(); |
| 8493 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8494 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8495 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8496 | if (phone.getEmergencyNumberTracker() != null |
| 8497 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8498 | emergencyNumberListInternal.put( |
| 8499 | phone.getSubId(), |
| 8500 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8501 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8502 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8503 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8504 | } finally { |
| 8505 | Binder.restoreCallingIdentity(identity); |
| 8506 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8507 | } |
| 8508 | |
| 8509 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8510 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8511 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8512 | if (!exactMatch) { |
| 8513 | TelephonyPermissions |
| 8514 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8515 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8516 | } |
| 8517 | final long identity = Binder.clearCallingIdentity(); |
| 8518 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8519 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8520 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8521 | && phone.getEmergencyNumberTracker() |
| 8522 | .isEmergencyNumber(number, exactMatch)) { |
| 8523 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8524 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8525 | } |
| 8526 | return false; |
| 8527 | } finally { |
| 8528 | Binder.restoreCallingIdentity(identity); |
| 8529 | } |
| 8530 | } |
| 8531 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8532 | /** |
| 8533 | * Update emergency number list for test mode. |
| 8534 | */ |
| 8535 | @Override |
| 8536 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8537 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8538 | "updateEmergencyNumberListTestMode"); |
| 8539 | |
| 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
| 8542 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8543 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8544 | if (tracker != null) { |
| 8545 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8546 | } |
| 8547 | } |
| 8548 | } finally { |
| 8549 | Binder.restoreCallingIdentity(identity); |
| 8550 | } |
| 8551 | } |
| 8552 | |
| 8553 | /** |
| 8554 | * Get the full emergency number list for test mode. |
| 8555 | */ |
| 8556 | @Override |
| 8557 | public List<String> getEmergencyNumberListTestMode() { |
| 8558 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8559 | "getEmergencyNumberListTestMode"); |
| 8560 | |
| 8561 | final long identity = Binder.clearCallingIdentity(); |
| 8562 | try { |
| 8563 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8564 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8565 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8566 | if (tracker != null) { |
| 8567 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8568 | emergencyNumbers.add(num.getNumber()); |
| 8569 | } |
| 8570 | } |
| 8571 | } |
| 8572 | return new ArrayList<>(emergencyNumbers); |
| 8573 | } finally { |
| 8574 | Binder.restoreCallingIdentity(identity); |
| 8575 | } |
| 8576 | } |
| 8577 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8578 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8579 | public int getEmergencyNumberDbVersion(int subId) { |
| 8580 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8581 | |
| 8582 | final long identity = Binder.clearCallingIdentity(); |
| 8583 | try { |
| 8584 | final Phone phone = getPhone(subId); |
| 8585 | if (phone == null) { |
| 8586 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8587 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8588 | } |
| 8589 | return phone.getEmergencyNumberDbVersion(); |
| 8590 | } finally { |
| 8591 | Binder.restoreCallingIdentity(identity); |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | @Override |
| 8596 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8597 | enforceModifyPermission(); |
| 8598 | |
| 8599 | final long identity = Binder.clearCallingIdentity(); |
| 8600 | try { |
| 8601 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8602 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8603 | if (tracker != null) { |
| 8604 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8605 | } |
| 8606 | } |
| 8607 | } finally { |
| 8608 | Binder.restoreCallingIdentity(identity); |
| 8609 | } |
| 8610 | } |
| 8611 | |
| 8612 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8613 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8614 | enforceActiveEmergencySessionPermission(); |
| 8615 | |
| 8616 | final long identity = Binder.clearCallingIdentity(); |
| 8617 | try { |
| 8618 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8619 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8620 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8621 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8622 | } |
| 8623 | } |
| 8624 | } finally { |
| 8625 | Binder.restoreCallingIdentity(identity); |
| 8626 | } |
| 8627 | } |
| 8628 | |
| 8629 | @Override |
| 8630 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8631 | enforceActiveEmergencySessionPermission(); |
| 8632 | |
| 8633 | final long identity = Binder.clearCallingIdentity(); |
| 8634 | try { |
| 8635 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8636 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8637 | if (tracker != null) { |
| 8638 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8639 | } |
| 8640 | } |
| 8641 | } finally { |
| 8642 | Binder.restoreCallingIdentity(identity); |
| 8643 | } |
| 8644 | } |
| 8645 | |
| 8646 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8647 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8648 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8649 | Phone phone = getPhone(subId); |
| 8650 | if (phone == null) { |
| 8651 | return null; |
| 8652 | } |
| 8653 | final long identity = Binder.clearCallingIdentity(); |
| 8654 | try { |
| 8655 | UiccProfile profile = UiccController.getInstance() |
| 8656 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8657 | if (profile != null) { |
| 8658 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8659 | } |
| 8660 | } finally { |
| 8661 | Binder.restoreCallingIdentity(identity); |
| 8662 | } |
| 8663 | return null; |
| 8664 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8665 | |
| 8666 | /** |
| 8667 | * Enable or disable a modem stack. |
| 8668 | */ |
| 8669 | @Override |
| 8670 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8671 | enforceModifyPermission(); |
| 8672 | |
| 8673 | final long identity = Binder.clearCallingIdentity(); |
| 8674 | try { |
| 8675 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8676 | if (phone == null) { |
| 8677 | return false; |
| 8678 | } else { |
| 8679 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8680 | } |
| 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
| 8684 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8685 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8686 | /** |
| 8687 | * Whether a modem stack is enabled or not. |
| 8688 | */ |
| 8689 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8690 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8691 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8692 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8693 | if (phone == null) return false; |
| 8694 | |
| 8695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8696 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8697 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8698 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8699 | } |
| 8700 | |
| 8701 | final long identity = Binder.clearCallingIdentity(); |
| 8702 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8703 | try { |
| 8704 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8705 | } catch (NoSuchElementException ex) { |
| 8706 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8707 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8708 | } finally { |
| 8709 | Binder.restoreCallingIdentity(identity); |
| 8710 | } |
| 8711 | } |
| 8712 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8713 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8714 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8715 | enforceModifyPermission(); |
| 8716 | |
| 8717 | final long identity = Binder.clearCallingIdentity(); |
| 8718 | try { |
| 8719 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8720 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8721 | .commit(); |
| 8722 | } finally { |
| 8723 | Binder.restoreCallingIdentity(identity); |
| 8724 | } |
| 8725 | } |
| 8726 | |
| 8727 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8728 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8729 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8730 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8731 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8732 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8733 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8734 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8735 | |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
| 8737 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8738 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8739 | } finally { |
| 8740 | Binder.restoreCallingIdentity(identity); |
| 8741 | } |
| 8742 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8743 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8744 | @TelephonyManager.IsMultiSimSupportedResult |
| 8745 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8746 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8747 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8748 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8749 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8750 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8751 | } |
| 8752 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8753 | // supported by the modem, indicate that it is restricted. |
| 8754 | PhoneCapability staticCapability = |
| 8755 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8756 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8757 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8758 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8759 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8760 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8761 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8762 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8763 | } |
| 8764 | // Check if support of multiple SIMs is restricted by carrier |
| 8765 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8766 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8767 | } |
| 8768 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8769 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8770 | } |
| 8771 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8772 | /** |
| 8773 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8774 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8775 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8776 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8777 | * @param numOfSims number of active sims we want to switch to |
| 8778 | */ |
| 8779 | @Override |
| 8780 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8781 | if (numOfSims == 1) { |
| 8782 | enforceModifyPermission(); |
| 8783 | } else { |
| 8784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8785 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8786 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8787 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8788 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8789 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8790 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8791 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8792 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8793 | return; |
| 8794 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8795 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8796 | } finally { |
| 8797 | Binder.restoreCallingIdentity(identity); |
| 8798 | } |
| 8799 | } |
| 8800 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8801 | @Override |
| 8802 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8803 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8804 | Phone phone = getPhone(subId); |
| 8805 | if (phone == null) { |
| 8806 | return false; |
| 8807 | } |
| 8808 | final long identity = Binder.clearCallingIdentity(); |
| 8809 | try { |
| 8810 | UiccCard uiccCard = phone.getUiccCard(); |
| 8811 | if (uiccCard == null) { |
| 8812 | return false; |
| 8813 | } |
| 8814 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8815 | if (uiccProfile == null) { |
| 8816 | return false; |
| 8817 | } |
| 8818 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8819 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8820 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8821 | } |
| 8822 | return false; |
| 8823 | } finally { |
| 8824 | Binder.restoreCallingIdentity(identity); |
| 8825 | } |
| 8826 | } |
| 8827 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8828 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8829 | * Get whether making changes to modem configurations will trigger reboot. |
| 8830 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8831 | */ |
| 8832 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8833 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8834 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8835 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8836 | mApp, subId, callingPackage, callingFeatureId, |
| 8837 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8838 | return false; |
| 8839 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8840 | final long identity = Binder.clearCallingIdentity(); |
| 8841 | try { |
| 8842 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8843 | } finally { |
| 8844 | Binder.restoreCallingIdentity(identity); |
| 8845 | } |
| 8846 | } |
| 8847 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8848 | private void updateModemStateMetrics() { |
| 8849 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8850 | // TODO: check the state for each modem if the api is ready. |
| 8851 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8852 | } |
| 8853 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8854 | @Override |
| 8855 | public int[] getSlotsMapping() { |
| 8856 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8857 | |
| 8858 | final long identity = Binder.clearCallingIdentity(); |
| 8859 | try { |
| 8860 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8861 | // All logical slots should have a mapping to a physical slot. |
| 8862 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8863 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8864 | for (int i = 0; i < slotInfos.length; i++) { |
| 8865 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8866 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8867 | } |
| 8868 | } |
| 8869 | return logicalSlotsMapping; |
| 8870 | } finally { |
| 8871 | Binder.restoreCallingIdentity(identity); |
| 8872 | } |
| 8873 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8874 | |
| 8875 | /** |
| 8876 | * Get the IRadio HAL Version |
| 8877 | */ |
| 8878 | @Override |
| 8879 | public int getRadioHalVersion() { |
| 8880 | Phone phone = getDefaultPhone(); |
| 8881 | if (phone == null) return -1; |
| 8882 | HalVersion hv = phone.getHalVersion(); |
| 8883 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8884 | return hv.major * 100 + hv.minor; |
| 8885 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8886 | |
| 8887 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8888 | * Get the current calling package name. |
| 8889 | * @return the current calling package name |
| 8890 | */ |
| 8891 | @Override |
| 8892 | public String getCurrentPackageName() { |
| 8893 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8894 | } |
| 8895 | |
| 8896 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8897 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8898 | * corresponding network requests on a subId. |
| 8899 | * |
| 8900 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8901 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8902 | * 2) APN is un-metered for this subscription, or |
| 8903 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8904 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8905 | * |
| 8906 | * @return whether data is allowed for a apn type. |
| 8907 | * |
| 8908 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8909 | */ |
| 8910 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8911 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8912 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8913 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8914 | |
| 8915 | // Now that all security checks passes, perform the operation as ourselves. |
| 8916 | final long identity = Binder.clearCallingIdentity(); |
| 8917 | try { |
| 8918 | Phone phone = getPhone(subId); |
| 8919 | if (phone == null) return false; |
| 8920 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8921 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8922 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8923 | } finally { |
| 8924 | Binder.restoreCallingIdentity(identity); |
| 8925 | } |
| 8926 | } |
| 8927 | |
| 8928 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8929 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8930 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8931 | |
| 8932 | // Now that all security checks passes, perform the operation as ourselves. |
| 8933 | final long identity = Binder.clearCallingIdentity(); |
| 8934 | try { |
| 8935 | Phone phone = getPhone(subId); |
| 8936 | if (phone == null) return true; // By default return true. |
| 8937 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8938 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8939 | } finally { |
| 8940 | Binder.restoreCallingIdentity(identity); |
| 8941 | } |
| 8942 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8943 | |
| 8944 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8945 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8946 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8947 | enforceModifyPermission(); |
| 8948 | long token = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | Phone phone = getPhone(subscriptionId); |
| 8951 | if (phone == null) { |
| 8952 | try { |
| 8953 | if (resultCallback != null) { |
| 8954 | resultCallback.accept(false); |
| 8955 | } |
| 8956 | } catch (RemoteException e) { |
| 8957 | // ignore |
| 8958 | } |
| 8959 | return; |
| 8960 | } |
| 8961 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8962 | Pair.create(specifiers, (x) -> { |
| 8963 | try { |
| 8964 | if (resultCallback != null) { |
| 8965 | resultCallback.accept(x); |
| 8966 | } |
| 8967 | } catch (RemoteException e) { |
| 8968 | // ignore |
| 8969 | } |
| 8970 | }); |
| 8971 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8972 | } finally { |
| 8973 | Binder.restoreCallingIdentity(token); |
| 8974 | } |
| 8975 | } |
| 8976 | |
| 8977 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8978 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8979 | TelephonyPermissions |
| 8980 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8981 | mApp, subId, "getSystemSelectionChannels"); |
| 8982 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8983 | final long identity = Binder.clearCallingIdentity(); |
| 8984 | try { |
| 8985 | List<RadioAccessSpecifier> specifiers = |
| 8986 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8987 | null, subId, workSource); |
| 8988 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8989 | return specifiers; |
| 8990 | } finally { |
| 8991 | Binder.restoreCallingIdentity(identity); |
| 8992 | } |
| 8993 | } |
| 8994 | |
| 8995 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8996 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8997 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8998 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8999 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9000 | if (iccRecords == null) { |
| 9001 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9002 | return false; |
| 9003 | } |
| 9004 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9005 | } |
| 9006 | |
| 9007 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9008 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9009 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9010 | if (callingPackage == null) { |
| 9011 | callingPackage = getCurrentPackageName(); |
| 9012 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9013 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9014 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9015 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9016 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9017 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9018 | } |
| 9019 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9020 | Intent intent = new Intent(); |
| 9021 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9022 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9023 | // Bring up choose default SMS subscription dialog right now |
| 9024 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9025 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9026 | mApp.startActivity(intent); |
| 9027 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9028 | |
| 9029 | @Override |
| 9030 | public String getMmsUAProfUrl(int subId) { |
| 9031 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9032 | final long identity = Binder.clearCallingIdentity(); |
| 9033 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9034 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9035 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9036 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9037 | return carrierUAProfUrl; |
| 9038 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9039 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9040 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9041 | } finally { |
| 9042 | Binder.restoreCallingIdentity(identity); |
| 9043 | } |
| 9044 | } |
| 9045 | |
| 9046 | @Override |
| 9047 | public String getMmsUserAgent(int subId) { |
| 9048 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9049 | final long identity = Binder.clearCallingIdentity(); |
| 9050 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9051 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9052 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9053 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9054 | return carrierUserAgent; |
| 9055 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9056 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9057 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9058 | } finally { |
| 9059 | Binder.restoreCallingIdentity(identity); |
| 9060 | } |
| 9061 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9062 | |
| 9063 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9064 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9065 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9066 | |
| 9067 | final long identity = Binder.clearCallingIdentity(); |
| 9068 | try { |
| 9069 | Phone phone = getPhone(subscriptionId); |
| 9070 | if (phone == null) return false; |
| 9071 | |
| 9072 | switch (policy) { |
| 9073 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9074 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9075 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9076 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9077 | default: |
| 9078 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9079 | } |
| 9080 | } finally { |
| 9081 | Binder.restoreCallingIdentity(identity); |
| 9082 | } |
| 9083 | } |
| 9084 | |
| 9085 | @Override |
| 9086 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9087 | boolean enabled) { |
| 9088 | enforceModifyPermission(); |
| 9089 | |
| 9090 | final long identity = Binder.clearCallingIdentity(); |
| 9091 | try { |
| 9092 | Phone phone = getPhone(subscriptionId); |
| 9093 | if (phone == null) return; |
| 9094 | |
| 9095 | switch (policy) { |
| 9096 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9097 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9098 | break; |
| 9099 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9100 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9101 | break; |
| 9102 | default: |
| 9103 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9104 | } |
| 9105 | } finally { |
| 9106 | Binder.restoreCallingIdentity(identity); |
| 9107 | } |
| 9108 | } |
| 9109 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9110 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9111 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9112 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9113 | * otherwise. |
| 9114 | */ |
| 9115 | @Override |
| 9116 | public void setCepEnabled(boolean isCepEnabled) { |
| 9117 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9118 | |
| 9119 | final long identity = Binder.clearCallingIdentity(); |
| 9120 | try { |
| 9121 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9122 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9123 | Phone defaultPhone = phone.getImsPhone(); |
| 9124 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9125 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9126 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9127 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9128 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9129 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9130 | + imsPhone.getMsisdn()); |
| 9131 | } |
| 9132 | } |
| 9133 | } finally { |
| 9134 | Binder.restoreCallingIdentity(identity); |
| 9135 | } |
| 9136 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9137 | |
| 9138 | /** |
| 9139 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9140 | * |
| 9141 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9142 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9143 | * before being read. |
| 9144 | */ |
| 9145 | @Override |
| 9146 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9147 | isCompressed) { |
| 9148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9149 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9150 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9151 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9152 | } |
| 9153 | if (!isImsAvailableOnDevice()) { |
| 9154 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9155 | "IMS not available on device."); |
| 9156 | } |
| 9157 | |
| 9158 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9159 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9160 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9161 | } finally { |
| 9162 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9163 | } |
| 9164 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9165 | |
| 9166 | @Override |
| 9167 | public boolean isIccLockEnabled(int subId) { |
| 9168 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9169 | |
| 9170 | // Now that all security checks passes, perform the operation as ourselves. |
| 9171 | final long identity = Binder.clearCallingIdentity(); |
| 9172 | try { |
| 9173 | Phone phone = getPhone(subId); |
| 9174 | if (phone != null && phone.getIccCard() != null) { |
| 9175 | return phone.getIccCard().getIccLockEnabled(); |
| 9176 | } else { |
| 9177 | return false; |
| 9178 | } |
| 9179 | } finally { |
| 9180 | Binder.restoreCallingIdentity(identity); |
| 9181 | } |
| 9182 | } |
| 9183 | |
| 9184 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9185 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9186 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9187 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9188 | * three cases: |
| 9189 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9190 | * successfully. |
| 9191 | * - Positive number and zero for remaining password attempts. |
| 9192 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9193 | * |
| 9194 | */ |
| 9195 | @Override |
| 9196 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9197 | enforceModifyPermission(); |
| 9198 | |
| 9199 | Phone phone = getPhone(subId); |
| 9200 | if (phone == null) { |
| 9201 | return 0; |
| 9202 | } |
| 9203 | // Now that all security checks passes, perform the operation as ourselves. |
| 9204 | final long identity = Binder.clearCallingIdentity(); |
| 9205 | try { |
| 9206 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9207 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9208 | return attemptsRemaining; |
| 9209 | |
| 9210 | } catch (Exception e) { |
| 9211 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9212 | } finally { |
| 9213 | Binder.restoreCallingIdentity(identity); |
| 9214 | } |
| 9215 | return 0; |
| 9216 | } |
| 9217 | |
| 9218 | /** |
| 9219 | * Change the ICC password used in ICC pin lock. |
| 9220 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9221 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9222 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9223 | * - Positive number and zero for remaining password attempts. |
| 9224 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9225 | * |
| 9226 | */ |
| 9227 | @Override |
| 9228 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9229 | enforceModifyPermission(); |
| 9230 | |
| 9231 | Phone phone = getPhone(subId); |
| 9232 | if (phone == null) { |
| 9233 | return 0; |
| 9234 | } |
| 9235 | // Now that all security checks passes, perform the operation as ourselves. |
| 9236 | final long identity = Binder.clearCallingIdentity(); |
| 9237 | try { |
| 9238 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9239 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9240 | return attemptsRemaining; |
| 9241 | |
| 9242 | } catch (Exception e) { |
| 9243 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9244 | } finally { |
| 9245 | Binder.restoreCallingIdentity(identity); |
| 9246 | } |
| 9247 | return 0; |
| 9248 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9249 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9250 | /** |
| 9251 | * Request for receiving user activity notification |
| 9252 | */ |
| 9253 | @Override |
| 9254 | public void requestUserActivityNotification() { |
| 9255 | if (!mNotifyUserActivity.get() |
| 9256 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9257 | mNotifyUserActivity.set(true); |
| 9258 | } |
| 9259 | } |
| 9260 | |
| 9261 | /** |
| 9262 | * Called when userActivity is signalled in the power manager. |
| 9263 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9264 | */ |
| 9265 | @Override |
| 9266 | public void userActivity() { |
| 9267 | // *************************************** |
| 9268 | // * Inherited from PhoneWindowManager * |
| 9269 | // *************************************** |
| 9270 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9271 | // WITH ITS LOCKS HELD. |
| 9272 | // |
| 9273 | // This code must be VERY careful about the locks |
| 9274 | // it acquires. |
| 9275 | // In fact, the current code acquires way too many, |
| 9276 | // and probably has lurking deadlocks. |
| 9277 | |
| 9278 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9279 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9280 | } |
| 9281 | |
| 9282 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9283 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9284 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9285 | } |
| 9286 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9287 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9288 | @Override |
| 9289 | public boolean canConnectTo5GInDsdsMode() { |
| 9290 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9291 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9292 | |
| 9293 | @Override |
| 9294 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9295 | String callingFeatureId) { |
| 9296 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9297 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9298 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9299 | } |
| 9300 | |
| 9301 | Phone phone = getPhone(subId); |
| 9302 | if (phone == null) { |
| 9303 | throw new RuntimeException("phone is not available"); |
| 9304 | } |
| 9305 | // Now that all security checks passes, perform the operation as ourselves. |
| 9306 | final long identity = Binder.clearCallingIdentity(); |
| 9307 | try { |
| 9308 | return phone.getEquivalentHomePlmns(); |
| 9309 | } finally { |
| 9310 | Binder.restoreCallingIdentity(identity); |
| 9311 | } |
| 9312 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9313 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9314 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9315 | public boolean isRadioInterfaceCapabilitySupported( |
| 9316 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9317 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9318 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9319 | if (radioInterfaceCapabilities == null) { |
| 9320 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9321 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9322 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9323 | } |
| 9324 | } |
| 9325 | |
| 9326 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9327 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9328 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9329 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9330 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9331 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9332 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9333 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9334 | if (DBG) { |
| 9335 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9336 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9337 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9338 | } |
| 9339 | |
| 9340 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9341 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9342 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9343 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9344 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9345 | if (callback != null) { |
| 9346 | try { |
| 9347 | callback.onAuthenticationFailure( |
| 9348 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9349 | } catch (RemoteException exception) { |
| 9350 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9351 | } |
| 9352 | return; |
| 9353 | } |
| 9354 | } |
| 9355 | |
| 9356 | final long token = Binder.clearCallingIdentity(); |
| 9357 | try { |
| 9358 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9359 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9360 | forceBootStrapping, callback)); |
| 9361 | } finally { |
| 9362 | Binder.restoreCallingIdentity(token); |
| 9363 | } |
| 9364 | } |
| 9365 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9366 | /** |
| 9367 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9368 | * requested radio power state will actually be set. See {@link |
| 9369 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9370 | * |
| 9371 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9372 | * @param enable {@code true} if trying to turn radio on. |
| 9373 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9374 | * false}. |
| 9375 | */ |
| 9376 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9377 | Phone phone = getPhone(subId); |
| 9378 | if (phone != null) { |
| 9379 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9380 | return true; |
| 9381 | } |
| 9382 | return false; |
| 9383 | } |
| 9384 | |
| 9385 | private int handleDataThrottlingRequest(int subId, |
| 9386 | DataThrottlingRequest dataThrottlingRequest) { |
| 9387 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9388 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9389 | if (!setRadioPowerForThermal(subId, true)) { |
| 9390 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9391 | } |
| 9392 | |
| 9393 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9394 | |
| 9395 | int thermalMitigationResult = |
| 9396 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9397 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9398 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9399 | } |
| 9400 | return thermalMitigationResult; |
| 9401 | } |
| 9402 | |
| 9403 | /** |
| 9404 | * Thermal mitigation request to control functionalities at modem. |
| 9405 | * |
| 9406 | * @param subId the id of the subscription. |
| 9407 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9408 | * |
| 9409 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9410 | */ |
| 9411 | @Override |
| 9412 | @ThermalMitigationResult |
| 9413 | public int sendThermalMitigationRequest( |
| 9414 | int subId, |
| 9415 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9416 | enforceModifyPermission(); |
| 9417 | |
| 9418 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9419 | final long identity = Binder.clearCallingIdentity(); |
| 9420 | |
| 9421 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9422 | try { |
| 9423 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9424 | switch (thermalMitigationAction) { |
| 9425 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9426 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9427 | handleDataThrottlingRequest(subId, |
| 9428 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9429 | break; |
| 9430 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9431 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9432 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9433 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9434 | } |
| 9435 | |
| 9436 | // Ensure that radio is on. If not able to power on due to phone being |
| 9437 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9438 | if (!setRadioPowerForThermal(subId, true)) { |
| 9439 | thermalMitigationResult = |
| 9440 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9441 | break; |
| 9442 | } |
| 9443 | |
| 9444 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9445 | false); |
| 9446 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9447 | break; |
| 9448 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9449 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9450 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9451 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9452 | } |
| 9453 | |
| 9454 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9455 | if (registry != null) { |
| 9456 | TelephonyConnectionService service = |
| 9457 | registry.getTelephonyConnectionService(); |
| 9458 | Phone phone = getPhone(subId); |
| 9459 | if (phone == null) { |
| 9460 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9461 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9462 | break; |
| 9463 | } |
| 9464 | |
| 9465 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9466 | != TelephonyManager.CALL_STATE_IDLE |
| 9467 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9468 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9469 | String errorMessage = "Phone state is not valid. call state = " |
| 9470 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9471 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9472 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9473 | errorMessage += service == null |
| 9474 | ? " TelephonyConnectionService is null" |
| 9475 | : " isEmergencyCallPending = " |
| 9476 | + service.isEmergencyCallPending(); |
| 9477 | Log.e(LOG_TAG, errorMessage); |
| 9478 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9479 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9480 | break; |
| 9481 | } |
| 9482 | } else { |
| 9483 | thermalMitigationResult = |
| 9484 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9485 | break; |
| 9486 | } |
| 9487 | |
| 9488 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9489 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9490 | if (!setRadioPowerForThermal(subId, false)) { |
| 9491 | thermalMitigationResult = |
| 9492 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9493 | break; |
| 9494 | } |
| 9495 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9496 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9497 | break; |
| 9498 | default: |
| 9499 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9500 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9501 | } |
| 9502 | } catch (IllegalArgumentException e) { |
| 9503 | throw e; |
| 9504 | } catch (Exception e) { |
| 9505 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9506 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
| 9510 | |
| 9511 | if (DBG) { |
| 9512 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9513 | + thermalMitigationResult); |
| 9514 | } |
| 9515 | |
| 9516 | return thermalMitigationResult; |
| 9517 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9518 | |
| 9519 | /** |
| 9520 | * Set the GbaService Package Name that Telephony will bind to. |
| 9521 | * |
| 9522 | * @param subId The sim that the GbaService is associated with. |
| 9523 | * @param packageName The name of the package to be replaced with. |
| 9524 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9525 | */ |
| 9526 | @Override |
| 9527 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9528 | enforceModifyPermission(); |
| 9529 | |
| 9530 | final long identity = Binder.clearCallingIdentity(); |
| 9531 | try { |
| 9532 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | /** |
| 9539 | * Return the package name of the currently bound GbaService. |
| 9540 | * |
| 9541 | * @param subId The sim that the GbaService is associated with. |
| 9542 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9543 | */ |
| 9544 | @Override |
| 9545 | public String getBoundGbaService(int subId) { |
| 9546 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9547 | |
| 9548 | final long identity = Binder.clearCallingIdentity(); |
| 9549 | try { |
| 9550 | return getGbaManager(subId).getServicePackage(); |
| 9551 | } finally { |
| 9552 | Binder.restoreCallingIdentity(identity); |
| 9553 | } |
| 9554 | } |
| 9555 | |
| 9556 | /** |
| 9557 | * Set the release time for telephony to unbind GbaService. |
| 9558 | * |
| 9559 | * @param subId The sim that the GbaService is associated with. |
| 9560 | * @param interval The release time to unbind GbaService by millisecond. |
| 9561 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9562 | */ |
| 9563 | @Override |
| 9564 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9565 | enforceModifyPermission(); |
| 9566 | |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9570 | } finally { |
| 9571 | Binder.restoreCallingIdentity(identity); |
| 9572 | } |
| 9573 | } |
| 9574 | |
| 9575 | /** |
| 9576 | * Return the release time for telephony to unbind GbaService. |
| 9577 | * |
| 9578 | * @param subId The sim that the GbaService is associated with. |
| 9579 | * @return The release time to unbind GbaService by millisecond. |
| 9580 | */ |
| 9581 | @Override |
| 9582 | public int getGbaReleaseTime(int subId) { |
| 9583 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9584 | |
| 9585 | final long identity = Binder.clearCallingIdentity(); |
| 9586 | try { |
| 9587 | return getGbaManager(subId).getReleaseTime(); |
| 9588 | } finally { |
| 9589 | Binder.restoreCallingIdentity(identity); |
| 9590 | } |
| 9591 | } |
| 9592 | |
| 9593 | private GbaManager getGbaManager(int subId) { |
| 9594 | GbaManager instance = GbaManager.getInstance(subId); |
| 9595 | if (instance == null) { |
| 9596 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9597 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9598 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9599 | } |
| 9600 | return instance; |
| 9601 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9602 | |
| 9603 | /** |
| 9604 | * indicate whether the device and the carrier can support |
| 9605 | * RCS VoLTE single registration. |
| 9606 | */ |
| 9607 | @Override |
| 9608 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9609 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9610 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9611 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9612 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9613 | |
| 9614 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9615 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9616 | } |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9621 | if (rpm != null) { |
| 9622 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9623 | } |
| 9624 | return false; |
| 9625 | } finally { |
| 9626 | Binder.restoreCallingIdentity(identity); |
| 9627 | } |
| 9628 | } |
| 9629 | |
| 9630 | /** |
| 9631 | * Register RCS provisioning callback. |
| 9632 | */ |
| 9633 | @Override |
| 9634 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9635 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9636 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9637 | Binder.getCallingUid(), "registerRcsProvisioningChangedCallback", |
| 9638 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9639 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9640 | |
| 9641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9642 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9643 | } |
| 9644 | if (!isImsAvailableOnDevice()) { |
| 9645 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9646 | "IMS not available on device."); |
| 9647 | } |
| 9648 | |
| 9649 | final long identity = Binder.clearCallingIdentity(); |
| 9650 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9651 | if (!RcsProvisioningMonitor.getInstance() |
| 9652 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9653 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9654 | "Service not available for the subscription."); |
| 9655 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9656 | } finally { |
| 9657 | Binder.restoreCallingIdentity(identity); |
| 9658 | } |
| 9659 | } |
| 9660 | |
| 9661 | /** |
| 9662 | * Unregister RCS provisioning callback. |
| 9663 | */ |
| 9664 | @Override |
| 9665 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9666 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9667 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9668 | Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback", |
| 9669 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9670 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9671 | |
| 9672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9673 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9674 | } |
| 9675 | if (!isImsAvailableOnDevice()) { |
| 9676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9677 | "IMS not available on device."); |
| 9678 | } |
| 9679 | |
| 9680 | final long identity = Binder.clearCallingIdentity(); |
| 9681 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9682 | RcsProvisioningMonitor.getInstance() |
| 9683 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9684 | } finally { |
| 9685 | Binder.restoreCallingIdentity(identity); |
| 9686 | } |
| 9687 | } |
| 9688 | |
| 9689 | /** |
| 9690 | * trigger RCS reconfiguration. |
| 9691 | */ |
| 9692 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9693 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9694 | "triggerRcsReconfiguration", |
| 9695 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9696 | |
| 9697 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9698 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9699 | } |
| 9700 | if (!isImsAvailableOnDevice()) { |
| 9701 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9702 | "IMS not available on device."); |
| 9703 | } |
| 9704 | |
| 9705 | final long identity = Binder.clearCallingIdentity(); |
| 9706 | try { |
| 9707 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
| 9712 | |
| 9713 | /** |
| 9714 | * Provide the client configuration parameters of the RCS application. |
| 9715 | */ |
| 9716 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9717 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9718 | "setRcsClientConfiguration", |
| 9719 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9720 | |
| 9721 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9722 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9723 | } |
| 9724 | if (!isImsAvailableOnDevice()) { |
| 9725 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9726 | "IMS not available on device."); |
| 9727 | } |
| 9728 | |
| 9729 | final long identity = Binder.clearCallingIdentity(); |
| 9730 | |
| 9731 | try { |
| 9732 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9733 | if (configBinder == null) { |
| 9734 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9735 | } else { |
| 9736 | configBinder.setRcsClientConfiguration(rcc); |
| 9737 | } |
| 9738 | } catch (RemoteException e) { |
| 9739 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9740 | } finally { |
| 9741 | Binder.restoreCallingIdentity(identity); |
| 9742 | } |
| 9743 | } |
| 9744 | |
| 9745 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9746 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9747 | */ |
| 9748 | @Override |
| 9749 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9750 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9751 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9752 | |
| 9753 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9754 | } |
| 9755 | |
| 9756 | /** |
| 9757 | * Gets the test mode for RCS VoLTE single registration. |
| 9758 | */ |
| 9759 | @Override |
| 9760 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9761 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9762 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9763 | |
| 9764 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9765 | } |
| 9766 | |
| 9767 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9768 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9769 | */ |
| 9770 | @Override |
| 9771 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9772 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9773 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9774 | enforceModifyPermission(); |
| 9775 | |
| 9776 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9777 | : Boolean.parseBoolean(enabledStr); |
| 9778 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9779 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9780 | } |
| 9781 | |
| 9782 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9783 | * Sends a device to device communication message. Only usable via shell. |
| 9784 | * @param message message to send. |
| 9785 | * @param value message value. |
| 9786 | */ |
| 9787 | @Override |
| 9788 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9789 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9790 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9791 | enforceModifyPermission(); |
| 9792 | |
| 9793 | final long identity = Binder.clearCallingIdentity(); |
| 9794 | try { |
| 9795 | TelephonyConnectionService service = |
| 9796 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9797 | if (service == null) { |
| 9798 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9799 | return; |
| 9800 | } |
| 9801 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9802 | } finally { |
| 9803 | Binder.restoreCallingIdentity(identity); |
| 9804 | } |
| 9805 | } |
| 9806 | |
| 9807 | |
| 9808 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9809 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9810 | */ |
| 9811 | @Override |
| 9812 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9813 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9814 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9815 | } |
| 9816 | |
| 9817 | /** |
| 9818 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9819 | */ |
| 9820 | @Override |
| 9821 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9822 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9823 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9824 | enforceModifyPermission(); |
| 9825 | |
| 9826 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9827 | : Boolean.parseBoolean(enabledStr); |
| 9828 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9829 | subId, enabled); |
| 9830 | } |
| 9831 | |
| 9832 | /** |
| 9833 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9834 | */ |
| 9835 | @Override |
| 9836 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9837 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9838 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9839 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9840 | |
| 9841 | /** |
| 9842 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9843 | * their mobile plan. |
| 9844 | */ |
| 9845 | @Override |
| 9846 | public String getMobileProvisioningUrl() { |
| 9847 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9848 | final long identity = Binder.clearCallingIdentity(); |
| 9849 | try { |
| 9850 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9851 | } finally { |
| 9852 | Binder.restoreCallingIdentity(identity); |
| 9853 | } |
| 9854 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9855 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9856 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9857 | * Get the EAB contact from the EAB database. |
| 9858 | */ |
| 9859 | @Override |
| 9860 | public String getContactFromEab(String contact) { |
| 9861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9862 | enforceModifyPermission(); |
| 9863 | final long identity = Binder.clearCallingIdentity(); |
| 9864 | try { |
| 9865 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9866 | } finally { |
| 9867 | Binder.restoreCallingIdentity(identity); |
| 9868 | } |
| 9869 | } |
| 9870 | |
| 9871 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9872 | * Remove the EAB contacts from the EAB database. |
| 9873 | */ |
| 9874 | @Override |
| 9875 | public int removeContactFromEab(int subId, String contacts) { |
| 9876 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9877 | enforceModifyPermission(); |
| 9878 | final long identity = Binder.clearCallingIdentity(); |
| 9879 | try { |
| 9880 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9881 | } finally { |
| 9882 | Binder.restoreCallingIdentity(identity); |
| 9883 | } |
| 9884 | } |
| 9885 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9886 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9887 | public boolean getDeviceUceEnabled() { |
| 9888 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9889 | final long identity = Binder.clearCallingIdentity(); |
| 9890 | try { |
| 9891 | return mApp.getDeviceUceEnabled(); |
| 9892 | } finally { |
| 9893 | Binder.restoreCallingIdentity(identity); |
| 9894 | } |
| 9895 | } |
| 9896 | |
| 9897 | @Override |
| 9898 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9899 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9900 | final long identity = Binder.clearCallingIdentity(); |
| 9901 | try { |
| 9902 | mApp.setDeviceUceEnabled(isEnabled); |
| 9903 | } finally { |
| 9904 | Binder.restoreCallingIdentity(identity); |
| 9905 | } |
| 9906 | } |
| 9907 | |
| 9908 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9909 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9910 | String callingPackage) { |
| 9911 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9912 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9913 | |
| 9914 | final int callingUid = Binder.getCallingUid(); |
| 9915 | // Verify that tha callingPackage belongs to the calling UID |
| 9916 | mApp.getSystemService(AppOpsManager.class) |
| 9917 | .checkPackage(callingUid, callingPackage); |
| 9918 | |
| 9919 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9920 | |
| 9921 | final long identity = Binder.clearCallingIdentity(); |
| 9922 | try { |
| 9923 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9924 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9925 | |
| 9926 | if (result instanceof IllegalStateException) { |
| 9927 | throw (IllegalStateException) result; |
| 9928 | } |
| 9929 | } finally { |
| 9930 | Binder.restoreCallingIdentity(identity); |
| 9931 | } |
| 9932 | } |
| 9933 | |
| 9934 | @Override |
| 9935 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9936 | String callingPackage) { |
| 9937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9938 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9939 | |
| 9940 | final int callingUid = Binder.getCallingUid(); |
| 9941 | // Verify that tha callingPackage belongs to the calling UID |
| 9942 | mApp.getSystemService(AppOpsManager.class) |
| 9943 | .checkPackage(callingUid, callingPackage); |
| 9944 | |
| 9945 | final long identity = Binder.clearCallingIdentity(); |
| 9946 | try { |
| 9947 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9948 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9949 | |
| 9950 | if (result instanceof IllegalStateException) { |
| 9951 | throw (IllegalStateException) result; |
| 9952 | } |
| 9953 | } finally { |
| 9954 | Binder.restoreCallingIdentity(identity); |
| 9955 | } |
| 9956 | } |
| 9957 | |
| 9958 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9959 | int callingUid) { |
| 9960 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9961 | // phone/system process do not have further restriction on request |
| 9962 | return; |
| 9963 | } |
| 9964 | |
| 9965 | // Applications has restrictions on how to use the request: |
| 9966 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9967 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9968 | // This is not system caller which has been checked above |
| 9969 | throw new IllegalArgumentException( |
| 9970 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9971 | } |
| 9972 | |
| 9973 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9974 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9975 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9976 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9977 | || info.isEnabled()) { |
| 9978 | throw new IllegalArgumentException( |
| 9979 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9980 | } |
| 9981 | |
| 9982 | // Thresholds length for each RAN need in range. This has been validated in |
| 9983 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9984 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9985 | final int[] thresholds = info.getThresholds(); |
| 9986 | Objects.requireNonNull(thresholds); |
| 9987 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9988 | || thresholds.length |
| 9989 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9990 | throw new IllegalArgumentException( |
| 9991 | "thresholds length is out of range: " + thresholds.length); |
| 9992 | } |
| 9993 | } |
| 9994 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 9995 | |
| 9996 | /** |
| 9997 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 9998 | * required to be done shortly after the API is invoked. |
| 9999 | */ |
| 10000 | @Override |
| 10001 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10002 | public int prepareForUnattendedReboot() { |
| 10003 | enforceRebootPermission(); |
| 10004 | |
| 10005 | final long identity = Binder.clearCallingIdentity(); |
| 10006 | try { |
| 10007 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10008 | } finally { |
| 10009 | Binder.restoreCallingIdentity(identity); |
| 10010 | } |
| 10011 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10012 | } |