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; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 174 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 188 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 190 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 192 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 194 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 195 | import com.android.services.telephony.TelecomAccountRegistry; |
| 196 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 197 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 198 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 199 | import java.io.FileDescriptor; |
| 200 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 203 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 204 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 205 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 206 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 207 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 208 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 209 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 210 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 211 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 212 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * Implementation of the ITelephony interface. |
| 216 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 217 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 218 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 219 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 220 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 221 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 222 | |
| 223 | // Message codes used with mMainThreadHandler |
| 224 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 225 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 226 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 227 | private static final int CMD_OPEN_CHANNEL = 9; |
| 228 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 229 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 230 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 231 | private static final int CMD_NV_READ_ITEM = 13; |
| 232 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 233 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 234 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 235 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 236 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 237 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 238 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 239 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 240 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 241 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 242 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 243 | private static final int CMD_SEND_ENVELOPE = 25; |
| 244 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 245 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 246 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 247 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 248 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 249 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 250 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 251 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 252 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 253 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 254 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 255 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 256 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 257 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 258 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 259 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 260 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 261 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 262 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 263 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 264 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 265 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 266 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 267 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 268 | private static final int CMD_SWITCH_SLOTS = 50; |
| 269 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 270 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 271 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 272 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 273 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 274 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 275 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 276 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 277 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 278 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 279 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 280 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 281 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 282 | private static final int CMD_MODEM_REBOOT = 64; |
| 283 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 284 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 285 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 286 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 287 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 288 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 289 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 290 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 291 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 292 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 293 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 294 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 295 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 296 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 297 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 298 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 299 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 300 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 301 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 302 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 303 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 304 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 305 | private static final int CMD_GET_CALL_WAITING = 87; |
| 306 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 307 | private static final int CMD_SET_CALL_WAITING = 89; |
| 308 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 309 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 310 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 311 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 312 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 314 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 315 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 316 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 317 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 318 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 319 | private static final int CMD_SET_SIM_POWER = 101; |
| 320 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 322 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 323 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 324 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 325 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 326 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 327 | // Parameters of select command. |
| 328 | private static final int SELECT_COMMAND = 0xA4; |
| 329 | private static final int SELECT_P1 = 0x04; |
| 330 | private static final int SELECT_P2 = 0; |
| 331 | private static final int SELECT_P3 = 0x10; |
| 332 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 333 | /** The singleton instance. */ |
| 334 | private static PhoneInterfaceManager sInstance; |
| 335 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 336 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 337 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 338 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 339 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 340 | private AppOpsManager mAppOps; |
| 341 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 342 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 343 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 344 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 346 | /** User Activity */ |
| 347 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 348 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 349 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 350 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 351 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 352 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 353 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 354 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 355 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 356 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 357 | // String to store multi SIM allowed |
| 358 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 359 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 360 | // The AID of ISD-R. |
| 361 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 362 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 363 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 364 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 365 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 366 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 367 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 368 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 369 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 370 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 371 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 372 | */ |
| 373 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 374 | "reset_network_erase_modem_config_enabled"; |
| 375 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 376 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 377 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 378 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 379 | * A request object to use for transmitting data to an ICC. |
| 380 | */ |
| 381 | private static final class IccAPDUArgument { |
| 382 | public int channel, cla, command, p1, p2, p3; |
| 383 | public String data; |
| 384 | |
| 385 | public IccAPDUArgument(int channel, int cla, int command, |
| 386 | int p1, int p2, int p3, String data) { |
| 387 | this.channel = channel; |
| 388 | this.cla = cla; |
| 389 | this.command = command; |
| 390 | this.p1 = p1; |
| 391 | this.p2 = p2; |
| 392 | this.p3 = p3; |
| 393 | this.data = data; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 398 | * A request object to use for transmitting data to an ICC. |
| 399 | */ |
| 400 | private static final class ManualNetworkSelectionArgument { |
| 401 | public OperatorInfo operatorInfo; |
| 402 | public boolean persistSelection; |
| 403 | |
| 404 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 405 | this.operatorInfo = operatorInfo; |
| 406 | this.persistSelection = persistSelection; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 412 | * request after sending. The main thread will notify the request when it is complete. |
| 413 | */ |
| 414 | private static final class MainThreadRequest { |
| 415 | /** The argument to use for the request */ |
| 416 | public Object argument; |
| 417 | /** The result of the request that is run on the main thread */ |
| 418 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 419 | // The subscriber id that this request applies to. Defaults to |
| 420 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 421 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 422 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 423 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 424 | public Phone phone; |
| 425 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 426 | public WorkSource workSource; |
| 427 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 428 | public MainThreadRequest(Object argument) { |
| 429 | this.argument = argument; |
| 430 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 431 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 432 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 433 | this.argument = argument; |
| 434 | if (phone != null) { |
| 435 | this.phone = phone; |
| 436 | } |
| 437 | this.workSource = workSource; |
| 438 | } |
| 439 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 440 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 441 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 442 | if (subId != null) { |
| 443 | this.subId = subId; |
| 444 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 445 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 449 | private static final class IncomingThirdPartyCallArgs { |
| 450 | public final ComponentName component; |
| 451 | public final String callId; |
| 452 | public final String callerDisplayName; |
| 453 | |
| 454 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 455 | String callerDisplayName) { |
| 456 | this.component = component; |
| 457 | this.callId = callId; |
| 458 | this.callerDisplayName = callerDisplayName; |
| 459 | } |
| 460 | } |
| 461 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 462 | /** |
| 463 | * A handler that processes messages on the main thread in the phone process. Since many |
| 464 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 465 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 466 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 467 | * on, which will be notified when the operation completes and will contain the result of the |
| 468 | * request. |
| 469 | * |
| 470 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 471 | * note that request.result must be set to something non-null for the calling thread to |
| 472 | * unblock. |
| 473 | */ |
| 474 | private final class MainThreadHandler extends Handler { |
| 475 | @Override |
| 476 | public void handleMessage(Message msg) { |
| 477 | MainThreadRequest request; |
| 478 | Message onCompleted; |
| 479 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 480 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 481 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 482 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | |
| 484 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | case CMD_HANDLE_USSD_REQUEST: { |
| 486 | request = (MainThreadRequest) msg.obj; |
| 487 | final Phone phone = getPhoneFromRequest(request); |
| 488 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 489 | String ussdRequest = ussdObject.first; |
| 490 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 491 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 492 | if (!isUssdApiAllowed(request.subId)) { |
| 493 | // Carrier does not support use of this API, return failure. |
| 494 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 495 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 496 | Bundle returnData = new Bundle(); |
| 497 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 498 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 499 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 500 | request.result = true; |
| 501 | notifyRequester(request); |
| 502 | return; |
| 503 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 504 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | try { |
| 506 | request.result = phone != null |
| 507 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 508 | } catch (CallStateException cse) { |
| 509 | request.result = false; |
| 510 | } |
| 511 | // Wake up the requesting thread |
| 512 | notifyRequester(request); |
| 513 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 516 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 517 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 518 | final Phone phone = getPhoneFromRequest(request); |
| 519 | request.result = phone != null ? |
| 520 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 521 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 524 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 528 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 529 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 530 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 531 | if (uiccCard == null) { |
| 532 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 533 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 534 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 535 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 537 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 540 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 542 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 543 | break; |
| 544 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 545 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 546 | ar = (AsyncResult) msg.obj; |
| 547 | request = (MainThreadRequest) ar.userObj; |
| 548 | if (ar.exception == null && ar.result != null) { |
| 549 | request.result = ar.result; |
| 550 | } else { |
| 551 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 552 | if (ar.result == null) { |
| 553 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 554 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 556 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | } else { |
| 558 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 559 | } |
| 560 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | break; |
| 563 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 565 | request = (MainThreadRequest) msg.obj; |
| 566 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 567 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | if (uiccCard == null) { |
| 569 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 570 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 571 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | } else { |
| 573 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 574 | request); |
| 575 | uiccCard.iccTransmitApduBasicChannel( |
| 576 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 577 | iccArgument.p3, iccArgument.data, onCompleted); |
| 578 | } |
| 579 | break; |
| 580 | |
| 581 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 582 | ar = (AsyncResult) msg.obj; |
| 583 | request = (MainThreadRequest) ar.userObj; |
| 584 | if (ar.exception == null && ar.result != null) { |
| 585 | request.result = ar.result; |
| 586 | } else { |
| 587 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 588 | if (ar.result == null) { |
| 589 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 590 | } else if (ar.exception instanceof CommandException) { |
| 591 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 592 | ar.exception); |
| 593 | } else { |
| 594 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 595 | } |
| 596 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 597 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | break; |
| 599 | |
| 600 | case CMD_EXCHANGE_SIM_IO: |
| 601 | request = (MainThreadRequest) msg.obj; |
| 602 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 603 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | if (uiccCard == null) { |
| 605 | loge("iccExchangeSimIO: No UICC"); |
| 606 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 607 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | } else { |
| 609 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 610 | request); |
| 611 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 612 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 613 | iccArgument.data, onCompleted); |
| 614 | } |
| 615 | break; |
| 616 | |
| 617 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 618 | ar = (AsyncResult) msg.obj; |
| 619 | request = (MainThreadRequest) ar.userObj; |
| 620 | if (ar.exception == null && ar.result != null) { |
| 621 | request.result = ar.result; |
| 622 | } else { |
| 623 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 624 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 625 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | break; |
| 627 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 628 | case CMD_SEND_ENVELOPE: |
| 629 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 630 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | if (uiccCard == null) { |
| 632 | loge("sendEnvelopeWithStatus: No UICC"); |
| 633 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 634 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | } else { |
| 636 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 637 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 638 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 639 | break; |
| 640 | |
| 641 | case EVENT_SEND_ENVELOPE_DONE: |
| 642 | ar = (AsyncResult) msg.obj; |
| 643 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 644 | if (ar.exception == null && ar.result != null) { |
| 645 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 646 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 647 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 648 | if (ar.result == null) { |
| 649 | loge("sendEnvelopeWithStatus: Empty response"); |
| 650 | } else if (ar.exception instanceof CommandException) { |
| 651 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 652 | ar.exception); |
| 653 | } else { |
| 654 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 655 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 656 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 658 | break; |
| 659 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | case CMD_OPEN_CHANNEL: |
| 661 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 662 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 663 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 664 | if (uiccCard == null) { |
| 665 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 666 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 667 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | } else { |
| 670 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 671 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 672 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 673 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case EVENT_OPEN_CHANNEL_DONE: |
| 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | int[] result = (int[]) ar.result; |
| 682 | int channelId = result[0]; |
| 683 | byte[] selectResponse = null; |
| 684 | if (result.length > 1) { |
| 685 | selectResponse = new byte[result.length - 1]; |
| 686 | for (int i = 1; i < result.length; ++i) { |
| 687 | selectResponse[i - 1] = (byte) result[i]; |
| 688 | } |
| 689 | } |
| 690 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 691 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | if (ar.result == null) { |
| 694 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 696 | if (ar.exception != null) { |
| 697 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 698 | } |
| 699 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 700 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 701 | if (ar.exception instanceof CommandException) { |
| 702 | CommandException.Error error = |
| 703 | ((CommandException) (ar.exception)).getCommandError(); |
| 704 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 705 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 706 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 707 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
| 710 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 711 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 713 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | break; |
| 716 | |
| 717 | case CMD_CLOSE_CHANNEL: |
| 718 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 719 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 720 | if (uiccCard == null) { |
| 721 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 722 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 723 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 724 | } else { |
| 725 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 726 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 727 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 732 | break; |
| 733 | |
| 734 | case CMD_NV_READ_ITEM: |
| 735 | request = (MainThreadRequest) msg.obj; |
| 736 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 737 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 738 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | ar = (AsyncResult) msg.obj; |
| 743 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 744 | if (ar.exception == null && ar.result != null) { |
| 745 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 746 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | request.result = ""; |
| 748 | if (ar.result == null) { |
| 749 | loge("nvReadItem: Empty response"); |
| 750 | } else if (ar.exception instanceof CommandException) { |
| 751 | loge("nvReadItem: CommandException: " + |
| 752 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | } |
| 756 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | break; |
| 759 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | case CMD_NV_WRITE_ITEM: |
| 761 | request = (MainThreadRequest) msg.obj; |
| 762 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 763 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 764 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 765 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case EVENT_NV_WRITE_ITEM_DONE: |
| 769 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 770 | break; |
| 771 | |
| 772 | case CMD_NV_WRITE_CDMA_PRL: |
| 773 | request = (MainThreadRequest) msg.obj; |
| 774 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 775 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 779 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 780 | break; |
| 781 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 782 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 783 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 784 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 785 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 788 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 789 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 790 | break; |
| 791 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 792 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 793 | request = (MainThreadRequest) msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 795 | request); |
| 796 | Phone phone = getPhoneFromRequest(request); |
| 797 | if (phone != null) { |
| 798 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 799 | } else { |
| 800 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 801 | request.result = false; |
| 802 | notifyRequester(request); |
| 803 | } |
| 804 | break; |
| 805 | } |
| 806 | |
| 807 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 808 | ar = (AsyncResult) msg.obj; |
| 809 | request = (MainThreadRequest) ar.userObj; |
| 810 | if (ar.exception == null && ar.result != null) { |
| 811 | request.result = ar.result; |
| 812 | } else { |
| 813 | // request.result must be set to something non-null |
| 814 | // for the calling thread to unblock |
| 815 | if (request.result != null) { |
| 816 | request.result = ar.result; |
| 817 | } else { |
| 818 | request.result = false; |
| 819 | } |
| 820 | if (ar.result == null) { |
| 821 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 822 | } else if (ar.exception instanceof CommandException) { |
| 823 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 824 | + ar.exception); |
| 825 | } else { |
| 826 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 827 | } |
| 828 | } |
| 829 | notifyRequester(request); |
| 830 | break; |
| 831 | |
| 832 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 833 | request = (MainThreadRequest) msg.obj; |
| 834 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 835 | Phone phone = getPhoneFromRequest(request); |
| 836 | if (phone != null) { |
| 837 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 838 | request.workSource); |
| 839 | } else { |
| 840 | loge("enableNrDualConnectivity: No phone object"); |
| 841 | request.result = |
| 842 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 843 | notifyRequester(request); |
| 844 | } |
| 845 | break; |
| 846 | } |
| 847 | |
| 848 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 849 | ar = (AsyncResult) msg.obj; |
| 850 | request = (MainThreadRequest) ar.userObj; |
| 851 | if (ar.exception == null) { |
| 852 | request.result = |
| 853 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 854 | } else { |
| 855 | request.result = |
| 856 | TelephonyManager |
| 857 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 858 | if (ar.exception instanceof CommandException) { |
| 859 | CommandException.Error error = |
| 860 | ((CommandException) (ar.exception)).getCommandError(); |
| 861 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 862 | request.result = |
| 863 | TelephonyManager |
| 864 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 865 | } |
| 866 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 867 | + ar.exception); |
| 868 | } else { |
| 869 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 870 | } |
| 871 | } |
| 872 | notifyRequester(request); |
| 873 | break; |
| 874 | } |
| 875 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 876 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 877 | request = (MainThreadRequest) msg.obj; |
| 878 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 879 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 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) { |
| 892 | loge("getPreferredNetworkType: Empty response"); |
| 893 | } else if (ar.exception instanceof CommandException) { |
| 894 | loge("getPreferredNetworkType: CommandException: " + |
| 895 | ar.exception); |
| 896 | } else { |
| 897 | loge("getPreferredNetworkType: Unknown exception"); |
| 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 | |
| 903 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 904 | request = (MainThreadRequest) msg.obj; |
| 905 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 906 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 907 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 911 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 912 | break; |
| 913 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 914 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 915 | request = (MainThreadRequest)msg.obj; |
| 916 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 917 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 921 | ar = (AsyncResult)msg.obj; |
| 922 | request = (MainThreadRequest)ar.userObj; |
| 923 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 924 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 925 | break; |
| 926 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 927 | case CMD_SET_VOICEMAIL_NUMBER: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 930 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 931 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 932 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 936 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 937 | break; |
| 938 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 939 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 940 | request = (MainThreadRequest) msg.obj; |
| 941 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 942 | request); |
| 943 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 944 | break; |
| 945 | |
| 946 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 947 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 948 | break; |
| 949 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 950 | case CMD_PERFORM_NETWORK_SCAN: |
| 951 | request = (MainThreadRequest) msg.obj; |
| 952 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 953 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 954 | break; |
| 955 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 956 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 957 | request = (MainThreadRequest) msg.obj; |
| 958 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 960 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 961 | request.argument; |
| 962 | int callForwardingReason = args.first; |
| 963 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 964 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 965 | } |
| 966 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 967 | ar = (AsyncResult) msg.obj; |
| 968 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | TelephonyManager.CallForwardingInfoCallback callback = |
| 970 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 971 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 972 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 973 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 974 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 975 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 976 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 977 | // any service for voice call. |
| 978 | if ((callForwardInfo.serviceClass |
| 979 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | callForwardingInfo = new CallForwardingInfo(true, |
| 981 | callForwardInfo.reason, |
| 982 | callForwardInfo.number, |
| 983 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 984 | break; |
| 985 | } |
| 986 | } |
| 987 | // Didn't find a call forward info for voice call. |
| 988 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 990 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 991 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 993 | } else { |
| 994 | if (ar.result == null) { |
| 995 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 996 | } |
| 997 | if (ar.exception != null) { |
| 998 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 999 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1000 | int errorCode = TelephonyManager |
| 1001 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | if (ar.exception instanceof CommandException) { |
| 1003 | CommandException.Error error = |
| 1004 | ((CommandException) (ar.exception)).getCommandError(); |
| 1005 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1006 | errorCode = TelephonyManager |
| 1007 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1008 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1009 | errorCode = TelephonyManager |
| 1010 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1011 | } |
| 1012 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1013 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1014 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1015 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1017 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1019 | request = (MainThreadRequest) msg.obj; |
| 1020 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1022 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1023 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1024 | request.argument).first; |
| 1025 | request.phone.setCallForwardingOption( |
| 1026 | callForwardingInfoToSet.isEnabled() |
| 1027 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1028 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1029 | callForwardingInfoToSet.getReason(), |
| 1030 | callForwardingInfoToSet.getNumber(), |
| 1031 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1032 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1034 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1035 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1036 | ar = (AsyncResult) msg.obj; |
| 1037 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | Consumer<Integer> callback = |
| 1039 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1040 | request.argument).second; |
| 1041 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1042 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1043 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1044 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1045 | if (ar.exception instanceof CommandException) { |
| 1046 | CommandException.Error error = |
| 1047 | ((CommandException) (ar.exception)).getCommandError(); |
| 1048 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1049 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1050 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1052 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1053 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | } |
| 1055 | } |
| 1056 | callback.accept(errorCode); |
| 1057 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1058 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1059 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1060 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1062 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | request = (MainThreadRequest) msg.obj; |
| 1065 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1066 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1067 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1069 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1071 | ar = (AsyncResult) msg.obj; |
| 1072 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1073 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1074 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1075 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1076 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1077 | // Service Class is a bit mask per 3gpp 27.007. |
| 1078 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1079 | if (callForwardResults.length > 1 |
| 1080 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1082 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1084 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1085 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1087 | } |
| 1088 | } else { |
| 1089 | if (ar.result == null) { |
| 1090 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1091 | } |
| 1092 | if (ar.exception != null) { |
| 1093 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1094 | } |
| 1095 | if (ar.exception instanceof CommandException) { |
| 1096 | CommandException.Error error = |
| 1097 | ((CommandException) (ar.exception)).getCommandError(); |
| 1098 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1099 | callForwardingStatus = |
| 1100 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1101 | } |
| 1102 | } |
| 1103 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1105 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1107 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | request = (MainThreadRequest) msg.obj; |
| 1110 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1112 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1113 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1115 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1116 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1117 | ar = (AsyncResult) msg.obj; |
| 1118 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1120 | Consumer<Integer> callback = |
| 1121 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1122 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1123 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1124 | if (ar.exception instanceof CommandException) { |
| 1125 | CommandException.Error error = |
| 1126 | ((CommandException) (ar.exception)).getCommandError(); |
| 1127 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1128 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1129 | } else { |
| 1130 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1131 | } |
| 1132 | } else { |
| 1133 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1134 | } |
| 1135 | } else { |
| 1136 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1137 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1138 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1139 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1140 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1141 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1142 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1143 | ar = (AsyncResult) msg.obj; |
| 1144 | request = (MainThreadRequest) ar.userObj; |
| 1145 | CellNetworkScanResult cellScanResult; |
| 1146 | if (ar.exception == null && ar.result != null) { |
| 1147 | cellScanResult = new CellNetworkScanResult( |
| 1148 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1149 | (List<OperatorInfo>) ar.result); |
| 1150 | } else { |
| 1151 | if (ar.result == null) { |
| 1152 | loge("getCellNetworkScanResults: Empty response"); |
| 1153 | } |
| 1154 | if (ar.exception != null) { |
| 1155 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1156 | } |
| 1157 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1158 | if (ar.exception instanceof CommandException) { |
| 1159 | CommandException.Error error = |
| 1160 | ((CommandException) (ar.exception)).getCommandError(); |
| 1161 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1162 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1163 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1164 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1165 | } |
| 1166 | } |
| 1167 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1168 | } |
| 1169 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1170 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1171 | break; |
| 1172 | |
| 1173 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1174 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1175 | ManualNetworkSelectionArgument selArg = |
| 1176 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1177 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1178 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1179 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1180 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1181 | break; |
| 1182 | |
| 1183 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1184 | ar = (AsyncResult) msg.obj; |
| 1185 | request = (MainThreadRequest) ar.userObj; |
| 1186 | if (ar.exception == null) { |
| 1187 | request.result = true; |
| 1188 | } else { |
| 1189 | request.result = false; |
| 1190 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1191 | } |
| 1192 | notifyRequester(request); |
| 1193 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1194 | break; |
| 1195 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1196 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1197 | request = (MainThreadRequest) msg.obj; |
| 1198 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1199 | if (defaultPhone != null) { |
| 1200 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1201 | } else { |
| 1202 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1203 | Bundle bundle = new Bundle(); |
| 1204 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1205 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1206 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1207 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1208 | break; |
| 1209 | |
| 1210 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1211 | ar = (AsyncResult) msg.obj; |
| 1212 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1213 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1214 | |
| 1215 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1216 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1217 | // Update the last modem activity info and the result of the request. |
| 1218 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1219 | if (isModemActivityInfoValid(info)) { |
| 1220 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1221 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1222 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1223 | .getTransmitTimeMillis(); |
| 1224 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1225 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1226 | } |
| 1227 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1228 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1229 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1230 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1231 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1232 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1233 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1234 | info.getReceiveTimeMillis() |
| 1235 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1236 | } |
| 1237 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1238 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1239 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1240 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1241 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1242 | } else { |
| 1243 | if (ar.result == null) { |
| 1244 | loge("queryModemActivityInfo: Empty response"); |
| 1245 | } else if (ar.exception instanceof CommandException) { |
| 1246 | loge("queryModemActivityInfo: CommandException: " + |
| 1247 | ar.exception); |
| 1248 | } else { |
| 1249 | loge("queryModemActivityInfo: Unknown exception"); |
| 1250 | } |
| 1251 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1252 | Bundle bundle = new Bundle(); |
| 1253 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1254 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1255 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1256 | break; |
| 1257 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1258 | case CMD_SET_ALLOWED_CARRIERS: |
| 1259 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1260 | CarrierRestrictionRules argument = |
| 1261 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1262 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1263 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1264 | break; |
| 1265 | |
| 1266 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1267 | ar = (AsyncResult) msg.obj; |
| 1268 | request = (MainThreadRequest) ar.userObj; |
| 1269 | if (ar.exception == null && ar.result != null) { |
| 1270 | request.result = ar.result; |
| 1271 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1272 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1273 | if (ar.exception instanceof CommandException) { |
| 1274 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1275 | CommandException.Error error = |
| 1276 | ((CommandException) (ar.exception)).getCommandError(); |
| 1277 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1278 | request.result = |
| 1279 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1280 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1281 | } else { |
| 1282 | loge("setAllowedCarriers: Unknown exception"); |
| 1283 | } |
| 1284 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1285 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1286 | break; |
| 1287 | |
| 1288 | case CMD_GET_ALLOWED_CARRIERS: |
| 1289 | request = (MainThreadRequest) msg.obj; |
| 1290 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1291 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | |
| 1294 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1295 | ar = (AsyncResult) msg.obj; |
| 1296 | request = (MainThreadRequest) ar.userObj; |
| 1297 | if (ar.exception == null && ar.result != null) { |
| 1298 | request.result = ar.result; |
| 1299 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1300 | request.result = new IllegalStateException( |
| 1301 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1302 | if (ar.result == null) { |
| 1303 | loge("getAllowedCarriers: Empty response"); |
| 1304 | } else if (ar.exception instanceof CommandException) { |
| 1305 | loge("getAllowedCarriers: CommandException: " + |
| 1306 | ar.exception); |
| 1307 | } else { |
| 1308 | loge("getAllowedCarriers: Unknown exception"); |
| 1309 | } |
| 1310 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1311 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1312 | break; |
| 1313 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1314 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1315 | ar = (AsyncResult) msg.obj; |
| 1316 | request = (MainThreadRequest) ar.userObj; |
| 1317 | if (ar.exception == null && ar.result != null) { |
| 1318 | request.result = ar.result; |
| 1319 | } else { |
| 1320 | request.result = new IllegalArgumentException( |
| 1321 | "Failed to retrieve Forbidden Plmns"); |
| 1322 | if (ar.result == null) { |
| 1323 | loge("getForbiddenPlmns: Empty response"); |
| 1324 | } else { |
| 1325 | loge("getForbiddenPlmns: Unknown exception"); |
| 1326 | } |
| 1327 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1328 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1329 | break; |
| 1330 | |
| 1331 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1332 | request = (MainThreadRequest) msg.obj; |
| 1333 | uiccCard = getUiccCardFromRequest(request); |
| 1334 | if (uiccCard == null) { |
| 1335 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1336 | request.result = new IllegalArgumentException( |
| 1337 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1338 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | Integer appType = (Integer) request.argument; |
| 1342 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1343 | if (uiccApp == null) { |
| 1344 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1345 | + appType); |
| 1346 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1347 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1348 | break; |
| 1349 | } else { |
| 1350 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1351 | + " specified type -- " + appType); |
| 1352 | } |
| 1353 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1354 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1355 | onCompleted); |
| 1356 | break; |
| 1357 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1358 | case CMD_SWITCH_SLOTS: |
| 1359 | request = (MainThreadRequest) msg.obj; |
| 1360 | int[] physicalSlots = (int[]) request.argument; |
| 1361 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1362 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1363 | break; |
| 1364 | |
| 1365 | case EVENT_SWITCH_SLOTS_DONE: |
| 1366 | ar = (AsyncResult) msg.obj; |
| 1367 | request = (MainThreadRequest) ar.userObj; |
| 1368 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1369 | notifyRequester(request); |
| 1370 | break; |
| 1371 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1372 | request = (MainThreadRequest) msg.obj; |
| 1373 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1374 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1375 | break; |
| 1376 | |
| 1377 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | if (ar.exception != null) { |
| 1381 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1382 | } else { |
| 1383 | int mode = ((int[]) ar.result)[0]; |
| 1384 | if (mode == 0) { |
| 1385 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1386 | } else { |
| 1387 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1388 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1389 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1390 | notifyRequester(request); |
| 1391 | break; |
| 1392 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1393 | request = (MainThreadRequest) msg.obj; |
| 1394 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1395 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1396 | break; |
| 1397 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1398 | ar = (AsyncResult) msg.obj; |
| 1399 | request = (MainThreadRequest) ar.userObj; |
| 1400 | if (ar.exception != null) { |
| 1401 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1402 | } else { |
| 1403 | request.result = ((int[]) ar.result)[0]; |
| 1404 | } |
| 1405 | notifyRequester(request); |
| 1406 | break; |
| 1407 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1408 | request = (MainThreadRequest) msg.obj; |
| 1409 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1410 | int mode = (int) request.argument; |
| 1411 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1412 | break; |
| 1413 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1414 | ar = (AsyncResult) msg.obj; |
| 1415 | request = (MainThreadRequest) ar.userObj; |
| 1416 | request.result = ar.exception == null; |
| 1417 | notifyRequester(request); |
| 1418 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1419 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1420 | request = (MainThreadRequest) msg.obj; |
| 1421 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1422 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1423 | break; |
| 1424 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1425 | ar = (AsyncResult) msg.obj; |
| 1426 | request = (MainThreadRequest) ar.userObj; |
| 1427 | if (ar.exception != null) { |
| 1428 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1429 | } else { |
| 1430 | request.result = ((int[]) ar.result)[0]; |
| 1431 | } |
| 1432 | notifyRequester(request); |
| 1433 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1434 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1435 | request = (MainThreadRequest) msg.obj; |
| 1436 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1437 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1438 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1439 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1440 | break; |
| 1441 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1442 | ar = (AsyncResult) msg.obj; |
| 1443 | request = (MainThreadRequest) ar.userObj; |
| 1444 | request.result = ar.exception == null; |
| 1445 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1446 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1447 | case CMD_GET_ALL_CELL_INFO: |
| 1448 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1449 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1450 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1451 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1452 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1453 | ar = (AsyncResult) msg.obj; |
| 1454 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1455 | // If a timeout occurs, the response will be null |
| 1456 | request.result = (ar.exception == null && ar.result != null) |
| 1457 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1458 | synchronized (request) { |
| 1459 | request.notifyAll(); |
| 1460 | } |
| 1461 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1462 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1463 | request = (MainThreadRequest) msg.obj; |
| 1464 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1465 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1466 | break; |
| 1467 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1468 | ar = (AsyncResult) msg.obj; |
| 1469 | request = (MainThreadRequest) ar.userObj; |
| 1470 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1471 | try { |
| 1472 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1473 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1474 | cb.onError( |
| 1475 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1476 | ar.exception.getClass().getName(), |
| 1477 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1478 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1479 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1480 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | // use the result as returned |
| 1483 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1484 | } |
| 1485 | } catch (RemoteException re) { |
| 1486 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1487 | } |
| 1488 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1489 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | request = (MainThreadRequest) msg.obj; |
| 1491 | WorkSource ws = (WorkSource) request.argument; |
| 1492 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1493 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1494 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1495 | } |
| 1496 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1497 | ar = (AsyncResult) msg.obj; |
| 1498 | request = (MainThreadRequest) ar.userObj; |
| 1499 | if (ar.exception == null) { |
| 1500 | request.result = ar.result; |
| 1501 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1502 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1503 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1504 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | synchronized (request) { |
| 1508 | request.notifyAll(); |
| 1509 | } |
| 1510 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1511 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1512 | case CMD_MODEM_REBOOT: |
| 1513 | request = (MainThreadRequest) msg.obj; |
| 1514 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1515 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1516 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1517 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1518 | handleNullReturnEvent(msg, "rebootModem"); |
| 1519 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1520 | case CMD_REQUEST_ENABLE_MODEM: |
| 1521 | request = (MainThreadRequest) msg.obj; |
| 1522 | boolean enable = (boolean) request.argument; |
| 1523 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1524 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1525 | PhoneConfigurationManager.getInstance() |
| 1526 | .enablePhone(request.phone, enable, onCompleted); |
| 1527 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1528 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1529 | ar = (AsyncResult) msg.obj; |
| 1530 | request = (MainThreadRequest) ar.userObj; |
| 1531 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1532 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1533 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1534 | if ((boolean) request.result) { |
| 1535 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1536 | updateModemStateMetrics(); |
| 1537 | } else { |
| 1538 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1539 | + ar.exception); |
| 1540 | } |
| 1541 | notifyRequester(request); |
| 1542 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1543 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1544 | case CMD_GET_MODEM_STATUS: |
| 1545 | request = (MainThreadRequest) msg.obj; |
| 1546 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1547 | PhoneConfigurationManager.getInstance() |
| 1548 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1549 | break; |
| 1550 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | int id = request.phone.getPhoneId(); |
| 1554 | if (ar.exception == null && ar.result != null) { |
| 1555 | request.result = ar.result; |
| 1556 | //update the cache as modem status has changed |
| 1557 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1558 | (boolean) request.result); |
| 1559 | } else { |
| 1560 | // Return true if modem status cannot be retrieved. For most cases, |
| 1561 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1562 | // and disable modem are not supported. Modem is always on. |
| 1563 | // TODO: this should be fixed in R to support a third |
| 1564 | // status UNKNOWN b/131631629 |
| 1565 | request.result = true; |
| 1566 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1567 | + ar.exception); |
| 1568 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1569 | notifyRequester(request); |
| 1570 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1571 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1572 | request = (MainThreadRequest) msg.obj; |
| 1573 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1574 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1575 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1576 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1577 | break; |
| 1578 | } |
| 1579 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1580 | ar = (AsyncResult) msg.obj; |
| 1581 | request = (MainThreadRequest) ar.userObj; |
| 1582 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1583 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1584 | args.second.accept(ar.exception == null); |
| 1585 | notifyRequester(request); |
| 1586 | break; |
| 1587 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1588 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1589 | request = (MainThreadRequest) msg.obj; |
| 1590 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1591 | Phone phone = getPhoneFromRequest(request); |
| 1592 | if (phone != null) { |
| 1593 | phone.getSystemSelectionChannels(onCompleted); |
| 1594 | } else { |
| 1595 | loge("getSystemSelectionChannels: No phone object"); |
| 1596 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1597 | notifyRequester(request); |
| 1598 | } |
| 1599 | break; |
| 1600 | } |
| 1601 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1602 | ar = (AsyncResult) msg.obj; |
| 1603 | request = (MainThreadRequest) ar.userObj; |
| 1604 | if (ar.exception == null && ar.result != null) { |
| 1605 | request.result = ar.result; |
| 1606 | } else { |
| 1607 | request.result = new IllegalArgumentException( |
| 1608 | "Failed to retrieve system selection channels"); |
| 1609 | if (ar.result == null) { |
| 1610 | loge("getSystemSelectionChannels: Empty response"); |
| 1611 | } else { |
| 1612 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1613 | } |
| 1614 | } |
| 1615 | notifyRequester(request); |
| 1616 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1617 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1618 | ar = (AsyncResult) msg.obj; |
| 1619 | request = (MainThreadRequest) ar.userObj; |
| 1620 | if (ar.exception == null && ar.result != null) { |
| 1621 | request.result = ar.result; |
| 1622 | } else { |
| 1623 | request.result = -1; |
| 1624 | loge("Failed to set Forbidden Plmns"); |
| 1625 | if (ar.result == null) { |
| 1626 | loge("setForbidenPlmns: Empty response"); |
| 1627 | } else if (ar.exception != null) { |
| 1628 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1629 | request.result = -1; |
| 1630 | } else { |
| 1631 | loge("setForbiddenPlmns: Unknown exception"); |
| 1632 | } |
| 1633 | } |
| 1634 | notifyRequester(request); |
| 1635 | break; |
| 1636 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1637 | request = (MainThreadRequest) msg.obj; |
| 1638 | uiccCard = getUiccCardFromRequest(request); |
| 1639 | if (uiccCard == null) { |
| 1640 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1641 | request.result = -1; |
| 1642 | notifyRequester(request); |
| 1643 | break; |
| 1644 | } |
| 1645 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1646 | (Pair<Integer, List<String>>) request.argument; |
| 1647 | appType = setFplmnsArgs.first; |
| 1648 | List<String> fplmns = setFplmnsArgs.second; |
| 1649 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1650 | if (uiccApp == null) { |
| 1651 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1652 | request.result = -1; |
| 1653 | loge("Failed to get UICC App"); |
| 1654 | notifyRequester(request); |
| 1655 | } else { |
| 1656 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1657 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1658 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1659 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1660 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1661 | case CMD_ERASE_MODEM_CONFIG: |
| 1662 | request = (MainThreadRequest) msg.obj; |
| 1663 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1664 | defaultPhone.eraseModemConfig(onCompleted); |
| 1665 | break; |
| 1666 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1667 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1668 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1669 | |
| 1670 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1671 | request = (MainThreadRequest) msg.obj; |
| 1672 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1673 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1674 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1675 | changed.first, changed.second, onCompleted); |
| 1676 | break; |
| 1677 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | if (ar.exception == null) { |
| 1681 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1682 | // If the operation is successful, update the PIN storage |
| 1683 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1684 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1685 | UiccController.getInstance().getPinStorage() |
| 1686 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1687 | } else { |
| 1688 | request.result = msg.arg1; |
| 1689 | } |
| 1690 | notifyRequester(request); |
| 1691 | break; |
| 1692 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1693 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1694 | request = (MainThreadRequest) msg.obj; |
| 1695 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1696 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1697 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1698 | enabled.first, enabled.second, onCompleted); |
| 1699 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1700 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1701 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1702 | ar = (AsyncResult) msg.obj; |
| 1703 | request = (MainThreadRequest) ar.userObj; |
| 1704 | if (ar.exception == null) { |
| 1705 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1706 | // If the operation is successful, update the PIN storage |
| 1707 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1708 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1709 | if (enabled.first) { |
| 1710 | UiccController.getInstance().getPinStorage() |
| 1711 | .storePin(enabled.second, phoneId); |
| 1712 | } else { |
| 1713 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1714 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1715 | } else { |
| 1716 | request.result = msg.arg1; |
| 1717 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1718 | |
| 1719 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1720 | notifyRequester(request); |
| 1721 | break; |
| 1722 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1723 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1724 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1725 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1726 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1727 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1728 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1729 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1730 | |
| 1731 | case CMD_SET_DATA_THROTTLING: { |
| 1732 | request = (MainThreadRequest) msg.obj; |
| 1733 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1734 | DataThrottlingRequest dataThrottlingRequest = |
| 1735 | (DataThrottlingRequest) request.argument; |
| 1736 | Phone phone = getPhoneFromRequest(request); |
| 1737 | if (phone != null) { |
| 1738 | phone.setDataThrottling(onCompleted, |
| 1739 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1740 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1741 | } else { |
| 1742 | loge("setDataThrottling: No phone object"); |
| 1743 | request.result = |
| 1744 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1745 | notifyRequester(request); |
| 1746 | } |
| 1747 | |
| 1748 | break; |
| 1749 | } |
| 1750 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1751 | ar = (AsyncResult) msg.obj; |
| 1752 | request = (MainThreadRequest) ar.userObj; |
| 1753 | |
| 1754 | if (ar.exception == null) { |
| 1755 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1756 | } else if (ar.exception instanceof CommandException) { |
| 1757 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1758 | CommandException.Error error = |
| 1759 | ((CommandException) (ar.exception)).getCommandError(); |
| 1760 | |
| 1761 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1762 | request.result = TelephonyManager |
| 1763 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1764 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1765 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1766 | } else { |
| 1767 | request.result = |
| 1768 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1769 | } |
| 1770 | } else { |
| 1771 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1772 | } |
| 1773 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1774 | notifyRequester(request); |
| 1775 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1776 | |
| 1777 | case CMD_SET_SIM_POWER: { |
| 1778 | request = (MainThreadRequest) msg.obj; |
| 1779 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1780 | request = (MainThreadRequest) msg.obj; |
| 1781 | int stateToSet = |
| 1782 | ((Pair<Integer, IIntegerConsumer>) |
| 1783 | request.argument).first; |
| 1784 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1785 | break; |
| 1786 | } |
| 1787 | case EVENT_SET_SIM_POWER_DONE: { |
| 1788 | ar = (AsyncResult) msg.obj; |
| 1789 | request = (MainThreadRequest) ar.userObj; |
| 1790 | IIntegerConsumer callback = |
| 1791 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1792 | if (ar.exception != null) { |
| 1793 | loge("setSimPower exception: " + ar.exception); |
| 1794 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1795 | .RESULT_ERROR_UNKNOWN; |
| 1796 | if (ar.exception instanceof CommandException) { |
| 1797 | CommandException.Error error = |
| 1798 | ((CommandException) (ar.exception)).getCommandError(); |
| 1799 | if (error == CommandException.Error.SIM_ERR) { |
| 1800 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1801 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1802 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1803 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1804 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1805 | } else { |
| 1806 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1807 | } |
| 1808 | } |
| 1809 | try { |
| 1810 | callback.accept(errorCode); |
| 1811 | } catch (RemoteException e) { |
| 1812 | // Ignore if the remote process is no longer available to call back. |
| 1813 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1814 | } |
| 1815 | } else { |
| 1816 | try { |
| 1817 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1818 | } catch (RemoteException e) { |
| 1819 | // Ignore if the remote process is no longer available to call back. |
| 1820 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1821 | } |
| 1822 | } |
| 1823 | break; |
| 1824 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1825 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1826 | request = (MainThreadRequest) msg.obj; |
| 1827 | |
| 1828 | final Phone phone = getPhoneFromRequest(request); |
| 1829 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1830 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1831 | notifyRequester(request); |
| 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1836 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1837 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1838 | request); |
| 1839 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1840 | request.subId, pair.first /*callingUid*/, |
| 1841 | pair.second /*request*/, onCompleted); |
| 1842 | break; |
| 1843 | } |
| 1844 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1845 | ar = (AsyncResult) msg.obj; |
| 1846 | request = (MainThreadRequest) ar.userObj; |
| 1847 | // request.result will be the exception of ar if present, true otherwise. |
| 1848 | // Be cautious not to leave result null which will wait() forever |
| 1849 | request.result = ar.exception != null ? ar.exception : true; |
| 1850 | notifyRequester(request); |
| 1851 | break; |
| 1852 | } |
| 1853 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1854 | request = (MainThreadRequest) msg.obj; |
| 1855 | |
| 1856 | Phone phone = getPhoneFromRequest(request); |
| 1857 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1858 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1859 | notifyRequester(request); |
| 1860 | break; |
| 1861 | } |
| 1862 | |
| 1863 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1864 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1865 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1866 | request); |
| 1867 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1868 | request.subId, pair.first /*callingUid*/, |
| 1869 | pair.second /*request*/, onCompleted); |
| 1870 | break; |
| 1871 | } |
| 1872 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1873 | ar = (AsyncResult) msg.obj; |
| 1874 | request = (MainThreadRequest) ar.userObj; |
| 1875 | request.result = ar.exception != null ? ar.exception : true; |
| 1876 | notifyRequester(request); |
| 1877 | break; |
| 1878 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1879 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1880 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1881 | request = (MainThreadRequest) msg.obj; |
| 1882 | request.result = |
| 1883 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1884 | notifyRequester(request); |
| 1885 | break; |
| 1886 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1887 | default: |
| 1888 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1889 | break; |
| 1890 | } |
| 1891 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1892 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1893 | private void notifyRequester(MainThreadRequest request) { |
| 1894 | synchronized (request) { |
| 1895 | request.notifyAll(); |
| 1896 | } |
| 1897 | } |
| 1898 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1899 | private void handleNullReturnEvent(Message msg, String command) { |
| 1900 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1901 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1902 | if (ar.exception == null) { |
| 1903 | request.result = true; |
| 1904 | } else { |
| 1905 | request.result = false; |
| 1906 | if (ar.exception instanceof CommandException) { |
| 1907 | loge(command + ": CommandException: " + ar.exception); |
| 1908 | } else { |
| 1909 | loge(command + ": Unknown exception"); |
| 1910 | } |
| 1911 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1912 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1913 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1914 | } |
| 1915 | |
| 1916 | /** |
| 1917 | * Posts the specified command to be executed on the main thread, |
| 1918 | * waits for the request to complete, and returns the result. |
| 1919 | * @see #sendRequestAsync |
| 1920 | */ |
| 1921 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1922 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1923 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Posts the specified command to be executed on the main thread, |
| 1928 | * waits for the request to complete, and returns the result. |
| 1929 | * @see #sendRequestAsync |
| 1930 | */ |
| 1931 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1932 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1933 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | /** |
| 1937 | * Posts the specified command to be executed on the main thread, |
| 1938 | * waits for the request to complete, and returns the result. |
| 1939 | * @see #sendRequestAsync |
| 1940 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1941 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1942 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1943 | } |
| 1944 | |
| 1945 | /** |
| 1946 | * Posts the specified command to be executed on the main thread, |
| 1947 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1948 | * if not timeout or null otherwise. |
| 1949 | * @see #sendRequestAsync |
| 1950 | */ |
| 1951 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1952 | long timeoutInMs) { |
| 1953 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /** |
| 1957 | * Posts the specified command to be executed on the main thread, |
| 1958 | * waits for the request to complete, and returns the result. |
| 1959 | * @see #sendRequestAsync |
| 1960 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1961 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1962 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * Posts the specified command to be executed on the main thread, |
| 1967 | * waits for the request to complete, and returns the result. |
| 1968 | * @see #sendRequestAsync |
| 1969 | */ |
| 1970 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1971 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1972 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1976 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1977 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1978 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1979 | * @see #sendRequestAsync |
| 1980 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1981 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1982 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1983 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1984 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1985 | } |
| 1986 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1987 | MainThreadRequest request = null; |
| 1988 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1989 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1990 | } else if (phone != null) { |
| 1991 | request = new MainThreadRequest(argument, phone, workSource); |
| 1992 | } else { |
| 1993 | request = new MainThreadRequest(argument, subId, workSource); |
| 1994 | } |
| 1995 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1997 | msg.sendToTarget(); |
| 1998 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1999 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2001 | if (timeoutInMs >= 0) { |
| 2002 | // Wait for at least timeoutInMs before returning null request result |
| 2003 | long now = SystemClock.elapsedRealtime(); |
| 2004 | long deadline = now + timeoutInMs; |
| 2005 | while (request == null && now < deadline) { |
| 2006 | try { |
| 2007 | request.wait(deadline - now); |
| 2008 | } catch (InterruptedException e) { |
| 2009 | // Do nothing, go back and check if request is completed or timeout |
| 2010 | } finally { |
| 2011 | now = SystemClock.elapsedRealtime(); |
| 2012 | } |
| 2013 | } |
| 2014 | } else { |
| 2015 | // Wait for the request to complete |
| 2016 | while (request.result == null) { |
| 2017 | try { |
| 2018 | request.wait(); |
| 2019 | } catch (InterruptedException e) { |
| 2020 | // Do nothing, go back and wait until the request is complete |
| 2021 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2022 | } |
| 2023 | } |
| 2024 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2025 | if (request.result == null) { |
| 2026 | Log.wtf(LOG_TAG, |
| 2027 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | return request.result; |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2034 | * Posts the specified command to be executed on the main thread, and |
| 2035 | * returns immediately. |
| 2036 | * @see #sendRequest |
| 2037 | */ |
| 2038 | private void sendRequestAsync(int command) { |
| 2039 | mMainThreadHandler.sendEmptyMessage(command); |
| 2040 | } |
| 2041 | |
| 2042 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2043 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2044 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2045 | */ |
| 2046 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2047 | sendRequestAsync(command, argument, null, null); |
| 2048 | } |
| 2049 | |
| 2050 | /** |
| 2051 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2052 | * @see {@link #sendRequest(int,Object)} |
| 2053 | */ |
| 2054 | private void sendRequestAsync( |
| 2055 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2056 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2057 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2058 | msg.sendToTarget(); |
| 2059 | } |
| 2060 | |
| 2061 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2063 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2064 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2065 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | synchronized (PhoneInterfaceManager.class) { |
| 2067 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2068 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | } else { |
| 2070 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2071 | } |
| 2072 | return sInstance; |
| 2073 | } |
| 2074 | } |
| 2075 | |
| 2076 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2077 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2079 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2080 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2081 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2082 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2083 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2084 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2085 | mTelephonySharedPreferences = |
| 2086 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2087 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2088 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2089 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2090 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | publish(); |
| 2092 | } |
| 2093 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2094 | private Phone getDefaultPhone() { |
| 2095 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2096 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2097 | } |
| 2098 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | private void publish() { |
| 2100 | if (DBG) log("publish: " + this); |
| 2101 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2102 | TelephonyFrameworkInitializer |
| 2103 | .getTelephonyServiceManager() |
| 2104 | .getTelephonyServiceRegisterer() |
| 2105 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2108 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2109 | if (request.phone != null) { |
| 2110 | return request.phone; |
| 2111 | } else { |
| 2112 | return getPhoneFromSubId(request.subId); |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | private Phone getPhoneFromSubId(int subId) { |
| 2117 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2118 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2119 | } |
| 2120 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2121 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2122 | Phone phone = getPhoneFromRequest(request); |
| 2123 | return phone == null ? null : |
| 2124 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2125 | } |
| 2126 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2127 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2128 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2129 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2130 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2132 | private void sendEraseModemConfig(Phone phone) { |
| 2133 | if (phone != null) { |
| 2134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2135 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2136 | final long identity = Binder.clearCallingIdentity(); |
| 2137 | try { |
| 2138 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2139 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2140 | } finally { |
| 2141 | Binder.restoreCallingIdentity(identity); |
| 2142 | } |
| 2143 | } |
| 2144 | } |
| 2145 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2146 | private boolean isImsAvailableOnDevice() { |
| 2147 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2148 | if (pm == null) { |
| 2149 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2150 | // so do not throw error and allow. |
| 2151 | return true; |
| 2152 | } |
| 2153 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2154 | } |
| 2155 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2157 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2160 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | if (DBG) log("dial: " + number); |
| 2162 | // No permission check needed here: This is just a wrapper around the |
| 2163 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2164 | // the UI before it does anything. |
| 2165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2166 | final long identity = Binder.clearCallingIdentity(); |
| 2167 | try { |
| 2168 | String url = createTelUrl(number); |
| 2169 | if (url == null) { |
| 2170 | return; |
| 2171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2173 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2174 | PhoneConstants.State state = mCM.getState(subId); |
| 2175 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2176 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2177 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2178 | mApp.startActivity(intent); |
| 2179 | } |
| 2180 | } finally { |
| 2181 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2186 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2189 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2190 | if (DBG) log("call: " + number); |
| 2191 | |
| 2192 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2193 | // need to do a permission check since we're calling startActivity() |
| 2194 | // from the context of the phone app. |
| 2195 | enforceCallPermission(); |
| 2196 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2197 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | != AppOpsManager.MODE_ALLOWED) { |
| 2199 | return; |
| 2200 | } |
| 2201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2202 | final long identity = Binder.clearCallingIdentity(); |
| 2203 | try { |
| 2204 | String url = createTelUrl(number); |
| 2205 | if (url == null) { |
| 2206 | return; |
| 2207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2209 | boolean isValid = false; |
| 2210 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2211 | if (slist != null) { |
| 2212 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2213 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2214 | isValid = true; |
| 2215 | break; |
| 2216 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2217 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2218 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | if (!isValid) { |
| 2220 | return; |
| 2221 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2224 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2225 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2226 | mApp.startActivity(intent); |
| 2227 | } finally { |
| 2228 | Binder.restoreCallingIdentity(identity); |
| 2229 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2232 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2233 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2234 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2235 | } |
| 2236 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2237 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2238 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, 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 int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2244 | |
| 2245 | final long identity = Binder.clearCallingIdentity(); |
| 2246 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2247 | Phone phone = getPhone(subId); |
| 2248 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2249 | checkSimPin.start(); |
| 2250 | return checkSimPin.unlockSim(null, pin); |
| 2251 | } finally { |
| 2252 | Binder.restoreCallingIdentity(identity); |
| 2253 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2256 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | |
| 2259 | final long identity = Binder.clearCallingIdentity(); |
| 2260 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2261 | Phone phone = getPhone(subId); |
| 2262 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2263 | checkSimPuk.start(); |
| 2264 | return checkSimPuk.unlockSim(puk, pin); |
| 2265 | } finally { |
| 2266 | Binder.restoreCallingIdentity(identity); |
| 2267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2271 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | * a synchronous one. |
| 2273 | */ |
| 2274 | private static class UnlockSim extends Thread { |
| 2275 | |
| 2276 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2277 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | |
| 2279 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2280 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2281 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | |
| 2283 | // For replies from SimCard interface |
| 2284 | private Handler mHandler; |
| 2285 | |
| 2286 | // For async handler to identify request type |
| 2287 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2288 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2289 | UnlockSim(int phoneId, IccCard simCard) { |
| 2290 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2291 | mSimCard = simCard; |
| 2292 | } |
| 2293 | |
| 2294 | @Override |
| 2295 | public void run() { |
| 2296 | Looper.prepare(); |
| 2297 | synchronized (UnlockSim.this) { |
| 2298 | mHandler = new Handler() { |
| 2299 | @Override |
| 2300 | public void handleMessage(Message msg) { |
| 2301 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2302 | switch (msg.what) { |
| 2303 | case SUPPLY_PIN_COMPLETE: |
| 2304 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2305 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2306 | mRetryCount = msg.arg1; |
| 2307 | if (ar.exception != null) { |
| 2308 | if (ar.exception instanceof CommandException && |
| 2309 | ((CommandException)(ar.exception)).getCommandError() |
| 2310 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2311 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2312 | } //When UiccCardApp dispose,handle message and return exception |
| 2313 | else if (ar.exception instanceof CommandException && |
| 2314 | ((CommandException) (ar.exception)).getCommandError() |
| 2315 | == CommandException.Error.ABORTED) { |
| 2316 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2317 | } else { |
| 2318 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2319 | } |
| 2320 | } else { |
| 2321 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2322 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | mDone = true; |
| 2324 | UnlockSim.this.notifyAll(); |
| 2325 | } |
| 2326 | break; |
| 2327 | } |
| 2328 | } |
| 2329 | }; |
| 2330 | UnlockSim.this.notifyAll(); |
| 2331 | } |
| 2332 | Looper.loop(); |
| 2333 | } |
| 2334 | |
| 2335 | /* |
| 2336 | * Use PIN or PUK to unlock SIM card |
| 2337 | * |
| 2338 | * If PUK is null, unlock SIM card with PIN |
| 2339 | * |
| 2340 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2341 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2342 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | |
| 2344 | while (mHandler == null) { |
| 2345 | try { |
| 2346 | wait(); |
| 2347 | } catch (InterruptedException e) { |
| 2348 | Thread.currentThread().interrupt(); |
| 2349 | } |
| 2350 | } |
| 2351 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2352 | |
| 2353 | if (puk == null) { |
| 2354 | mSimCard.supplyPin(pin, callback); |
| 2355 | } else { |
| 2356 | mSimCard.supplyPuk(puk, pin, callback); |
| 2357 | } |
| 2358 | |
| 2359 | while (!mDone) { |
| 2360 | try { |
| 2361 | Log.d(LOG_TAG, "wait for done"); |
| 2362 | wait(); |
| 2363 | } catch (InterruptedException e) { |
| 2364 | // Restore the interrupted status |
| 2365 | Thread.currentThread().interrupt(); |
| 2366 | } |
| 2367 | } |
| 2368 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2369 | int[] resultArray = new int[2]; |
| 2370 | resultArray[0] = mResult; |
| 2371 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2372 | |
| 2373 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2374 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2375 | } |
| 2376 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2377 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2381 | /** |
| 2382 | * This method has been removed due to privacy and stability concerns. |
| 2383 | */ |
| 2384 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2386 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2387 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2390 | @Override |
| 2391 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2392 | mApp.getSystemService(AppOpsManager.class) |
| 2393 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2394 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2395 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2396 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2397 | // Callers targeting S have no business invoking this method. |
| 2398 | return; |
| 2399 | } |
| 2400 | |
| 2401 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2402 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2403 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2404 | .setCallingPackage(callingPackage) |
| 2405 | .setCallingFeatureId(null) |
| 2406 | .setCallingPid(Binder.getCallingPid()) |
| 2407 | .setCallingUid(Binder.getCallingUid()) |
| 2408 | .setMethod("updateServiceLocation") |
| 2409 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2410 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2411 | .build()); |
| 2412 | // Apps that lack location permission have no business calling this method; |
| 2413 | // however, because no permission was declared in the public API, denials must |
| 2414 | // all be "soft". |
| 2415 | switch (locationResult) { |
| 2416 | case DENIED_HARD: /* fall through */ |
| 2417 | case DENIED_SOFT: |
| 2418 | return; |
| 2419 | } |
| 2420 | |
| 2421 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | final long identity = Binder.clearCallingIdentity(); |
| 2423 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2424 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2425 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2426 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2427 | } |
| 2428 | } finally { |
| 2429 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2433 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2434 | @Override |
| 2435 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2436 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2439 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2440 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2441 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2442 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2443 | callingFeatureId); |
| 2444 | } |
| 2445 | |
| 2446 | @Deprecated |
| 2447 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2448 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2449 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2450 | } |
| 2451 | |
| 2452 | @Override |
| 2453 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2454 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2455 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2456 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2457 | return false; |
| 2458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | |
| 2460 | final long identity = Binder.clearCallingIdentity(); |
| 2461 | try { |
| 2462 | return isRadioOnForSubscriber(subId); |
| 2463 | } finally { |
| 2464 | Binder.restoreCallingIdentity(identity); |
| 2465 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | final long identity = Binder.clearCallingIdentity(); |
| 2470 | try { |
| 2471 | final Phone phone = getPhone(subId); |
| 2472 | if (phone != null) { |
| 2473 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2474 | } else { |
| 2475 | return false; |
| 2476 | } |
| 2477 | } finally { |
| 2478 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2483 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2486 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | |
| 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
| 2491 | final Phone phone = getPhone(subId); |
| 2492 | if (phone != null) { |
| 2493 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2494 | } |
| 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2497 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2501 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2504 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2505 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2506 | |
| 2507 | final long identity = Binder.clearCallingIdentity(); |
| 2508 | try { |
| 2509 | final Phone phone = getPhone(subId); |
| 2510 | if (phone == null) { |
| 2511 | return false; |
| 2512 | } |
| 2513 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2514 | toggleRadioOnOffForSubscriber(subId); |
| 2515 | } |
| 2516 | return true; |
| 2517 | } finally { |
| 2518 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2519 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2520 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2521 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2522 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2523 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2524 | /* |
| 2525 | * If any of the Radios are available, it will need to be |
| 2526 | * shutdown. So return true if any Radio is available. |
| 2527 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2528 | final long identity = Binder.clearCallingIdentity(); |
| 2529 | try { |
| 2530 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2531 | Phone phone = PhoneFactory.getPhone(i); |
| 2532 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2533 | } |
| 2534 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2535 | return false; |
| 2536 | } finally { |
| 2537 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2538 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2542 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | enforceModifyPermission(); |
| 2544 | |
| 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2548 | logv("Shutting down Phone " + i); |
| 2549 | shutdownRadioUsingPhoneId(i); |
| 2550 | } |
| 2551 | } finally { |
| 2552 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2557 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2558 | if (phone != null && phone.isRadioAvailable()) { |
| 2559 | phone.shutdownRadio(); |
| 2560 | } |
| 2561 | } |
| 2562 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2564 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | |
| 2566 | final long identity = Binder.clearCallingIdentity(); |
| 2567 | try { |
| 2568 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2569 | if (defaultPhone != null) { |
| 2570 | defaultPhone.setRadioPower(turnOn); |
| 2571 | return true; |
| 2572 | } else { |
| 2573 | loge("There's no default phone."); |
| 2574 | return false; |
| 2575 | } |
| 2576 | } finally { |
| 2577 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2578 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2581 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2583 | |
| 2584 | final long identity = Binder.clearCallingIdentity(); |
| 2585 | try { |
| 2586 | final Phone phone = getPhone(subId); |
| 2587 | if (phone != null) { |
| 2588 | phone.setRadioPower(turnOn); |
| 2589 | return true; |
| 2590 | } else { |
| 2591 | return false; |
| 2592 | } |
| 2593 | } finally { |
| 2594 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2595 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2598 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2599 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | public boolean enableDataConnectivity() { |
| 2601 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | |
| 2603 | final long identity = Binder.clearCallingIdentity(); |
| 2604 | try { |
| 2605 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2606 | final Phone phone = getPhone(subId); |
| 2607 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2608 | phone.getDataEnabledSettings().setDataEnabled( |
| 2609 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2610 | return true; |
| 2611 | } else { |
| 2612 | return false; |
| 2613 | } |
| 2614 | } finally { |
| 2615 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2616 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2619 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2620 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | public boolean disableDataConnectivity() { |
| 2622 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2623 | |
| 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2627 | final Phone phone = getPhone(subId); |
| 2628 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2629 | phone.getDataEnabledSettings().setDataEnabled( |
| 2630 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2631 | return true; |
| 2632 | } else { |
| 2633 | return false; |
| 2634 | } |
| 2635 | } finally { |
| 2636 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2637 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2640 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2641 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2642 | final long identity = Binder.clearCallingIdentity(); |
| 2643 | try { |
| 2644 | final Phone phone = getPhone(subId); |
| 2645 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2646 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2647 | } else { |
| 2648 | return false; |
| 2649 | } |
| 2650 | } finally { |
| 2651 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2652 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2656 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2659 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | enforceCallPermission(); |
| 2661 | |
| 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2665 | return; |
| 2666 | } |
| 2667 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2668 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
| 2671 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2672 | }; |
| 2673 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2674 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | |
| 2677 | final long identity = Binder.clearCallingIdentity(); |
| 2678 | try { |
| 2679 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2680 | return false; |
| 2681 | } |
| 2682 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2685 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2689 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2692 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | final long identity = Binder.clearCallingIdentity(); |
| 2694 | try { |
| 2695 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2696 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2697 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2698 | } finally { |
| 2699 | Binder.restoreCallingIdentity(identity); |
| 2700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2703 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2704 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2705 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2706 | } |
| 2707 | |
| 2708 | @Override |
| 2709 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2712 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | if (phone != null) { |
| 2714 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2715 | } else { |
| 2716 | return PhoneConstantConversions.convertDataState( |
| 2717 | PhoneConstants.DataState.DISCONNECTED); |
| 2718 | } |
| 2719 | } finally { |
| 2720 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2724 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2725 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2726 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2727 | } |
| 2728 | |
| 2729 | @Override |
| 2730 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2731 | final long identity = Binder.clearCallingIdentity(); |
| 2732 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2733 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | if (phone != null) { |
| 2735 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2736 | } else { |
| 2737 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2738 | } |
| 2739 | } finally { |
| 2740 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2741 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2745 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2746 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2747 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2748 | |
| 2749 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2750 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2751 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2752 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2753 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2754 | .setCallingPid(Binder.getCallingPid()) |
| 2755 | .setCallingUid(Binder.getCallingUid()) |
| 2756 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2757 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2758 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2759 | .build()); |
| 2760 | switch (locationResult) { |
| 2761 | case DENIED_HARD: |
| 2762 | throw new SecurityException("Not allowed to access cell location"); |
| 2763 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2764 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2765 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2768 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2772 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2773 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2774 | } finally { |
| 2775 | Binder.restoreCallingIdentity(identity); |
| 2776 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2780 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2781 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2782 | // registered cell info, so return a NULL country instead. |
| 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2785 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2786 | // Get default phone in this case. |
| 2787 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2788 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2789 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2790 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2791 | if (phone == null) return ""; |
| 2792 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2793 | if (sst == null) return ""; |
| 2794 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2795 | if (lt == null) return ""; |
| 2796 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2797 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2798 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2799 | } finally { |
| 2800 | Binder.restoreCallingIdentity(identity); |
| 2801 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2804 | /** |
| 2805 | * This method was removed due to potential issues caused by performing partial |
| 2806 | * updates of service state, and lack of a credible use case. |
| 2807 | * |
| 2808 | * This has the ability to break the telephony implementation by disabling notification of |
| 2809 | * changes in device connectivity. DO NOT USE THIS! |
| 2810 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2811 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | public void enableLocationUpdates() { |
| 2813 | mApp.enforceCallingOrSelfPermission( |
| 2814 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2817 | /** |
| 2818 | * This method was removed due to potential issues caused by performing partial |
| 2819 | * updates of service state, and lack of a credible use case. |
| 2820 | * |
| 2821 | * This has the ability to break the telephony implementation by disabling notification of |
| 2822 | * changes in device connectivity. DO NOT USE THIS! |
| 2823 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | @Override |
| 2825 | public void disableLocationUpdates() { |
| 2826 | mApp.enforceCallingOrSelfPermission( |
| 2827 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | @Override |
| 2831 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2832 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2833 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2834 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2835 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2836 | throw new SecurityException( |
| 2837 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2838 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2839 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2840 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2842 | return null; |
| 2843 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2844 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2845 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2847 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2848 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2850 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2851 | for (CellInfo ci : info) { |
| 2852 | if (ci instanceof CellInfoGsm) { |
| 2853 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2854 | } else if (ci instanceof CellInfoWcdma) { |
| 2855 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2856 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2858 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2861 | private List<CellInfo> getCachedCellInfo() { |
| 2862 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2863 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2864 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2865 | if (info != null) cellInfos.addAll(info); |
| 2866 | } |
| 2867 | return cellInfos; |
| 2868 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2869 | |
| 2870 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2871 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2872 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2873 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2874 | |
| 2875 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2876 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2877 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2878 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2879 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2880 | .setCallingPid(Binder.getCallingPid()) |
| 2881 | .setCallingUid(Binder.getCallingUid()) |
| 2882 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2883 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2884 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2885 | .build()); |
| 2886 | switch (locationResult) { |
| 2887 | case DENIED_HARD: |
| 2888 | throw new SecurityException("Not allowed to access cell info"); |
| 2889 | case DENIED_SOFT: |
| 2890 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2893 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2894 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2895 | return getCachedCellInfo(); |
| 2896 | } |
| 2897 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2898 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2899 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2903 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2904 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2905 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | if (info != null) cellInfos.addAll(info); |
| 2907 | } |
| 2908 | return cellInfos; |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2911 | } |
| 2912 | } |
| 2913 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2914 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2915 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2916 | String callingFeatureId) { |
| 2917 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2918 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2922 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2923 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2924 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2925 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2928 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2929 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2930 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2931 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2932 | |
| 2933 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2934 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2935 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2936 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2937 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2938 | .setCallingPid(Binder.getCallingPid()) |
| 2939 | .setCallingUid(Binder.getCallingUid()) |
| 2940 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2941 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2942 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2943 | .build()); |
| 2944 | switch (locationResult) { |
| 2945 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2946 | if (TelephonyPermissions |
| 2947 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2948 | // Safetynet logging for b/154934934 |
| 2949 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2950 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2951 | throw new SecurityException("Not allowed to access cell info"); |
| 2952 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2953 | if (TelephonyPermissions |
| 2954 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2955 | // Safetynet logging for b/154934934 |
| 2956 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2957 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2958 | try { |
| 2959 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2960 | } catch (RemoteException re) { |
| 2961 | // Drop without consequences |
| 2962 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2963 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2964 | } |
| 2965 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2966 | |
| 2967 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2968 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2969 | |
| 2970 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2974 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2975 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2976 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | |
| 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2980 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2986 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2987 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2988 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2989 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2990 | return null; |
| 2991 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2992 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2993 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2994 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2995 | return null; |
| 2996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 | |
| 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | return phone.getImei(); |
| 3001 | } finally { |
| 3002 | Binder.restoreCallingIdentity(identity); |
| 3003 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
| 3006 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3007 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3008 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3009 | String tac = null; |
| 3010 | if (phone != null) { |
| 3011 | String imei = phone.getImei(); |
| 3012 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3013 | } |
| 3014 | return tac; |
| 3015 | } |
| 3016 | |
| 3017 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3018 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3019 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3020 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3021 | return null; |
| 3022 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3024 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3025 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3026 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3027 | return null; |
| 3028 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | |
| 3030 | final long identity = Binder.clearCallingIdentity(); |
| 3031 | try { |
| 3032 | return phone.getMeid(); |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3039 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3040 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3041 | String manufacturerCode = null; |
| 3042 | if (phone != null) { |
| 3043 | String meid = phone.getMeid(); |
| 3044 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3045 | } |
| 3046 | return manufacturerCode; |
| 3047 | } |
| 3048 | |
| 3049 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3050 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3051 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3052 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3053 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3054 | return null; |
| 3055 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3056 | int subId = phone.getSubId(); |
| 3057 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3058 | mApp, subId, callingPackage, callingFeatureId, |
| 3059 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3060 | return null; |
| 3061 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3062 | |
| 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | return phone.getDeviceSvn(); |
| 3066 | } finally { |
| 3067 | Binder.restoreCallingIdentity(identity); |
| 3068 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3071 | @Override |
| 3072 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3073 | final long identity = Binder.clearCallingIdentity(); |
| 3074 | try { |
| 3075 | final Phone phone = getPhone(subId); |
| 3076 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
| 3079 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | @Override |
| 3083 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
| 3086 | final Phone phone = getPhone(subId); |
| 3087 | return phone == null ? null : phone.getCarrierName(); |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
| 3090 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3091 | } |
| 3092 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3093 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3094 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3095 | final long identity = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | final Phone phone = getPhone(subId); |
| 3098 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3099 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(identity); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3106 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3107 | final long identity = Binder.clearCallingIdentity(); |
| 3108 | try { |
| 3109 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3110 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3111 | } finally { |
| 3112 | Binder.restoreCallingIdentity(identity); |
| 3113 | } |
| 3114 | } |
| 3115 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3116 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3117 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3118 | if (!isSubscriptionMccMnc) { |
| 3119 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3120 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3121 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3122 | if (phone == null) { |
| 3123 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3124 | } |
| 3125 | final long identity = Binder.clearCallingIdentity(); |
| 3126 | try { |
| 3127 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3128 | } finally { |
| 3129 | Binder.restoreCallingIdentity(identity); |
| 3130 | } |
| 3131 | } |
| 3132 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3133 | // |
| 3134 | // Internal helper methods. |
| 3135 | // |
| 3136 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3137 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3138 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3139 | * |
| 3140 | * @throws SecurityException if the caller does not have the required permission |
| 3141 | */ |
| 3142 | private void enforceModifyPermission() { |
| 3143 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3144 | } |
| 3145 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3146 | /** |
| 3147 | * Make sure the caller is system. |
| 3148 | * |
| 3149 | * @throws SecurityException if the caller is not system. |
| 3150 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3151 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3152 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3153 | throw new SecurityException("Caller must be system"); |
| 3154 | } |
| 3155 | } |
| 3156 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3157 | private void enforceActiveEmergencySessionPermission() { |
| 3158 | mApp.enforceCallingOrSelfPermission( |
| 3159 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3160 | } |
| 3161 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | /** |
| 3163 | * Make sure the caller has the CALL_PHONE permission. |
| 3164 | * |
| 3165 | * @throws SecurityException if the caller does not have the required permission |
| 3166 | */ |
| 3167 | private void enforceCallPermission() { |
| 3168 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3169 | } |
| 3170 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3171 | private void enforceSettingsPermission() { |
| 3172 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3175 | private void enforceRebootPermission() { |
| 3176 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3177 | } |
| 3178 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3179 | private String createTelUrl(String number) { |
| 3180 | if (TextUtils.isEmpty(number)) { |
| 3181 | return null; |
| 3182 | } |
| 3183 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3184 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3185 | } |
| 3186 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3187 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3188 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3189 | } |
| 3190 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3191 | private static void logv(String msg) { |
| 3192 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3193 | } |
| 3194 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3195 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3196 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3197 | } |
| 3198 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3199 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3201 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3204 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3205 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | final long identity = Binder.clearCallingIdentity(); |
| 3207 | try { |
| 3208 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3209 | if (phone == null) { |
| 3210 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3211 | } else { |
| 3212 | return phone.getPhoneType(); |
| 3213 | } |
| 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3216 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | /** |
| 3220 | * Returns the CDMA ERI icon index to display |
| 3221 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3222 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3223 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3224 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3225 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3228 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3229 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3230 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3231 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3232 | mApp, subId, callingPackage, callingFeatureId, |
| 3233 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3234 | return -1; |
| 3235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | |
| 3237 | final long identity = Binder.clearCallingIdentity(); |
| 3238 | try { |
| 3239 | final Phone phone = getPhone(subId); |
| 3240 | if (phone != null) { |
| 3241 | return phone.getCdmaEriIconIndex(); |
| 3242 | } else { |
| 3243 | return -1; |
| 3244 | } |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | /** |
| 3251 | * Returns the CDMA ERI icon mode, |
| 3252 | * 0 - ON |
| 3253 | * 1 - FLASHING |
| 3254 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3255 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3256 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3257 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3258 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3262 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3263 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3264 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3265 | mApp, subId, callingPackage, callingFeatureId, |
| 3266 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3267 | return -1; |
| 3268 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | |
| 3270 | final long identity = Binder.clearCallingIdentity(); |
| 3271 | try { |
| 3272 | final Phone phone = getPhone(subId); |
| 3273 | if (phone != null) { |
| 3274 | return phone.getCdmaEriIconMode(); |
| 3275 | } else { |
| 3276 | return -1; |
| 3277 | } |
| 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3280 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | /** |
| 3284 | * Returns the CDMA ERI text, |
| 3285 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3286 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3287 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3288 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3289 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3290 | } |
| 3291 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3292 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3293 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3294 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3295 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3296 | mApp, subId, callingPackage, callingFeatureId, |
| 3297 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3298 | return null; |
| 3299 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3300 | |
| 3301 | final long identity = Binder.clearCallingIdentity(); |
| 3302 | try { |
| 3303 | final Phone phone = getPhone(subId); |
| 3304 | if (phone != null) { |
| 3305 | return phone.getCdmaEriText(); |
| 3306 | } else { |
| 3307 | return null; |
| 3308 | } |
| 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3315 | * Returns the CDMA MDN. |
| 3316 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3317 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3318 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3320 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3321 | |
| 3322 | final long identity = Binder.clearCallingIdentity(); |
| 3323 | try { |
| 3324 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3325 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | return phone.getLine1Number(); |
| 3327 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3328 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3329 | return null; |
| 3330 | } |
| 3331 | } finally { |
| 3332 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | /** |
| 3337 | * Returns the CDMA MIN. |
| 3338 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3339 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3340 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3342 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | |
| 3344 | final long identity = Binder.clearCallingIdentity(); |
| 3345 | try { |
| 3346 | final Phone phone = getPhone(subId); |
| 3347 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3348 | return phone.getCdmaMin(); |
| 3349 | } else { |
| 3350 | return null; |
| 3351 | } |
| 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3357 | @Override |
| 3358 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3359 | INumberVerificationCallback callback, String callingPackage) { |
| 3360 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3361 | != PERMISSION_GRANTED) { |
| 3362 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3363 | } |
| 3364 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3365 | |
| 3366 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3367 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3368 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3369 | + "calling package: " + callingPackage |
| 3370 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3371 | } |
| 3372 | |
| 3373 | if (range == null) { |
| 3374 | throw new NullPointerException("Range must be non-null"); |
| 3375 | } |
| 3376 | |
| 3377 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3378 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3379 | |
| 3380 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3381 | } |
| 3382 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3383 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3384 | * Returns true if CDMA provisioning needs to run. |
| 3385 | */ |
| 3386 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3389 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3390 | } finally { |
| 3391 | Binder.restoreCallingIdentity(identity); |
| 3392 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3396 | * Sets the voice mail number of a given subId. |
| 3397 | */ |
| 3398 | @Override |
| 3399 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3400 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3401 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3402 | |
| 3403 | final long identity = Binder.clearCallingIdentity(); |
| 3404 | try { |
| 3405 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3406 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3407 | return success; |
| 3408 | } finally { |
| 3409 | Binder.restoreCallingIdentity(identity); |
| 3410 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3411 | } |
| 3412 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3413 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3414 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3415 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3416 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3417 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3418 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3419 | throw new SecurityException("caller must be system dialer"); |
| 3420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3421 | |
| 3422 | final long identity = Binder.clearCallingIdentity(); |
| 3423 | try { |
| 3424 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3425 | if (phoneAccountHandle == null) { |
| 3426 | return null; |
| 3427 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3428 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3431 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
| 3434 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3435 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3436 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3437 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3439 | mApp, subId, callingPackage, callingFeatureId, |
| 3440 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3441 | return null; |
| 3442 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3443 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3446 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3447 | } finally { |
| 3448 | Binder.restoreCallingIdentity(identity); |
| 3449 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3450 | } |
| 3451 | |
| 3452 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3453 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3454 | VisualVoicemailSmsFilterSettings settings) { |
| 3455 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3456 | |
| 3457 | final long identity = Binder.clearCallingIdentity(); |
| 3458 | try { |
| 3459 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3460 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3461 | } finally { |
| 3462 | Binder.restoreCallingIdentity(identity); |
| 3463 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3467 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3468 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3469 | |
| 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3473 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(identity); |
| 3476 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
| 3479 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3480 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3481 | String callingPackage, int subId) { |
| 3482 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3483 | |
| 3484 | final long identity = Binder.clearCallingIdentity(); |
| 3485 | try { |
| 3486 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3487 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3488 | } finally { |
| 3489 | Binder.restoreCallingIdentity(identity); |
| 3490 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3494 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3495 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3496 | |
| 3497 | final long identity = Binder.clearCallingIdentity(); |
| 3498 | try { |
| 3499 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3500 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(identity); |
| 3503 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3507 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3508 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3509 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3510 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3511 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3512 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3513 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3514 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3515 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3516 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3517 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3518 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3519 | * Sets the voice activation state of a given subId. |
| 3520 | */ |
| 3521 | @Override |
| 3522 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3524 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3525 | |
| 3526 | final long identity = Binder.clearCallingIdentity(); |
| 3527 | try { |
| 3528 | final Phone phone = getPhone(subId); |
| 3529 | if (phone != null) { |
| 3530 | phone.setVoiceActivationState(activationState); |
| 3531 | } else { |
| 3532 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3533 | } |
| 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | /** |
| 3540 | * Sets the data activation state of a given subId. |
| 3541 | */ |
| 3542 | @Override |
| 3543 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3545 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3546 | |
| 3547 | final long identity = Binder.clearCallingIdentity(); |
| 3548 | try { |
| 3549 | final Phone phone = getPhone(subId); |
| 3550 | if (phone != null) { |
| 3551 | phone.setDataActivationState(activationState); |
| 3552 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3553 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3554 | } |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3557 | } |
| 3558 | } |
| 3559 | |
| 3560 | /** |
| 3561 | * Returns the voice activation state of a given subId. |
| 3562 | */ |
| 3563 | @Override |
| 3564 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3565 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3566 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3567 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | if (phone != null) { |
| 3571 | return phone.getVoiceActivationState(); |
| 3572 | } else { |
| 3573 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3574 | } |
| 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | /** |
| 3581 | * Returns the data activation state of a given subId. |
| 3582 | */ |
| 3583 | @Override |
| 3584 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3586 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3587 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3588 | final long identity = Binder.clearCallingIdentity(); |
| 3589 | try { |
| 3590 | if (phone != null) { |
| 3591 | return phone.getDataActivationState(); |
| 3592 | } else { |
| 3593 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3594 | } |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3597 | } |
| 3598 | } |
| 3599 | |
| 3600 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3601 | * Returns the unread count of voicemails for a subId |
| 3602 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3603 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3604 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3605 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3606 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3607 | mApp, subId, callingPackage, callingFeatureId, |
| 3608 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3609 | return 0; |
| 3610 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3611 | final long identity = Binder.clearCallingIdentity(); |
| 3612 | try { |
| 3613 | final Phone phone = getPhone(subId); |
| 3614 | if (phone != null) { |
| 3615 | return phone.getVoiceMessageCount(); |
| 3616 | } else { |
| 3617 | return 0; |
| 3618 | } |
| 3619 | } finally { |
| 3620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3625 | * returns true, if the device is in a state where both voice and data |
| 3626 | * are supported simultaneously. This can change based on location or network condition. |
| 3627 | */ |
| 3628 | @Override |
| 3629 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
| 3632 | final Phone phone = getPhone(subId); |
| 3633 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
| 3636 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3640 | * Send the dialer code if called from the current default dialer or the caller has |
| 3641 | * carrier privilege. |
| 3642 | * @param inputCode The dialer code to send |
| 3643 | */ |
| 3644 | @Override |
| 3645 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3646 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3647 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3648 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3649 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3650 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3651 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3652 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3653 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | |
| 3655 | final long identity = Binder.clearCallingIdentity(); |
| 3656 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3657 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(identity); |
| 3660 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3661 | } |
| 3662 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3663 | @Override |
| 3664 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3665 | TelephonyPermissions |
| 3666 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3667 | mApp, subId, "getNetworkSelectionMode"); |
| 3668 | final long identity = Binder.clearCallingIdentity(); |
| 3669 | try { |
| 3670 | if (!isActiveSubscription(subId)) { |
| 3671 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3672 | } |
| 3673 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3674 | } finally { |
| 3675 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3676 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3679 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3680 | public boolean isInEmergencySmsMode() { |
| 3681 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3685 | if (phone.isInEmergencySmsMode()) { |
| 3686 | return true; |
| 3687 | } |
| 3688 | } |
| 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
| 3691 | } |
| 3692 | return false; |
| 3693 | } |
| 3694 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3695 | /** |
| 3696 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3697 | * @param subId The subscription to use to check the configuration. |
| 3698 | * @param c The callback that will be used to send the result. |
| 3699 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3700 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3701 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3702 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3703 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3704 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3705 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3706 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3707 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3708 | "IMS not available on device."); |
| 3709 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3710 | final long token = Binder.clearCallingIdentity(); |
| 3711 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3712 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3713 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3715 | } catch (ImsException e) { |
| 3716 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3717 | } finally { |
| 3718 | Binder.restoreCallingIdentity(token); |
| 3719 | } |
| 3720 | } |
| 3721 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3722 | /** |
| 3723 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3724 | * @param subId The subscription to use to check the configuration. |
| 3725 | * @param c The callback that will be used to send the result. |
| 3726 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3727 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3728 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3730 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3731 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3732 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3733 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3734 | final long token = Binder.clearCallingIdentity(); |
| 3735 | try { |
| 3736 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3737 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3738 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3739 | } catch (ImsException e) { |
| 3740 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3741 | + "is inactive, ignoring unregister."); |
| 3742 | // If the subscription is no longer active, just return, since the callback |
| 3743 | // will already have been removed internally. |
| 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(token); |
| 3746 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3749 | /** |
| 3750 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3751 | */ |
| 3752 | @Override |
| 3753 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3754 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3755 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3756 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3757 | "IMS not available on device."); |
| 3758 | } |
| 3759 | final long token = Binder.clearCallingIdentity(); |
| 3760 | try { |
| 3761 | Phone phone = getPhone(subId); |
| 3762 | if (phone == null) { |
| 3763 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3764 | + subId + "'"); |
| 3765 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3766 | } |
| 3767 | phone.getImsRegistrationState(regState -> { |
| 3768 | try { |
| 3769 | consumer.accept((regState == null) |
| 3770 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3771 | } catch (RemoteException e) { |
| 3772 | // Ignore if the remote process is no longer available to call back. |
| 3773 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3774 | } |
| 3775 | }); |
| 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(token); |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | /** |
| 3782 | * Get the transport type for the IMS service registration state. |
| 3783 | */ |
| 3784 | @Override |
| 3785 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3786 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3787 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3788 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3789 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3790 | "IMS not available on device."); |
| 3791 | } |
| 3792 | final long token = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | Phone phone = getPhone(subId); |
| 3795 | if (phone == null) { |
| 3796 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3797 | + subId + "'"); |
| 3798 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3799 | } |
| 3800 | phone.getImsRegistrationTech(regTech -> { |
| 3801 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3802 | int regTechConverted = (regTech == null) |
| 3803 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3804 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3805 | regTechConverted); |
| 3806 | try { |
| 3807 | consumer.accept(regTechConverted); |
| 3808 | } catch (RemoteException e) { |
| 3809 | // Ignore if the remote process is no longer available to call back. |
| 3810 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3811 | } |
| 3812 | }); |
| 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(token); |
| 3815 | } |
| 3816 | } |
| 3817 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3818 | /** |
| 3819 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3820 | * @param subId The subscription to use to check the configuration. |
| 3821 | * @param c The callback that will be used to send the result. |
| 3822 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3823 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3824 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3825 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3826 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3827 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3828 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3829 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3830 | "IMS not available on device."); |
| 3831 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3832 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3833 | final long token = Binder.clearCallingIdentity(); |
| 3834 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3835 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3836 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3837 | } catch (ImsException e) { |
| 3838 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(token); |
| 3841 | } |
| 3842 | } |
| 3843 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3844 | /** |
| 3845 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3846 | * @param subId The subscription to use to check the configuration. |
| 3847 | * @param c The callback that will be used to send the result. |
| 3848 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3849 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3850 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3851 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3852 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3853 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3854 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3855 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3856 | |
| 3857 | final long token = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3860 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3861 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3862 | } catch (ImsException e) { |
| 3863 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3864 | + "is inactive, ignoring unregister."); |
| 3865 | // If the subscription is no longer active, just return, since the callback |
| 3866 | // will already have been removed internally. |
| 3867 | } finally { |
| 3868 | Binder.restoreCallingIdentity(token); |
| 3869 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3873 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3874 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3875 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3876 | final long token = Binder.clearCallingIdentity(); |
| 3877 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3878 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3879 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3880 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3882 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3883 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3884 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3885 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3886 | } finally { |
| 3887 | Binder.restoreCallingIdentity(token); |
| 3888 | } |
| 3889 | } |
| 3890 | |
| 3891 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3892 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3893 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | final long token = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | Phone phone = getPhone(subId); |
| 3897 | if (phone == null) return false; |
| 3898 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3899 | } catch (com.android.ims.ImsException e) { |
| 3900 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3901 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3902 | } finally { |
| 3903 | Binder.restoreCallingIdentity(token); |
| 3904 | } |
| 3905 | } |
| 3906 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3907 | /** |
| 3908 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3909 | * subscription. |
| 3910 | * @param subId The subscription to use to check the configuration. |
| 3911 | * @param callback The callback that will be used to send the result. |
| 3912 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3913 | * @param transportType The transport type of the MmTelFeature capability. |
| 3914 | */ |
| 3915 | @Override |
| 3916 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3917 | int transportType) { |
| 3918 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3919 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3920 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3921 | "IMS not available on device."); |
| 3922 | } |
| 3923 | final long token = Binder.clearCallingIdentity(); |
| 3924 | try { |
| 3925 | int slotId = getSlotIndex(subId); |
| 3926 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3927 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3928 | + subId + "'"); |
| 3929 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3930 | } |
| 3931 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3932 | transportType, aBoolean -> { |
| 3933 | try { |
| 3934 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3935 | } catch (RemoteException e) { |
| 3936 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3937 | + "running. Ignore"); |
| 3938 | } |
| 3939 | }); |
| 3940 | } finally { |
| 3941 | Binder.restoreCallingIdentity(token); |
| 3942 | } |
| 3943 | } |
| 3944 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3945 | /** |
| 3946 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3947 | * @param subId The subscription to use to check the configuration. |
| 3948 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3949 | @Override |
| 3950 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3951 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3952 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3953 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3954 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3955 | final long token = Binder.clearCallingIdentity(); |
| 3956 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3958 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3959 | } catch (ImsException e) { |
| 3960 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(token); |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3967 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3968 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3969 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3970 | final long identity = Binder.clearCallingIdentity(); |
| 3971 | try { |
| 3972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3973 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3974 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3975 | } catch (ImsException e) { |
| 3976 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
| 3979 | } |
| 3980 | } |
| 3981 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3982 | /** |
| 3983 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3984 | * @param subId The subscription to use to check the configuration. |
| 3985 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3986 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3987 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3988 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3989 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | final long identity = Binder.clearCallingIdentity(); |
| 3991 | try { |
| 3992 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3993 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3994 | } catch (ImsException e) { |
| 3995 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3996 | } finally { |
| 3997 | Binder.restoreCallingIdentity(identity); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4002 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4004 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | final long identity = Binder.clearCallingIdentity(); |
| 4006 | try { |
| 4007 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4008 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4009 | } catch (ImsException e) { |
| 4010 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | } |
| 4015 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4016 | /** |
| 4017 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4018 | * @param subId The subscription to use to check the configuration. |
| 4019 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4020 | @Override |
| 4021 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4022 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4023 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | final long identity = Binder.clearCallingIdentity(); |
| 4025 | try { |
| 4026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4027 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4029 | } catch (ImsException e) { |
| 4030 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
| 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4037 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4039 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
| 4042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4043 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4044 | } catch (ImsException e) { |
| 4045 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(identity); |
| 4048 | } |
| 4049 | } |
| 4050 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4051 | /** |
| 4052 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4053 | * @param subId The subscription to use to check the configuration. |
| 4054 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | @Override |
| 4056 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4057 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4058 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | final long identity = Binder.clearCallingIdentity(); |
| 4060 | try { |
| 4061 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4062 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4063 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4064 | } catch (ImsException e) { |
| 4065 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4066 | } finally { |
| 4067 | Binder.restoreCallingIdentity(identity); |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4072 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4074 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
| 4077 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4078 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4079 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4080 | } catch (ImsException e) { |
| 4081 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
| 4085 | } |
| 4086 | |
| 4087 | @Override |
| 4088 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4090 | "setVoWiFiNonPersistent"); |
| 4091 | final long identity = Binder.clearCallingIdentity(); |
| 4092 | try { |
| 4093 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4094 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4095 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4096 | } catch (ImsException e) { |
| 4097 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4098 | } finally { |
| 4099 | Binder.restoreCallingIdentity(identity); |
| 4100 | } |
| 4101 | } |
| 4102 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4103 | /** |
| 4104 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4105 | * @param subId The subscription to use to check the configuration. |
| 4106 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4107 | @Override |
| 4108 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4109 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4110 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4114 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4116 | } catch (ImsException e) { |
| 4117 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(identity); |
| 4120 | } |
| 4121 | } |
| 4122 | |
| 4123 | @Override |
| 4124 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4125 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4126 | "setVoWiFiModeSetting"); |
| 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
| 4129 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4130 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4131 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4132 | } catch (ImsException e) { |
| 4133 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4134 | } finally { |
| 4135 | Binder.restoreCallingIdentity(identity); |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | @Override |
| 4140 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4141 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
| 4144 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4145 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4147 | } catch (ImsException e) { |
| 4148 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | @Override |
| 4155 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4157 | "setVoWiFiRoamingModeSetting"); |
| 4158 | final long identity = Binder.clearCallingIdentity(); |
| 4159 | try { |
| 4160 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4161 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4162 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4163 | } catch (ImsException e) { |
| 4164 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | @Override |
| 4171 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4173 | "setRttCapabilityEnabled"); |
| 4174 | final long identity = Binder.clearCallingIdentity(); |
| 4175 | try { |
| 4176 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4177 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4178 | } catch (ImsException e) { |
| 4179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | } finally { |
| 4181 | Binder.restoreCallingIdentity(identity); |
| 4182 | } |
| 4183 | } |
| 4184 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4185 | /** |
| 4186 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4187 | * @param subId The subscription to use to check the configuration. |
| 4188 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4189 | @Override |
| 4190 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4191 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4192 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4196 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4198 | } catch (ImsException e) { |
| 4199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4200 | } finally { |
| 4201 | Binder.restoreCallingIdentity(identity); |
| 4202 | } |
| 4203 | } |
| 4204 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4205 | @Override |
| 4206 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4207 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4208 | final long identity = Binder.clearCallingIdentity(); |
| 4209 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4210 | if (!isImsAvailableOnDevice()) { |
| 4211 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4212 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4213 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4214 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4215 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4216 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4217 | } catch (ImsException e) { |
| 4218 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(identity); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | @Override |
| 4225 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4226 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4227 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4228 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4229 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4230 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4231 | try { |
| 4232 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4233 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4234 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4235 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4236 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4237 | + "is inactive, ignoring unregister."); |
| 4238 | // If the subscription is no longer active, just return, since the callback will already |
| 4239 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4240 | } finally { |
| 4241 | Binder.restoreCallingIdentity(identity); |
| 4242 | } |
| 4243 | } |
| 4244 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4245 | |
| 4246 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4248 | message); |
| 4249 | } |
| 4250 | |
| 4251 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4252 | boolean isMmtelCapability) { |
| 4253 | Phone phone = getPhone(subId); |
| 4254 | if (phone == null) { |
| 4255 | loge("phone instance null for subid " + subId); |
| 4256 | return false; |
| 4257 | } |
| 4258 | if (isMmtelCapability) { |
| 4259 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4260 | return false; |
| 4261 | } |
| 4262 | } else { |
| 4263 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4264 | return false; |
| 4265 | } |
| 4266 | } |
| 4267 | return true; |
| 4268 | } |
| 4269 | |
| 4270 | @Override |
| 4271 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4272 | boolean isProvisioned) { |
| 4273 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4274 | |
| 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
| 4277 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4278 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4279 | return; |
| 4280 | } |
| 4281 | |
| 4282 | // this capability requires provisioning, route to the correct API. |
| 4283 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4284 | switch (capability) { |
| 4285 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4286 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4287 | ims.setEabProvisioned(isProvisioned); |
| 4288 | break; |
| 4289 | default: { |
| 4290 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4291 | + "rcs capability '" + capability + "', which does not require " |
| 4292 | + "provisioning."); |
| 4293 | } |
| 4294 | } |
| 4295 | } finally { |
| 4296 | Binder.restoreCallingIdentity(identity); |
| 4297 | } |
| 4298 | |
| 4299 | } |
| 4300 | |
| 4301 | |
| 4302 | @Override |
| 4303 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4304 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4305 | final long identity = Binder.clearCallingIdentity(); |
| 4306 | try { |
| 4307 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4308 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4309 | return true; |
| 4310 | } |
| 4311 | |
| 4312 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4313 | switch (capability) { |
| 4314 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4315 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4316 | return ims.isEabProvisionedOnDevice(); |
| 4317 | |
| 4318 | default: { |
| 4319 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4320 | + "capability '" + capability + "', which does not require " |
| 4321 | + "provisioning."); |
| 4322 | } |
| 4323 | } |
| 4324 | |
| 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(identity); |
| 4327 | } |
| 4328 | } |
| 4329 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4330 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4331 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4332 | boolean isProvisioned) { |
| 4333 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4334 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4335 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4336 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4337 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4338 | final long identity = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4341 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4342 | return; |
| 4343 | } |
| 4344 | |
| 4345 | // this capability requires provisioning, route to the correct API. |
| 4346 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4347 | switch (capability) { |
| 4348 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4349 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4350 | ims.setVolteProvisioned(isProvisioned); |
| 4351 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4352 | ims.setWfcProvisioned(isProvisioned); |
| 4353 | } |
| 4354 | break; |
| 4355 | } |
| 4356 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4357 | // There is currently no difference in VT provisioning type. |
| 4358 | ims.setVtProvisioned(isProvisioned); |
| 4359 | break; |
| 4360 | } |
| 4361 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4362 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4363 | // change the capability of the feature instead if needed. |
| 4364 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4365 | == isProvisioned) { |
| 4366 | // No change in provisioning. |
| 4367 | return; |
| 4368 | } |
| 4369 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4370 | try { |
| 4371 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4372 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4373 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4374 | + ", Exception" + e.getMessage()); |
| 4375 | } |
| 4376 | break; |
| 4377 | } |
| 4378 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4379 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4380 | + "MmTel capability '" + capability + "', which does not require " |
| 4381 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(identity); |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | @Override |
| 4391 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4392 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4393 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4394 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4395 | } |
| 4396 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4397 | final long identity = Binder.clearCallingIdentity(); |
| 4398 | try { |
| 4399 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4400 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4401 | return true; |
| 4402 | } |
| 4403 | |
| 4404 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4405 | switch (capability) { |
| 4406 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4407 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4408 | return ims.isVolteProvisionedOnDevice(); |
| 4409 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4410 | return ims.isWfcProvisionedOnDevice(); |
| 4411 | } |
| 4412 | // This should never happen, since we are checking tech above to make sure it |
| 4413 | // is either LTE or IWLAN. |
| 4414 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4415 | + "capability."); |
| 4416 | } |
| 4417 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4418 | // There is currently no difference in VT provisioning type. |
| 4419 | return ims.isVtProvisionedOnDevice(); |
| 4420 | } |
| 4421 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4422 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4423 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4424 | } |
| 4425 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4426 | throw new IllegalArgumentException( |
| 4427 | "Tried to get provisioning for MmTel capability '" + capability |
| 4428 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(identity); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | @Override |
| 4438 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4439 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4440 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4441 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4442 | } |
| 4443 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4444 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4445 | return (provisionedBits & capability) > 0; |
| 4446 | } |
| 4447 | |
| 4448 | @Override |
| 4449 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4450 | boolean isProvisioned) { |
| 4451 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4452 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4453 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4454 | } |
| 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4456 | "setProvisioningStatusForCapability"); |
| 4457 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4458 | // If the current provisioning status for capability already matches isProvisioned, |
| 4459 | // do nothing. |
| 4460 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4461 | return; |
| 4462 | } |
| 4463 | if (isProvisioned) { |
| 4464 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4465 | } else { |
| 4466 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | /** |
| 4471 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4472 | * technology. The bitfield should mirror the bitfield defined by |
| 4473 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4474 | */ |
| 4475 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4476 | String key = getMmTelProvisioningKey(subId, tech); |
| 4477 | // Default is no capabilities are provisioned. |
| 4478 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4479 | } |
| 4480 | |
| 4481 | /** |
| 4482 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4483 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4484 | * technology specified. |
| 4485 | * |
| 4486 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4487 | */ |
| 4488 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4489 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4490 | String key = getMmTelProvisioningKey(subId, tech); |
| 4491 | editor.putInt(key, newField); |
| 4492 | editor.commit(); |
| 4493 | } |
| 4494 | |
| 4495 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4496 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4497 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4498 | } |
| 4499 | |
| 4500 | /** |
| 4501 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4502 | * carrier associated with the subscription id. |
| 4503 | */ |
| 4504 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4505 | int capability) { |
| 4506 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4507 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4508 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4509 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4510 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4511 | false); |
| 4512 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4513 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4514 | |
| 4515 | // First check to make sure that the capability requires provisioning. |
| 4516 | switch (capability) { |
| 4517 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4518 | // intentional fallthrough |
| 4519 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4520 | if (requireVoiceVtProvisioning) { |
| 4521 | // Voice and Video requires provisioning |
| 4522 | return true; |
| 4523 | } |
| 4524 | break; |
| 4525 | } |
| 4526 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4527 | if (requireUtProvisioning) { |
| 4528 | // UT requires provisioning |
| 4529 | return true; |
| 4530 | } |
| 4531 | break; |
| 4532 | } |
| 4533 | } |
| 4534 | return false; |
| 4535 | } |
| 4536 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4537 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4538 | int capability) { |
| 4539 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4540 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4541 | |
| 4542 | boolean requireRcsProvisioning = c.getBoolean( |
| 4543 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4544 | |
| 4545 | // First check to make sure that the capability requires provisioning. |
| 4546 | switch (capability) { |
| 4547 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4548 | // intentional fallthrough |
| 4549 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4550 | if (requireRcsProvisioning) { |
| 4551 | // OPTION or PRESENCE requires provisioning |
| 4552 | return true; |
| 4553 | } |
| 4554 | break; |
| 4555 | } |
| 4556 | } |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4560 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4561 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4562 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4563 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4564 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4565 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4566 | final long identity = Binder.clearCallingIdentity(); |
| 4567 | try { |
| 4568 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4569 | int slotId = getSlotIndex(subId); |
| 4570 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4571 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4572 | + subId + "' for key:" + key); |
| 4573 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4574 | } |
| 4575 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4576 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4577 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4578 | + subId + "' for key:" + key); |
| 4579 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4580 | } finally { |
| 4581 | Binder.restoreCallingIdentity(identity); |
| 4582 | } |
| 4583 | } |
| 4584 | |
| 4585 | @Override |
| 4586 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4587 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4588 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4589 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4590 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
| 4593 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4594 | int slotId = getSlotIndex(subId); |
| 4595 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4596 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4597 | + subId + "' for key:" + key); |
| 4598 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4599 | } |
| 4600 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4601 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4602 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4603 | + subId + "' for key:" + key); |
| 4604 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4605 | } finally { |
| 4606 | Binder.restoreCallingIdentity(identity); |
| 4607 | } |
| 4608 | } |
| 4609 | |
| 4610 | @Override |
| 4611 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4612 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4613 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4614 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4616 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4617 | final long identity = Binder.clearCallingIdentity(); |
| 4618 | try { |
| 4619 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4620 | int slotId = getSlotIndex(subId); |
| 4621 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4622 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4623 | + subId + "' for key:" + key); |
| 4624 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4625 | } |
| 4626 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4627 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4628 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4629 | + "' for key:" + key); |
| 4630 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(identity); |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | @Override |
| 4637 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4638 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4639 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4640 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4642 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4643 | final long identity = Binder.clearCallingIdentity(); |
| 4644 | try { |
| 4645 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4646 | int slotId = getSlotIndex(subId); |
| 4647 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4648 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4649 | + subId + "' for key:" + key); |
| 4650 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4651 | } |
| 4652 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4653 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4654 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4655 | + "' for key:" + key); |
| 4656 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4657 | } finally { |
| 4658 | Binder.restoreCallingIdentity(identity); |
| 4659 | } |
| 4660 | } |
| 4661 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4662 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4663 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4664 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4665 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4666 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4667 | } |
| 4668 | return slotId; |
| 4669 | } |
| 4670 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4671 | private int getSlotIndex(int subId) { |
| 4672 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4673 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4674 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4675 | } |
| 4676 | return slotId; |
| 4677 | } |
| 4678 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4679 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4680 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4681 | */ |
| 4682 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4683 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4684 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4685 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4686 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4687 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4688 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4689 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4690 | mApp, subId, callingPackage, callingFeatureId, |
| 4691 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4692 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4693 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4694 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | final long identity = Binder.clearCallingIdentity(); |
| 4696 | try { |
| 4697 | final Phone phone = getPhone(subId); |
| 4698 | if (phone != null) { |
| 4699 | return phone.getServiceState().getDataNetworkType(); |
| 4700 | } else { |
| 4701 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4702 | } |
| 4703 | } finally { |
| 4704 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | /** |
| 4709 | * Returns the data network type |
| 4710 | */ |
| 4711 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4712 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4713 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4714 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | /** |
| 4718 | * Returns the data network type for a subId |
| 4719 | */ |
| 4720 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4721 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4722 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4723 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4724 | mApp, subId, callingPackage, callingFeatureId, |
| 4725 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4726 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4727 | } |
| 4728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
| 4731 | final Phone phone = getPhone(subId); |
| 4732 | if (phone != null) { |
| 4733 | return phone.getServiceState().getDataNetworkType(); |
| 4734 | } else { |
| 4735 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4736 | } |
| 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4743 | * Returns the Voice network type for a subId |
| 4744 | */ |
| 4745 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4746 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4747 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4749 | mApp, subId, callingPackage, callingFeatureId, |
| 4750 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4751 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4752 | } |
| 4753 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4754 | final long identity = Binder.clearCallingIdentity(); |
| 4755 | try { |
| 4756 | final Phone phone = getPhone(subId); |
| 4757 | if (phone != null) { |
| 4758 | return phone.getServiceState().getVoiceNetworkType(); |
| 4759 | } else { |
| 4760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4761 | } |
| 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * @return true if a ICC card is present |
| 4769 | */ |
| 4770 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4771 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4772 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4773 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4777 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4778 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4779 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4780 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | final long identity = Binder.clearCallingIdentity(); |
| 4782 | try { |
| 4783 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4784 | if (phone != null) { |
| 4785 | return phone.getIccCard().hasIccCard(); |
| 4786 | } else { |
| 4787 | return false; |
| 4788 | } |
| 4789 | } finally { |
| 4790 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | /** |
| 4795 | * Return if the current radio is LTE on CDMA. This |
| 4796 | * is a tri-state return value as for a period of time |
| 4797 | * the mode may be unknown. |
| 4798 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4799 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4800 | * @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] | 4801 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4802 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4803 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4804 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4805 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4806 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4809 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4810 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4811 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4812 | try { |
| 4813 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4814 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4815 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4816 | } |
| 4817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4818 | final long identity = Binder.clearCallingIdentity(); |
| 4819 | try { |
| 4820 | final Phone phone = getPhone(subId); |
| 4821 | if (phone == null) { |
| 4822 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4823 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4824 | return TelephonyProperties.lte_on_cdma_device() |
| 4825 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4826 | } |
| 4827 | } finally { |
| 4828 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4829 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4832 | /** |
| 4833 | * {@hide} |
| 4834 | * Returns Default subId, 0 in the case of single standby. |
| 4835 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4836 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4837 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4838 | } |
| 4839 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4840 | private int getSlotForDefaultSubscription() { |
| 4841 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4842 | } |
| 4843 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4844 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4845 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4846 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4847 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4848 | private boolean isActiveSubscription(int subId) { |
| 4849 | return mSubscriptionController.isActiveSubId(subId); |
| 4850 | } |
| 4851 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4852 | /** |
| 4853 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4854 | */ |
| 4855 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4856 | final long identity = Binder.clearCallingIdentity(); |
| 4857 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4858 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4859 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4860 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
| 4863 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | /** |
| 4867 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4868 | */ |
| 4869 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | final long identity = Binder.clearCallingIdentity(); |
| 4871 | try { |
| 4872 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4875 | } finally { |
| 4876 | Binder.restoreCallingIdentity(identity); |
| 4877 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4878 | } |
| 4879 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4880 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4881 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4882 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4883 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4884 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4885 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4886 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4887 | if (phoneId == -1) { |
| 4888 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4889 | + " does not correspond to an active phone"); |
| 4890 | } |
| 4891 | return PhoneFactory.getPhone(phoneId); |
| 4892 | } |
| 4893 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4894 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4895 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4896 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4898 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4900 | if (DBG) { |
| 4901 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4902 | } |
| 4903 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4904 | p2); |
| 4905 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4906 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4907 | |
| 4908 | @Override |
| 4909 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4910 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4911 | enforceModifyPermission(); |
| 4912 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4913 | if (DBG) { |
| 4914 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4915 | } |
| 4916 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4917 | callingPackage, aid, p2); |
| 4918 | } |
| 4919 | |
| 4920 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4921 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | final long identity = Binder.clearCallingIdentity(); |
| 4923 | try { |
| 4924 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4925 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4926 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4927 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4928 | if (bestComponent == null |
| 4929 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4930 | loge("The calling package is not allowed to access ISD-R."); |
| 4931 | throw new SecurityException( |
| 4932 | "The calling package is not allowed to access ISD-R."); |
| 4933 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4934 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4936 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4937 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4938 | null /* workSource */); |
| 4939 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | return response; |
| 4941 | } finally { |
| 4942 | Binder.restoreCallingIdentity(identity); |
| 4943 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4947 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4949 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4950 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4951 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4952 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4953 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4954 | @Override |
| 4955 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4956 | enforceModifyPermission(); |
| 4957 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4958 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4959 | channel); |
| 4960 | } |
| 4961 | |
| 4962 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | if (channel < 0) { |
| 4966 | return false; |
| 4967 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4968 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4969 | null /* workSource */); |
| 4970 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4971 | return success; |
| 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4974 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4978 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4979 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4980 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4981 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4982 | if (DBG) { |
| 4983 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4984 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4985 | + p3 + " data=" + data); |
| 4986 | } |
| 4987 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4988 | command, p1, p2, p3, data); |
| 4989 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4990 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4991 | @Override |
| 4992 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4993 | int command, int p1, int p2, int p3, String data) { |
| 4994 | enforceModifyPermission(); |
| 4995 | if (DBG) { |
| 4996 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4997 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4998 | + p3 + " data=" + data); |
| 4999 | } |
| 5000 | return iccTransmitApduLogicalChannelWithPermission( |
| 5001 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5002 | data); |
| 5003 | } |
| 5004 | |
| 5005 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5006 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5007 | final long identity = Binder.clearCallingIdentity(); |
| 5008 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5009 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5010 | return ""; |
| 5011 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5012 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5014 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5015 | null /* workSource */); |
| 5016 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
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 | // Append the returned status code to the end of the response payload. |
| 5019 | String s = Integer.toHexString( |
| 5020 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5021 | if (response.payload != null) { |
| 5022 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5023 | } |
| 5024 | return s; |
| 5025 | } finally { |
| 5026 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5027 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5028 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5029 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5030 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5031 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5032 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5033 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5034 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5035 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5036 | if (DBG) { |
| 5037 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5038 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5039 | } |
| 5040 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5041 | cla, command, p1, p2, p3, data); |
| 5042 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5043 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5044 | @Override |
| 5045 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5046 | int command, int p1, int p2, int p3, String data) { |
| 5047 | enforceModifyPermission(); |
| 5048 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5049 | if (DBG) { |
| 5050 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5051 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5052 | + " data=" + data); |
| 5053 | } |
| 5054 | |
| 5055 | return iccTransmitApduBasicChannelWithPermission( |
| 5056 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5057 | p2, p3, data); |
| 5058 | } |
| 5059 | |
| 5060 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5061 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5062 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | final long identity = Binder.clearCallingIdentity(); |
| 5064 | try { |
| 5065 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5066 | && TextUtils.equals(ISDR_AID, data)) { |
| 5067 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5068 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5069 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5070 | if (bestComponent == null |
| 5071 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5072 | loge("The calling package is not allowed to select ISD-R."); |
| 5073 | throw new SecurityException( |
| 5074 | "The calling package is not allowed to select ISD-R."); |
| 5075 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5076 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5077 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5079 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5080 | null /* workSource */); |
| 5081 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | // Append the returned status code to the end of the response payload. |
| 5084 | String s = Integer.toHexString( |
| 5085 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5086 | if (response.payload != null) { |
| 5087 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5088 | } |
| 5089 | return s; |
| 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5092 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5096 | 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] | 5097 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5098 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5099 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5100 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5101 | final long identity = Binder.clearCallingIdentity(); |
| 5102 | try { |
| 5103 | if (DBG) { |
| 5104 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5105 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5106 | } |
| 5107 | |
| 5108 | IccIoResult response = |
| 5109 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5110 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5111 | subId); |
| 5112 | |
| 5113 | if (DBG) { |
| 5114 | log("Exchange SIM_IO [R]" + response); |
| 5115 | } |
| 5116 | |
| 5117 | byte[] result = null; |
| 5118 | int length = 2; |
| 5119 | if (response.payload != null) { |
| 5120 | length = 2 + response.payload.length; |
| 5121 | result = new byte[length]; |
| 5122 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5123 | } else { |
| 5124 | result = new byte[length]; |
| 5125 | } |
| 5126 | |
| 5127 | result[length - 1] = (byte) response.sw2; |
| 5128 | result[length - 2] = (byte) response.sw1; |
| 5129 | return result; |
| 5130 | } finally { |
| 5131 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5132 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5133 | } |
| 5134 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5135 | /** |
| 5136 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5137 | * on a particular subscription |
| 5138 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5139 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5140 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5141 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5142 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5143 | return null; |
| 5144 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5145 | |
| 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
| 5148 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5149 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5150 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5151 | return null; |
| 5152 | } |
| 5153 | Object response = sendRequest( |
| 5154 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5155 | if (response instanceof String[]) { |
| 5156 | return (String[]) response; |
| 5157 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5158 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5160 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5163 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5164 | } |
| 5165 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5166 | /** |
| 5167 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5168 | * subscription. |
| 5169 | * |
| 5170 | * @param subId the id of the subscription. |
| 5171 | * @param appType the uicc app type, must be USIM or SIM. |
| 5172 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5173 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5174 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5175 | * @return number of fplmns that is successfully written to the SIM. |
| 5176 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5177 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5178 | String callingFeatureId) { |
| 5179 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5180 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5181 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5182 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5183 | } |
| 5184 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5185 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5186 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5187 | } |
| 5188 | if (fplmns == null) { |
| 5189 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5190 | } |
| 5191 | for (String fplmn : fplmns) { |
| 5192 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5193 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5194 | } |
| 5195 | } |
| 5196 | final long identity = Binder.clearCallingIdentity(); |
| 5197 | try { |
| 5198 | Object response = sendRequest( |
| 5199 | CMD_SET_FORBIDDEN_PLMNS, |
| 5200 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5201 | subId); |
| 5202 | return (int) response; |
| 5203 | } finally { |
| 5204 | Binder.restoreCallingIdentity(identity); |
| 5205 | } |
| 5206 | } |
| 5207 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5208 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5209 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5211 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5213 | final long identity = Binder.clearCallingIdentity(); |
| 5214 | try { |
| 5215 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5216 | if (response.payload == null) { |
| 5217 | return ""; |
| 5218 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | // Append the returned status code to the end of the response payload. |
| 5221 | String s = Integer.toHexString( |
| 5222 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5223 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5224 | return s; |
| 5225 | } finally { |
| 5226 | Binder.restoreCallingIdentity(identity); |
| 5227 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5228 | } |
| 5229 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5230 | /** |
| 5231 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5232 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5233 | * |
| 5234 | * @param itemID the ID of the item to read |
| 5235 | * @return the NV item as a String, or null on error. |
| 5236 | */ |
| 5237 | @Override |
| 5238 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5239 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5241 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | |
| 5243 | final long identity = Binder.clearCallingIdentity(); |
| 5244 | try { |
| 5245 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5246 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5248 | return value; |
| 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | /** |
| 5255 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5256 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5257 | * |
| 5258 | * @param itemID the ID of the item to read |
| 5259 | * @param itemValue the value to write, as a String |
| 5260 | * @return true on success; false on any failure |
| 5261 | */ |
| 5262 | @Override |
| 5263 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5264 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5265 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5266 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | |
| 5268 | final long identity = Binder.clearCallingIdentity(); |
| 5269 | try { |
| 5270 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5271 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5272 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5274 | return success; |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5282 | * Used for device configuration by some CDMA operators. |
| 5283 | * |
| 5284 | * @param preferredRoamingList byte array containing the new PRL |
| 5285 | * @return true on success; false on any failure |
| 5286 | */ |
| 5287 | @Override |
| 5288 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5290 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5291 | |
| 5292 | final long identity = Binder.clearCallingIdentity(); |
| 5293 | try { |
| 5294 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5295 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5296 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5297 | return success; |
| 5298 | } finally { |
| 5299 | Binder.restoreCallingIdentity(identity); |
| 5300 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5304 | * 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] | 5305 | * Used for device configuration by some CDMA operators. |
| 5306 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5307 | * @param slotIndex - device slot. |
| 5308 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5309 | * @return true on success; false on any failure |
| 5310 | */ |
| 5311 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5312 | public boolean resetModemConfig(int slotIndex) { |
| 5313 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5314 | if (phone != null) { |
| 5315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5316 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5317 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5318 | final long identity = Binder.clearCallingIdentity(); |
| 5319 | try { |
| 5320 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5321 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5322 | return success; |
| 5323 | } finally { |
| 5324 | Binder.restoreCallingIdentity(identity); |
| 5325 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5327 | return false; |
| 5328 | } |
| 5329 | |
| 5330 | /** |
| 5331 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5332 | * |
| 5333 | * @param slotIndex - device slot. |
| 5334 | * |
| 5335 | * @return true on success; false on any failure |
| 5336 | */ |
| 5337 | @Override |
| 5338 | public boolean rebootModem(int slotIndex) { |
| 5339 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5340 | if (phone != null) { |
| 5341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5342 | mApp, phone.getSubId(), "rebootModem"); |
| 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5347 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5348 | return success; |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
| 5352 | } |
| 5353 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5354 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5355 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5356 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5357 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5358 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5359 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5360 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5361 | return new String[0]; |
| 5362 | } |
| 5363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5364 | final long identity = Binder.clearCallingIdentity(); |
| 5365 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5366 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | } finally { |
| 5368 | Binder.restoreCallingIdentity(identity); |
| 5369 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5370 | } |
| 5371 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5372 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5373 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5374 | * {@link #disableIms(int)}. |
| 5375 | * @param slotIndex device slot. |
| 5376 | */ |
| 5377 | public void resetIms(int slotIndex) { |
| 5378 | enforceModifyPermission(); |
| 5379 | |
| 5380 | final long identity = Binder.clearCallingIdentity(); |
| 5381 | try { |
| 5382 | if (mImsResolver == null) { |
| 5383 | // may happen if the does not support IMS. |
| 5384 | return; |
| 5385 | } |
| 5386 | mImsResolver.disableIms(slotIndex); |
| 5387 | mImsResolver.enableIms(slotIndex); |
| 5388 | } finally { |
| 5389 | Binder.restoreCallingIdentity(identity); |
| 5390 | } |
| 5391 | } |
| 5392 | |
| 5393 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5394 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5395 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5396 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5397 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5398 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | |
| 5400 | final long identity = Binder.clearCallingIdentity(); |
| 5401 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5402 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5403 | // may happen if the device does not support IMS. |
| 5404 | return; |
| 5405 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5406 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5413 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5414 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5415 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5416 | public void disableIms(int slotId) { |
| 5417 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | |
| 5419 | final long identity = Binder.clearCallingIdentity(); |
| 5420 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5421 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5422 | // may happen if the device does not support IMS. |
| 5423 | return; |
| 5424 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5425 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | } finally { |
| 5427 | Binder.restoreCallingIdentity(identity); |
| 5428 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5432 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5433 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5434 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5435 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5436 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5437 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5438 | |
| 5439 | final long identity = Binder.clearCallingIdentity(); |
| 5440 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5441 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5442 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5443 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5444 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5445 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | } finally { |
| 5447 | Binder.restoreCallingIdentity(identity); |
| 5448 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5449 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5450 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5451 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5452 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5453 | @Override |
| 5454 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5455 | enforceModifyPermission(); |
| 5456 | |
| 5457 | final long identity = Binder.clearCallingIdentity(); |
| 5458 | try { |
| 5459 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5460 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5467 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5468 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5469 | */ |
| 5470 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5471 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | |
| 5473 | final long identity = Binder.clearCallingIdentity(); |
| 5474 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5476 | // may happen if the device does not support IMS. |
| 5477 | return null; |
| 5478 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5479 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5483 | } |
| 5484 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5485 | /** |
| 5486 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5487 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5488 | */ |
| 5489 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5490 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | |
| 5492 | final long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5494 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5495 | // may happen if the device does not support IMS. |
| 5496 | return null; |
| 5497 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5498 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | } finally { |
| 5500 | Binder.restoreCallingIdentity(identity); |
| 5501 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5502 | } |
| 5503 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5504 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5505 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5506 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5507 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5508 | * @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] | 5509 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5510 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5511 | * @param packageName The name of the package that the current configuration will be replaced |
| 5512 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5513 | * @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] | 5514 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5515 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5516 | int[] featureTypes, String packageName) { |
| 5517 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5518 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5520 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5521 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5522 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); |
| 5524 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5525 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5526 | // may happen if the device does not support IMS. |
| 5527 | return false; |
| 5528 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5529 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5530 | for (int featureType : featureTypes) { |
| 5531 | featureConfig.put(featureType, packageName); |
| 5532 | } |
| 5533 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5534 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5535 | } finally { |
| 5536 | Binder.restoreCallingIdentity(identity); |
| 5537 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5538 | } |
| 5539 | |
| 5540 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5541 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5542 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5543 | * |
| 5544 | * This should only be used for testing. |
| 5545 | * |
| 5546 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5547 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5548 | */ |
| 5549 | @Override |
| 5550 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5551 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5552 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5553 | "clearCarrierImsServiceOverride"); |
| 5554 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5555 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5556 | "clearCarrierImsServiceOverride"); |
| 5557 | |
| 5558 | final long identity = Binder.clearCallingIdentity(); |
| 5559 | try { |
| 5560 | if (mImsResolver == null) { |
| 5561 | // may happen if the device does not support IMS. |
| 5562 | return false; |
| 5563 | } |
| 5564 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5565 | } finally { |
| 5566 | Binder.restoreCallingIdentity(identity); |
| 5567 | } |
| 5568 | } |
| 5569 | |
| 5570 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5571 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5572 | * |
| 5573 | * @param slotId The slot that the ImsService is associated with. |
| 5574 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5575 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5576 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5577 | * @return the package name of the ImsService configuration. |
| 5578 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5579 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5580 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5581 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5582 | TelephonyPermissions |
| 5583 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5584 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5585 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5586 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | final long identity = Binder.clearCallingIdentity(); |
| 5588 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5589 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5590 | // may happen if the device does not support IMS. |
| 5591 | return ""; |
| 5592 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5593 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5594 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5595 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5601 | /** |
| 5602 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5603 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5604 | * @param callback A callback with an integer containing the |
| 5605 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5606 | */ |
| 5607 | @Override |
| 5608 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5609 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5610 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5611 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5612 | "IMS not available on device."); |
| 5613 | } |
| 5614 | final long token = Binder.clearCallingIdentity(); |
| 5615 | try { |
| 5616 | int slotId = getSlotIndex(subId); |
| 5617 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5618 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5619 | + subId + "'"); |
| 5620 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5621 | } |
| 5622 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5623 | try { |
| 5624 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5625 | } catch (RemoteException e) { |
| 5626 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5627 | + "Ignore"); |
| 5628 | } |
| 5629 | }); |
| 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(token); |
| 5632 | } |
| 5633 | } |
| 5634 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5635 | /** |
| 5636 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5637 | */ |
| 5638 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5639 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | |
| 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5643 | // NOTE: Before S, this method only set the default phone. |
| 5644 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5645 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5646 | phone.setImsRegistrationState(registered); |
| 5647 | } |
| 5648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
| 5651 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5655 | * Set the network selection mode to automatic. |
| 5656 | * |
| 5657 | */ |
| 5658 | @Override |
| 5659 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5661 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5662 | |
| 5663 | final long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5665 | if (!isActiveSubscription(subId)) { |
| 5666 | return; |
| 5667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5668 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5669 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5670 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5674 | } |
| 5675 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5676 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5677 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5678 | * |
| 5679 | * @param subId the id of the subscription. |
| 5680 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5681 | * the operator to attach to. |
| 5682 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5683 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5684 | * normal network selection next time. |
| 5685 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5686 | */ |
| 5687 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5688 | public boolean setNetworkSelectionModeManual( |
| 5689 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5691 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5692 | |
| 5693 | if (!isActiveSubscription(subId)) { |
| 5694 | return false; |
| 5695 | } |
| 5696 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5699 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5701 | if (DBG) { |
| 5702 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5703 | + " operator: " + operatorInfo); |
| 5704 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
| 5708 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5709 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5710 | /** |
| 5711 | * Get the manual network selection |
| 5712 | * |
| 5713 | * @param subId the id of the subscription. |
| 5714 | * |
| 5715 | * @return the previously saved user selected PLMN |
| 5716 | */ |
| 5717 | @Override |
| 5718 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5719 | TelephonyPermissions |
| 5720 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5721 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5722 | |
| 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | if (!isActiveSubscription(subId)) { |
| 5726 | return ""; |
| 5727 | } |
| 5728 | |
| 5729 | final Phone phone = getPhone(subId); |
| 5730 | if (phone == null) { |
| 5731 | return ""; |
| 5732 | } |
| 5733 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5734 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5735 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
| 5739 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5740 | |
| 5741 | /** |
| 5742 | * Scans for available networks. |
| 5743 | */ |
| 5744 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5745 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5746 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5748 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5749 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5750 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5751 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5752 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5753 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5754 | .setCallingPid(Binder.getCallingPid()) |
| 5755 | .setCallingUid(Binder.getCallingUid()) |
| 5756 | .setMethod("getCellNetworkScanResults") |
| 5757 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5758 | .build()); |
| 5759 | switch (locationResult) { |
| 5760 | case DENIED_HARD: |
| 5761 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5762 | case DENIED_SOFT: |
| 5763 | return null; |
| 5764 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5766 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5767 | try { |
| 5768 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5769 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | } finally { |
| 5772 | Binder.restoreCallingIdentity(identity); |
| 5773 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
| 5776 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5777 | * Get the call forwarding info, given the call forwarding reason. |
| 5778 | */ |
| 5779 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5780 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5781 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5782 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5783 | long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
| 5785 | if (DBG) { |
| 5786 | log("getCallForwarding: subId " + subId |
| 5787 | + " callForwardingReason" + callForwardingReason); |
| 5788 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5789 | |
| 5790 | Phone phone = getPhone(subId); |
| 5791 | if (phone == null) { |
| 5792 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5793 | callback.onError( |
| 5794 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5795 | } catch (RemoteException e) { |
| 5796 | // ignore |
| 5797 | } |
| 5798 | return; |
| 5799 | } |
| 5800 | |
| 5801 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5802 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5803 | @Override |
| 5804 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5805 | try { |
| 5806 | callback.onCallForwardingInfoAvailable(info); |
| 5807 | } catch (RemoteException e) { |
| 5808 | // ignore |
| 5809 | } |
| 5810 | } |
| 5811 | |
| 5812 | @Override |
| 5813 | public void onError(int error) { |
| 5814 | try { |
| 5815 | callback.onError(error); |
| 5816 | } catch (RemoteException e) { |
| 5817 | // ignore |
| 5818 | } |
| 5819 | } |
| 5820 | }); |
| 5821 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5822 | } finally { |
| 5823 | Binder.restoreCallingIdentity(identity); |
| 5824 | } |
| 5825 | } |
| 5826 | |
| 5827 | /** |
| 5828 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5829 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5830 | */ |
| 5831 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5832 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5833 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5834 | enforceModifyPermission(); |
| 5835 | long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
| 5837 | if (DBG) { |
| 5838 | log("setCallForwarding: subId " + subId |
| 5839 | + " callForwardingInfo" + callForwardingInfo); |
| 5840 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5841 | |
| 5842 | Phone phone = getPhone(subId); |
| 5843 | if (phone == null) { |
| 5844 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5845 | callback.accept( |
| 5846 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5847 | } catch (RemoteException e) { |
| 5848 | // ignore |
| 5849 | } |
| 5850 | return; |
| 5851 | } |
| 5852 | |
| 5853 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5854 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5855 | |
| 5856 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5863 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5864 | */ |
| 5865 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5866 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5867 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5868 | long identity = Binder.clearCallingIdentity(); |
| 5869 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5870 | |
| 5871 | Phone phone = getPhone(subId); |
| 5872 | if (phone == null) { |
| 5873 | try { |
| 5874 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5875 | } catch (RemoteException e) { |
| 5876 | // ignore |
| 5877 | } |
| 5878 | return; |
| 5879 | } |
| 5880 | |
| 5881 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5882 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5883 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5884 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5885 | } finally { |
| 5886 | Binder.restoreCallingIdentity(identity); |
| 5887 | } |
| 5888 | } |
| 5889 | |
| 5890 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5891 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5892 | */ |
| 5893 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5894 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5895 | enforceModifyPermission(); |
| 5896 | long identity = Binder.clearCallingIdentity(); |
| 5897 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5898 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5899 | |
| 5900 | Phone phone = getPhone(subId); |
| 5901 | if (phone == null) { |
| 5902 | try { |
| 5903 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5904 | } catch (RemoteException e) { |
| 5905 | // ignore |
| 5906 | } |
| 5907 | return; |
| 5908 | } |
| 5909 | |
| 5910 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5911 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5912 | |
| 5913 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5914 | } finally { |
| 5915 | Binder.restoreCallingIdentity(identity); |
| 5916 | } |
| 5917 | } |
| 5918 | |
| 5919 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5920 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5921 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5922 | * @param subId id of the subscription |
| 5923 | * @param request contains the radio access networks with bands/channels to scan |
| 5924 | * @param messenger callback messenger for scan results or errors |
| 5925 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5926 | * @return the id of the requested scan which can be used to stop the scan. |
| 5927 | */ |
| 5928 | @Override |
| 5929 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5930 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5932 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5933 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5934 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5935 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5936 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5937 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5938 | .setCallingPid(Binder.getCallingPid()) |
| 5939 | .setCallingUid(Binder.getCallingUid()) |
| 5940 | .setMethod("requestNetworkScan") |
| 5941 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5942 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5943 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5944 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5945 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5946 | if (e != null) { |
| 5947 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5948 | throw e; |
| 5949 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5950 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5951 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5952 | } |
| 5953 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5955 | int callingUid = Binder.getCallingUid(); |
| 5956 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5957 | final long identity = Binder.clearCallingIdentity(); |
| 5958 | try { |
| 5959 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5960 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5961 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
| 5964 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5967 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5968 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5969 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5970 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5971 | boolean hasNetworkScanPermission = |
| 5972 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5973 | == PERMISSION_GRANTED; |
| 5974 | |
| 5975 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5976 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5977 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5981 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5982 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5983 | return new SecurityException("Specific channels must not be" |
| 5984 | + " scanned without location access."); |
| 5985 | } |
| 5986 | } |
| 5987 | } |
| 5988 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5989 | return null; |
| 5990 | } |
| 5991 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5992 | /** |
| 5993 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5994 | * |
| 5995 | * @param subId id of the subscription |
| 5996 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5997 | */ |
| 5998 | @Override |
| 5999 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6001 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6003 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6004 | final long identity = Binder.clearCallingIdentity(); |
| 6005 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6006 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6007 | } finally { |
| 6008 | Binder.restoreCallingIdentity(identity); |
| 6009 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6013 | * Get the calculated preferred network type. |
| 6014 | * Used for debugging incorrect network type. |
| 6015 | * |
| 6016 | * @return the preferred network type, defined in RILConstants.java. |
| 6017 | */ |
| 6018 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6019 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6020 | final Phone defaultPhone = getDefaultPhone(); |
| 6021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6022 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6023 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 6024 | } |
| 6025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
| 6028 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6029 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | } finally { |
| 6031 | Binder.restoreCallingIdentity(identity); |
| 6032 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
| 6035 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6036 | * Get the preferred network type. |
| 6037 | * Used for device configuration by some CDMA operators. |
| 6038 | * |
| 6039 | * @return the preferred network type, defined in RILConstants.java. |
| 6040 | */ |
| 6041 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6042 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6043 | TelephonyPermissions |
| 6044 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6045 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | |
| 6047 | final long identity = Binder.clearCallingIdentity(); |
| 6048 | try { |
| 6049 | if (DBG) log("getPreferredNetworkType"); |
| 6050 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 6051 | int networkType = (result != null ? result[0] : -1); |
| 6052 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 6053 | return networkType; |
| 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(identity); |
| 6056 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | /** |
| 6060 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6061 | * |
| 6062 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 6063 | * @return true on success; false on any failure. |
| 6064 | */ |
| 6065 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6066 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6068 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | |
| 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6072 | Boolean success = (Boolean) sendRequest( |
| 6073 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 6074 | |
| 6075 | if (success) { |
| 6076 | Settings.Global.putInt(mApp.getContentResolver(), |
| 6077 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 6078 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6079 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 6080 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 6083 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6084 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6085 | |
| 6086 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6087 | * Get the allowed network types that store in the telephony provider. |
| 6088 | * |
| 6089 | * @param subId the id of the subscription. |
| 6090 | * @return allowedNetworkTypes the allowed network types. |
| 6091 | */ |
| 6092 | @Override |
| 6093 | public long getAllowedNetworkTypes(int subId) { |
| 6094 | TelephonyPermissions |
| 6095 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6096 | mApp, subId, "getAllowedNetworkTypes"); |
| 6097 | |
| 6098 | final long identity = Binder.clearCallingIdentity(); |
| 6099 | try { |
| 6100 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6101 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
| 6104 | } |
| 6105 | } |
| 6106 | |
| 6107 | /** |
| 6108 | * Set the allowed network types. |
| 6109 | * |
| 6110 | * @param subId the id of the subscription. |
| 6111 | * @param allowedNetworkTypes the allowed network types. |
| 6112 | * @return true on success; false on any failure. |
| 6113 | */ |
| 6114 | @Override |
| 6115 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6116 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6117 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6118 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6119 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6120 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6121 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6122 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6123 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6124 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6125 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6126 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6130 | * Get the allowed network types for certain reason. |
| 6131 | * |
| 6132 | * @param subId the id of the subscription. |
| 6133 | * @param reason the reason the allowed network type change is taking place |
| 6134 | * @return the allowed network types. |
| 6135 | */ |
| 6136 | @Override |
| 6137 | public long getAllowedNetworkTypesForReason(int subId, |
| 6138 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6139 | TelephonyPermissions |
| 6140 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6141 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6142 | final long identity = Binder.clearCallingIdentity(); |
| 6143 | try { |
| 6144 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6145 | } finally { |
| 6146 | Binder.restoreCallingIdentity(identity); |
| 6147 | } |
| 6148 | } |
| 6149 | |
| 6150 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6151 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6152 | * @param subId subscription id of the sim card |
| 6153 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6154 | * This can be passed following states |
| 6155 | * <ol> |
| 6156 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6157 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6158 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6159 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6160 | * </ol> |
| 6161 | * @return operation result. |
| 6162 | */ |
| 6163 | @Override |
| 6164 | public int setNrDualConnectivityState(int subId, |
| 6165 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6167 | mApp, subId, "enableNRDualConnectivity"); |
| 6168 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6169 | final long identity = Binder.clearCallingIdentity(); |
| 6170 | try { |
| 6171 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6172 | nrDualConnectivityState, subId, |
| 6173 | workSource); |
| 6174 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6175 | return result; |
| 6176 | } finally { |
| 6177 | Binder.restoreCallingIdentity(identity); |
| 6178 | } |
| 6179 | } |
| 6180 | |
| 6181 | /** |
| 6182 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6183 | * @return true if dual connectivity is enabled else false |
| 6184 | */ |
| 6185 | @Override |
| 6186 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6187 | TelephonyPermissions |
| 6188 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6189 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6190 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6191 | final long identity = Binder.clearCallingIdentity(); |
| 6192 | try { |
| 6193 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6194 | null, subId, workSource); |
| 6195 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6196 | return isEnabled; |
| 6197 | } finally { |
| 6198 | Binder.restoreCallingIdentity(identity); |
| 6199 | } |
| 6200 | } |
| 6201 | |
| 6202 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6203 | * get carrier bandwidth per primary and secondary carrier |
| 6204 | * @param subId subscription id of the sim card |
| 6205 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6206 | */ |
| 6207 | @Override |
| 6208 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6209 | TelephonyPermissions |
| 6210 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6211 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6212 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6213 | final long identity = Binder.clearCallingIdentity(); |
| 6214 | try { |
| 6215 | CarrierBandwidth carrierBandwidth = |
| 6216 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6217 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6218 | return carrierBandwidth; |
| 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
| 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6225 | * Get the effective allowed network types on the device. |
| 6226 | * This API will return an intersection of allowed network types for all reasons, |
| 6227 | * including the configuration done through setAllowedNetworkTypes |
| 6228 | * |
| 6229 | * @param subId the id of the subscription. |
| 6230 | * @return the allowed network types |
| 6231 | */ |
| 6232 | @Override |
| 6233 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6234 | TelephonyPermissions |
| 6235 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6236 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | try { |
| 6239 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6240 | } finally { |
| 6241 | Binder.restoreCallingIdentity(identity); |
| 6242 | } |
| 6243 | } |
| 6244 | |
| 6245 | /** |
| 6246 | * Set the allowed network types of the device and |
| 6247 | * provide the reason triggering the allowed network change. |
| 6248 | * |
| 6249 | * @param subId the id of the subscription. |
| 6250 | * @param reason the reason the allowed network type change is taking place |
| 6251 | * @param allowedNetworkTypes the allowed network types. |
| 6252 | * @return true on success; false on any failure. |
| 6253 | */ |
| 6254 | @Override |
| 6255 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6256 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6257 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6258 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6259 | final long identity = Binder.clearCallingIdentity(); |
| 6260 | try { |
| 6261 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6262 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6263 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6264 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6265 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6266 | } finally { |
| 6267 | Binder.restoreCallingIdentity(identity); |
| 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6272 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6273 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6274 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6275 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6276 | * @hide |
| 6277 | */ |
| 6278 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6279 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6282 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6284 | if (phone != null) { |
| 6285 | return phone.hasMatchedTetherApnSetting(); |
| 6286 | } else { |
| 6287 | return false; |
| 6288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | } finally { |
| 6290 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6291 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6295 | * Enable or disable always reporting signal strength changes from radio. |
| 6296 | * |
| 6297 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6298 | */ |
| 6299 | @Override |
| 6300 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6301 | enforceModifyPermission(); |
| 6302 | enforceSystemCaller(); |
| 6303 | |
| 6304 | final long identity = Binder.clearCallingIdentity(); |
| 6305 | final Phone phone = getPhone(subId); |
| 6306 | try { |
| 6307 | if (phone != null) { |
| 6308 | if (DBG) { |
| 6309 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6310 | + " isEnable=" + isEnable); |
| 6311 | } |
| 6312 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6313 | } else { |
| 6314 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6315 | + subId); |
| 6316 | } |
| 6317 | } finally { |
| 6318 | Binder.restoreCallingIdentity(identity); |
| 6319 | } |
| 6320 | } |
| 6321 | |
| 6322 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6323 | * Get the user enabled state of Mobile Data. |
| 6324 | * |
| 6325 | * TODO: remove and use isUserDataEnabled. |
| 6326 | * This can't be removed now because some vendor codes |
| 6327 | * calls through ITelephony directly while they should |
| 6328 | * use TelephonyManager. |
| 6329 | * |
| 6330 | * @return true on enabled |
| 6331 | */ |
| 6332 | @Override |
| 6333 | public boolean getDataEnabled(int subId) { |
| 6334 | return isUserDataEnabled(subId); |
| 6335 | } |
| 6336 | |
| 6337 | /** |
| 6338 | * Get whether mobile data is enabled per user setting. |
| 6339 | * |
| 6340 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6341 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6342 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6343 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6344 | * |
| 6345 | * @return {@code true} if data is enabled else {@code false} |
| 6346 | */ |
| 6347 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6348 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6349 | try { |
| 6350 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6351 | null); |
| 6352 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6354 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6355 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6356 | |
| 6357 | final long identity = Binder.clearCallingIdentity(); |
| 6358 | try { |
| 6359 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6360 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6361 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6362 | if (phone != null) { |
| 6363 | boolean retVal = phone.isUserDataEnabled(); |
| 6364 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6365 | return retVal; |
| 6366 | } else { |
| 6367 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6368 | return false; |
| 6369 | } |
| 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6376 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6377 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6378 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6379 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6380 | * @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] | 6381 | */ |
| 6382 | @Override |
| 6383 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6384 | try { |
| 6385 | try { |
| 6386 | mApp.enforceCallingOrSelfPermission( |
| 6387 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6388 | null); |
| 6389 | } catch (Exception e) { |
| 6390 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6391 | "isDataEnabled"); |
| 6392 | } |
| 6393 | } catch (Exception e) { |
| 6394 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6395 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6396 | |
| 6397 | final long identity = Binder.clearCallingIdentity(); |
| 6398 | try { |
| 6399 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6400 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6401 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6402 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6403 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6404 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6405 | return retVal; |
| 6406 | } else { |
| 6407 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6408 | return false; |
| 6409 | } |
| 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6412 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6413 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6414 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6415 | /** |
| 6416 | * Check if data is enabled for a specific reason |
| 6417 | * @param subId Subscription index |
| 6418 | * @param reason the reason the data enable change is taking place |
| 6419 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6420 | */ |
| 6421 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6422 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6423 | @TelephonyManager.DataEnabledReason int reason) { |
| 6424 | try { |
| 6425 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6426 | null); |
| 6427 | } catch (Exception e) { |
| 6428 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6429 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6430 | } |
| 6431 | |
| 6432 | |
| 6433 | final long identity = Binder.clearCallingIdentity(); |
| 6434 | try { |
| 6435 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6436 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6437 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6438 | + " reason=" + reason); |
| 6439 | } |
| 6440 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6441 | if (phone != null) { |
| 6442 | boolean retVal; |
| 6443 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6444 | retVal = phone.isUserDataEnabled(); |
| 6445 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6446 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6447 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6448 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6449 | return retVal; |
| 6450 | } else { |
| 6451 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6452 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6453 | + subId + " retVal=false"); |
| 6454 | } |
| 6455 | return false; |
| 6456 | } |
| 6457 | } finally { |
| 6458 | Binder.restoreCallingIdentity(identity); |
| 6459 | } |
| 6460 | } |
| 6461 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6462 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6463 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6464 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6465 | // Skip the check if it's one of these special uids |
| 6466 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6467 | } |
| 6468 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6469 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6470 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6471 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6472 | || subController == null) return privilegeFromSim; |
| 6473 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6474 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6475 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6476 | |
| 6477 | final long identity = Binder.clearCallingIdentity(); |
| 6478 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6479 | int subId = phone.getSubId(); |
| 6480 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6481 | // A test override is in place for the privileges for this subId, so don't try to |
| 6482 | // read the subscription privileges. |
| 6483 | return privilegeFromSim; |
| 6484 | } |
| 6485 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6486 | SubscriptionManager subManager = (SubscriptionManager) |
| 6487 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6488 | for (String pkg : packages) { |
| 6489 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6490 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6491 | } |
| 6492 | } |
| 6493 | return privilegeFromSim; |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6500 | String pkgName) { |
| 6501 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6502 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6503 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6504 | || subController == null) return privilegeFromSim; |
| 6505 | |
| 6506 | final long identity = Binder.clearCallingIdentity(); |
| 6507 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6508 | int subId = phone.getSubId(); |
| 6509 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6510 | // A test override is in place for the privileges for this subId, so don't try to |
| 6511 | // read the subscription privileges. |
| 6512 | return privilegeFromSim; |
| 6513 | } |
| 6514 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6515 | SubscriptionManager subManager = (SubscriptionManager) |
| 6516 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6517 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6518 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
| 6521 | } |
| 6522 | } |
| 6523 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6524 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6525 | public int getCarrierPrivilegeStatus(int subId) { |
| 6526 | final Phone phone = getPhone(subId); |
| 6527 | if (phone == null) { |
| 6528 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6529 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6530 | } |
| 6531 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6532 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6533 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6534 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6535 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6536 | |
| 6537 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6538 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6539 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6540 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6541 | |
| 6542 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6543 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6544 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6545 | final Phone phone = getPhone(subId); |
| 6546 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6547 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6548 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6549 | } |
| 6550 | UiccProfile profile = |
| 6551 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6552 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6553 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6554 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6555 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6556 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6557 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6558 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6559 | } |
| 6560 | |
| 6561 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6562 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6563 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6564 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6568 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6569 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6570 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6571 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6572 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6573 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6574 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6575 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6576 | } |
| 6577 | |
| 6578 | @Override |
| 6579 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6580 | if (TextUtils.isEmpty(pkgName)) |
| 6581 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6582 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6583 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6584 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6585 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6586 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6587 | continue; |
| 6588 | } |
| 6589 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6590 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6591 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6592 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6593 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6594 | break; |
| 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6599 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6600 | |
| 6601 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6602 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6603 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6604 | loge("phoneId " + phoneId + " is not valid."); |
| 6605 | return null; |
| 6606 | } |
| 6607 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6608 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6609 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6610 | return null ; |
| 6611 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6612 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6613 | } |
| 6614 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6615 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6616 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6617 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6618 | List<String> privilegedPackages = new ArrayList<>(); |
| 6619 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6620 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6621 | // has UICC in that slot. |
| 6622 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6623 | if (card.hasCarrierPrivilegeRules()) { |
| 6624 | if (packages == null) { |
| 6625 | // Only check packages in user 0 for now |
| 6626 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6627 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6628 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6629 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6630 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6631 | } |
| 6632 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6633 | PackageInfo pkgInfo = packages.get(p); |
| 6634 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6635 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6636 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6637 | privilegedPackages.add(pkgInfo.packageName); |
| 6638 | } |
| 6639 | } |
| 6640 | } |
| 6641 | } |
| 6642 | return privilegedPackages; |
| 6643 | } |
| 6644 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6645 | @Override |
| 6646 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6647 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6648 | |
| 6649 | final long identity = Binder.clearCallingIdentity(); |
| 6650 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6651 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6652 | try { |
| 6653 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6654 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6655 | } |
| 6656 | } finally { |
| 6657 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6658 | } |
| 6659 | return privilegedPackages; |
| 6660 | } |
| 6661 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6662 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6663 | final Phone phone = getPhone(subId); |
| 6664 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6665 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6666 | return null; |
| 6667 | } |
| 6668 | String iccId = card.getIccId(); |
| 6669 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6670 | return null; |
| 6671 | } |
| 6672 | return iccId; |
| 6673 | } |
| 6674 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6675 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6676 | public void setCallComposerStatus(int subId, int status) { |
| 6677 | enforceModifyPermission(); |
| 6678 | |
| 6679 | final long identity = Binder.clearCallingIdentity(); |
| 6680 | try { |
| 6681 | Phone phone = getPhone(subId); |
| 6682 | if (phone != null) { |
| 6683 | Phone defaultPhone = phone.getImsPhone(); |
| 6684 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6685 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6686 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6687 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6688 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6689 | } |
| 6690 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6691 | } catch (ImsException e) { |
| 6692 | throw new ServiceSpecificException(e.getCode()); |
| 6693 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6694 | Binder.restoreCallingIdentity(identity); |
| 6695 | } |
| 6696 | } |
| 6697 | |
| 6698 | @Override |
| 6699 | public int getCallComposerStatus(int subId) { |
| 6700 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6701 | |
| 6702 | final long identity = Binder.clearCallingIdentity(); |
| 6703 | try { |
| 6704 | Phone phone = getPhone(subId); |
| 6705 | if (phone != null) { |
| 6706 | Phone defaultPhone = phone.getImsPhone(); |
| 6707 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6708 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6709 | return imsPhone.getCallComposerStatus(); |
| 6710 | } |
| 6711 | } |
| 6712 | } finally { |
| 6713 | Binder.restoreCallingIdentity(identity); |
| 6714 | } |
| 6715 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6716 | } |
| 6717 | |
| 6718 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6719 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6720 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6721 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6722 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
| 6726 | final String iccId = getIccId(subId); |
| 6727 | final Phone phone = getPhone(subId); |
| 6728 | if (phone == null) { |
| 6729 | return false; |
| 6730 | } |
| 6731 | final String subscriberId = phone.getSubscriberId(); |
| 6732 | |
| 6733 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6734 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6735 | + subscriberId + " to " + number); |
| 6736 | } |
| 6737 | |
| 6738 | if (TextUtils.isEmpty(iccId)) { |
| 6739 | return false; |
| 6740 | } |
| 6741 | |
| 6742 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6743 | |
| 6744 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6745 | if (alphaTag == null) { |
| 6746 | editor.remove(alphaTagPrefKey); |
| 6747 | } else { |
| 6748 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6749 | } |
| 6750 | |
| 6751 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6752 | // track all merged IMSIs based on line number |
| 6753 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6754 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6755 | if (number == null) { |
| 6756 | editor.remove(numberPrefKey); |
| 6757 | editor.remove(subscriberPrefKey); |
| 6758 | } else { |
| 6759 | editor.putString(numberPrefKey, number); |
| 6760 | editor.putString(subscriberPrefKey, subscriberId); |
| 6761 | } |
| 6762 | |
| 6763 | editor.commit(); |
| 6764 | return true; |
| 6765 | } finally { |
| 6766 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6767 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6771 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6772 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6773 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6775 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6776 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6777 | return null; |
| 6778 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | final long identity = Binder.clearCallingIdentity(); |
| 6781 | try { |
| 6782 | String iccId = getIccId(subId); |
| 6783 | if (iccId != null) { |
| 6784 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6785 | if (DBG_MERGE) { |
| 6786 | log("getLine1NumberForDisplay returning " |
| 6787 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6788 | } |
| 6789 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6790 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6791 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6792 | return null; |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6795 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6799 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6800 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6802 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6803 | return null; |
| 6804 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6805 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
| 6808 | String iccId = getIccId(subId); |
| 6809 | if (iccId != null) { |
| 6810 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6811 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6812 | } |
| 6813 | return null; |
| 6814 | } finally { |
| 6815 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6816 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6817 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6818 | |
| 6819 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6820 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6821 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6822 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6823 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6825 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6826 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6827 | return null; |
| 6828 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6829 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6830 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6831 | // the process, where TelephonyManager was instantiated. |
| 6832 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6833 | final long identity = Binder.clearCallingIdentity(); |
| 6834 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6835 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6836 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6837 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6838 | |
| 6839 | // Figure out what subscribers are currently active |
| 6840 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6842 | // Only consider subs which match the current subId |
| 6843 | // This logic can be simplified. See b/131189269 for progress. |
| 6844 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6845 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6847 | |
| 6848 | // First pass, find a number override for an active subscriber |
| 6849 | String mergeNumber = null; |
| 6850 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6851 | for (String key : prefs.keySet()) { |
| 6852 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6853 | final String subscriberId = (String) prefs.get(key); |
| 6854 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6855 | final String iccId = key.substring( |
| 6856 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6857 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6858 | mergeNumber = (String) prefs.get(numberKey); |
| 6859 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6860 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | + " for active subscriber " + subscriberId); |
| 6862 | } |
| 6863 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6864 | break; |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | } |
| 6869 | |
| 6870 | // Shortcut when no active merged subscribers |
| 6871 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6872 | return null; |
| 6873 | } |
| 6874 | |
| 6875 | // Second pass, find all subscribers under that line override |
| 6876 | final ArraySet<String> result = new ArraySet<>(); |
| 6877 | for (String key : prefs.keySet()) { |
| 6878 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6879 | final String number = (String) prefs.get(key); |
| 6880 | if (mergeNumber.equals(number)) { |
| 6881 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6882 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6883 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6884 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6885 | result.add(subscriberId); |
| 6886 | } |
| 6887 | } |
| 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6892 | Arrays.sort(resultArray); |
| 6893 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6894 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6895 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6896 | } |
| 6897 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6898 | } finally { |
| 6899 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6900 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6901 | } |
| 6902 | |
| 6903 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6904 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6905 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6906 | |
| 6907 | final long identity = Binder.clearCallingIdentity(); |
| 6908 | try { |
| 6909 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6910 | TelephonyManager.class); |
| 6911 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6912 | if (subscriberId == null) { |
| 6913 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6914 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6915 | + subId); |
| 6916 | } |
| 6917 | return null; |
| 6918 | } |
| 6919 | |
| 6920 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6921 | .getSubscriptionInfo(subId); |
| 6922 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6923 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6924 | if (groupUuid == null) { |
| 6925 | return new String[]{subscriberId}; |
| 6926 | } |
| 6927 | |
| 6928 | // Get all subscriberIds from the group. |
| 6929 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6930 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6931 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6932 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6933 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6934 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6935 | if (subscriberId != null) { |
| 6936 | mergedSubscriberIds.add(subscriberId); |
| 6937 | } |
| 6938 | } |
| 6939 | |
| 6940 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6941 | } finally { |
| 6942 | Binder.restoreCallingIdentity(identity); |
| 6943 | |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6948 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6949 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6950 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6951 | |
| 6952 | final long identity = Binder.clearCallingIdentity(); |
| 6953 | try { |
| 6954 | final Phone phone = getPhone(subId); |
| 6955 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6956 | } finally { |
| 6957 | Binder.restoreCallingIdentity(identity); |
| 6958 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6959 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6960 | |
| 6961 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6962 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6963 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6964 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6965 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6966 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6967 | |
| 6968 | final long identity = Binder.clearCallingIdentity(); |
| 6969 | try { |
| 6970 | final Phone phone = getPhone(subId); |
| 6971 | if (phone == null) { |
| 6972 | return false; |
| 6973 | } |
| 6974 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6975 | cdmaNonRoamingList); |
| 6976 | } finally { |
| 6977 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6978 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6982 | @Deprecated |
| 6983 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6984 | enforceModifyPermission(); |
| 6985 | |
| 6986 | int returnValue = 0; |
| 6987 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6988 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6989 | if(result.exception == null) { |
| 6990 | if (result.result != null) { |
| 6991 | byte[] responseData = (byte[])(result.result); |
| 6992 | if(responseData.length > oemResp.length) { |
| 6993 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6994 | responseData.length + "bytes. Buffer Size is " + |
| 6995 | oemResp.length + "bytes."); |
| 6996 | } |
| 6997 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6998 | returnValue = responseData.length; |
| 6999 | } |
| 7000 | } else { |
| 7001 | CommandException ex = (CommandException) result.exception; |
| 7002 | returnValue = ex.getCommandError().ordinal(); |
| 7003 | if(returnValue > 0) returnValue *= -1; |
| 7004 | } |
| 7005 | } catch (RuntimeException e) { |
| 7006 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7007 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7008 | if(returnValue > 0) returnValue *= -1; |
| 7009 | } |
| 7010 | |
| 7011 | return returnValue; |
| 7012 | } |
| 7013 | |
| 7014 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7015 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 7016 | try { |
| 7017 | ProxyController.getInstance().setRadioCapability(rafs); |
| 7018 | } catch (RuntimeException e) { |
| 7019 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7024 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7025 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7026 | try { |
| 7027 | TelephonyPermissions |
| 7028 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7029 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7030 | } catch (SecurityException e) { |
| 7031 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7032 | throw e; |
| 7033 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7034 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7035 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7036 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7040 | TelephonyPermissions |
| 7041 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7042 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7043 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7044 | } finally { |
| 7045 | Binder.restoreCallingIdentity(identity); |
| 7046 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7047 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7048 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7049 | |
| 7050 | @Override |
| 7051 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7052 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7053 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7054 | |
| 7055 | final long identity = Binder.clearCallingIdentity(); |
| 7056 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7057 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7058 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7062 | } |
| 7063 | |
| 7064 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7065 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7066 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7068 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7069 | return false; |
| 7070 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7072 | final long identity = Binder.clearCallingIdentity(); |
| 7073 | try { |
| 7074 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7075 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7076 | // In the long run, we may instead need to check if there exists a connection service |
| 7077 | // which can support video calling. |
| 7078 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7079 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | return imsManager.isVtEnabledByPlatform() |
| 7081 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7082 | && imsManager.isVtEnabledByUser(); |
| 7083 | } finally { |
| 7084 | Binder.restoreCallingIdentity(identity); |
| 7085 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7086 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7087 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7088 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7089 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7090 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7091 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7092 | mApp, subId, callingPackage, callingFeatureId, |
| 7093 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | return false; |
| 7095 | } |
| 7096 | |
| 7097 | final long identity = Binder.clearCallingIdentity(); |
| 7098 | try { |
| 7099 | CarrierConfigManager configManager = |
| 7100 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7101 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7102 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7103 | } finally { |
| 7104 | Binder.restoreCallingIdentity(identity); |
| 7105 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7109 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7110 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7111 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7112 | return false; |
| 7113 | } |
| 7114 | |
| 7115 | final long identity = Binder.clearCallingIdentity(); |
| 7116 | try { |
| 7117 | CarrierConfigManager configManager = |
| 7118 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7119 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7121 | } finally { |
| 7122 | Binder.restoreCallingIdentity(identity); |
| 7123 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7124 | } |
| 7125 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7126 | @Override |
| 7127 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7128 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7129 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7130 | } |
| 7131 | |
| 7132 | @Override |
| 7133 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7134 | final long identity = Binder.clearCallingIdentity(); |
| 7135 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7136 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
| 7139 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7140 | } |
| 7141 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7142 | /** |
| 7143 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7144 | * support for the feature and device firmware support. |
| 7145 | * |
| 7146 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7147 | */ |
| 7148 | @Override |
| 7149 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7151 | final Phone phone = getPhone(subscriptionId); |
| 7152 | if (phone == null) { |
| 7153 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7154 | return false; |
| 7155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7157 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7159 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7160 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7161 | return isCarrierSupported && isDeviceSupported; |
| 7162 | } finally { |
| 7163 | Binder.restoreCallingIdentity(identity); |
| 7164 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7165 | } |
| 7166 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7167 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7168 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7169 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7170 | * 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] | 7171 | */ |
| 7172 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7173 | final long identity = Binder.clearCallingIdentity(); |
| 7174 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7175 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7176 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7177 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7178 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7179 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7180 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | } finally { |
| 7182 | Binder.restoreCallingIdentity(identity); |
| 7183 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7184 | } |
| 7185 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7186 | @Deprecated |
| 7187 | @Override |
| 7188 | public String getDeviceId(String callingPackage) { |
| 7189 | return getDeviceIdWithFeature(callingPackage, null); |
| 7190 | } |
| 7191 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7192 | /** |
| 7193 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7194 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7195 | * |
| 7196 | * <p>Requires Permission: |
| 7197 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7198 | */ |
| 7199 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7200 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7201 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7202 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7203 | return null; |
| 7204 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7205 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7206 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7207 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7208 | return null; |
| 7209 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | |
| 7211 | final long identity = Binder.clearCallingIdentity(); |
| 7212 | try { |
| 7213 | return phone.getDeviceId(); |
| 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
| 7216 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7217 | } |
| 7218 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7219 | /** |
| 7220 | * {@hide} |
| 7221 | * Returns the IMS Registration Status on a particular subid |
| 7222 | * |
| 7223 | * @param subId |
| 7224 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7225 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7226 | Phone phone = getPhone(subId); |
| 7227 | if (phone != null) { |
| 7228 | return phone.isImsRegistered(); |
| 7229 | } else { |
| 7230 | return false; |
| 7231 | } |
| 7232 | } |
| 7233 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7234 | @Override |
| 7235 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
| 7238 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7239 | } finally { |
| 7240 | Binder.restoreCallingIdentity(identity); |
| 7241 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7242 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7243 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7244 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7245 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7246 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7247 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7248 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7249 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7250 | } |
| 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
| 7256 | } |
| 7257 | } |
| 7258 | |
| 7259 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7260 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7261 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7262 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7263 | final long identity = Binder.clearCallingIdentity(); |
| 7264 | try { |
| 7265 | Phone phone = getPhone(subscriptionId); |
| 7266 | if (phone == null) { |
| 7267 | return null; |
| 7268 | } |
| 7269 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7270 | } finally { |
| 7271 | Binder.restoreCallingIdentity(identity); |
| 7272 | } |
| 7273 | } |
| 7274 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7275 | /** |
| 7276 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7277 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7278 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | Phone phone = getPhone(subId); |
| 7282 | if (phone != null) { |
| 7283 | return phone.isWifiCallingEnabled(); |
| 7284 | } else { |
| 7285 | return false; |
| 7286 | } |
| 7287 | } finally { |
| 7288 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7289 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7290 | } |
| 7291 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7292 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7293 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7294 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7295 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
| 7298 | Phone phone = getPhone(subId); |
| 7299 | if (phone != null) { |
| 7300 | return phone.isVideoEnabled(); |
| 7301 | } else { |
| 7302 | return false; |
| 7303 | } |
| 7304 | } finally { |
| 7305 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7306 | } |
| 7307 | } |
| 7308 | |
| 7309 | /** |
| 7310 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7311 | * defined in {@link ImsRegistrationImplBase}. |
| 7312 | */ |
| 7313 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7314 | final long identity = Binder.clearCallingIdentity(); |
| 7315 | try { |
| 7316 | Phone phone = getPhone(subId); |
| 7317 | if (phone != null) { |
| 7318 | return phone.getImsRegistrationTech(); |
| 7319 | } else { |
| 7320 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7321 | } |
| 7322 | } finally { |
| 7323 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7324 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7325 | } |
| 7326 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7327 | @Override |
| 7328 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7329 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7330 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7331 | return; |
| 7332 | } |
| 7333 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7334 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7335 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7336 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7337 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7338 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7339 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7340 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7341 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7342 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7343 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7344 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7345 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7346 | // There has been issues when Sms raw table somehow stores orphan |
| 7347 | // fragments. They lead to garbled message when new fragments come |
| 7348 | // in and combined with those stale ones. In case this happens again, |
| 7349 | // user can reset all network settings which will clean up this table. |
| 7350 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7351 | // Clean up IMS settings as well here. |
| 7352 | int slotId = getSlotIndex(subId); |
| 7353 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7354 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7355 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7356 | |
| 7357 | // Erase modem config if erase modem on network setting is enabled. |
| 7358 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7359 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7360 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7361 | sendEraseModemConfig(getDefaultPhone()); |
| 7362 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7363 | } finally { |
| 7364 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7365 | } |
| 7366 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7367 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7368 | private void cleanUpSmsRawTable(Context context) { |
| 7369 | ContentResolver resolver = context.getContentResolver(); |
| 7370 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7371 | resolver.delete(uri, null, null); |
| 7372 | } |
| 7373 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7374 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7375 | public String getSimLocaleForSubscriber(int subId) { |
| 7376 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7377 | final Phone phone = getPhone(subId); |
| 7378 | if (phone == null) { |
| 7379 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7380 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7382 | final long identity = Binder.clearCallingIdentity(); |
| 7383 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7384 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7385 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7386 | if (info == null) { |
| 7387 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7388 | return null; |
| 7389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7390 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7391 | // preferences (EF-PL and EF-LI)... |
| 7392 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7393 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7394 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7395 | if (localeFromDefaultSim != null) { |
| 7396 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7397 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7398 | + localeFromDefaultSim); |
| 7399 | return localeFromDefaultSim.toLanguageTag(); |
| 7400 | } else { |
| 7401 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7402 | } |
| 7403 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7404 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7406 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7407 | // the SIM and carrier preferences does not include a country we add the country |
| 7408 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7409 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7411 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7412 | return mccLocale.toLanguageTag(); |
| 7413 | } |
| 7414 | |
| 7415 | if (DBG) log("No locale found - returning null"); |
| 7416 | return null; |
| 7417 | } finally { |
| 7418 | Binder.restoreCallingIdentity(identity); |
| 7419 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7423 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7424 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7425 | } |
| 7426 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | /** |
| 7428 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7429 | */ |
| 7430 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7431 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7432 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7433 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7434 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7435 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7436 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7437 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7438 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7439 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7440 | * representing the state of the modem. |
| 7441 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7442 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7443 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7444 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7445 | */ |
| 7446 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7447 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7448 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7449 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7450 | |
| 7451 | final long identity = Binder.clearCallingIdentity(); |
| 7452 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7453 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7454 | } finally { |
| 7455 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7456 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7457 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7458 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7459 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7460 | // less than total activity duration. |
| 7461 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7462 | if (info == null) { |
| 7463 | return false; |
| 7464 | } |
| 7465 | int activityDurationMs = |
| 7466 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7467 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7468 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7469 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7470 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7471 | } |
| 7472 | return (info.isValid() |
| 7473 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7474 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7475 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7476 | && (totalTxTimeMs <= activityDurationMs)); |
| 7477 | } |
| 7478 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7479 | /** |
| 7480 | * {@hide} |
| 7481 | * Returns the service state information on specified subscription. |
| 7482 | */ |
| 7483 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7484 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7485 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7487 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7488 | return null; |
| 7489 | } |
| 7490 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7491 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7492 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7493 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7494 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7495 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7496 | .setCallingPid(Binder.getCallingPid()) |
| 7497 | .setCallingUid(Binder.getCallingUid()) |
| 7498 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7499 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7500 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7501 | .build()); |
| 7502 | |
| 7503 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7504 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7505 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7506 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7507 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7508 | .setCallingPid(Binder.getCallingPid()) |
| 7509 | .setCallingUid(Binder.getCallingUid()) |
| 7510 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7511 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7512 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7513 | .build()); |
| 7514 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7515 | boolean hasFinePermission = |
| 7516 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7517 | boolean hasCoarsePermission = |
| 7518 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7519 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | final long identity = Binder.clearCallingIdentity(); |
| 7521 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7522 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7523 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7524 | Rlog.d(LOG_TAG, |
| 7525 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7526 | return null; |
| 7527 | } |
| 7528 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | final Phone phone = getPhone(subId); |
| 7530 | if (phone == null) { |
| 7531 | return null; |
| 7532 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7533 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7534 | ServiceState ss = phone.getServiceState(); |
| 7535 | |
| 7536 | // Scrub out the location info in ServiceState depending on what level of access |
| 7537 | // the caller has. |
| 7538 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7539 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7540 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7544 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7545 | |
| 7546 | /** |
| 7547 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7548 | * |
| 7549 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7550 | * voicemail ringtone. |
| 7551 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7552 | * PhoneAccount. |
| 7553 | */ |
| 7554 | @Override |
| 7555 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | final long identity = Binder.clearCallingIdentity(); |
| 7557 | try { |
| 7558 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7559 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7560 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7563 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
| 7566 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7570 | * Sets the per-account voicemail ringtone. |
| 7571 | * |
| 7572 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7573 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7574 | * |
| 7575 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7576 | * voicemail ringtone. |
| 7577 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7578 | * PhoneAccount. |
| 7579 | */ |
| 7580 | @Override |
| 7581 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7582 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7583 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7585 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7586 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7588 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7589 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7590 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7591 | |
| 7592 | final long identity = Binder.clearCallingIdentity(); |
| 7593 | try { |
| 7594 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7595 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7596 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7597 | } |
| 7598 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7599 | } finally { |
| 7600 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7601 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7605 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7606 | * |
| 7607 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7608 | * voicemail vibration setting. |
| 7609 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7610 | */ |
| 7611 | @Override |
| 7612 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7616 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7617 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7618 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7619 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7620 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7621 | } finally { |
| 7622 | Binder.restoreCallingIdentity(identity); |
| 7623 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7624 | } |
| 7625 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7626 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7627 | * Sets the per-account voicemail vibration. |
| 7628 | * |
| 7629 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7630 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7631 | * |
| 7632 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7633 | * voicemail vibration setting. |
| 7634 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7635 | * specific PhoneAccount. |
| 7636 | */ |
| 7637 | @Override |
| 7638 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7639 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7640 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7641 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7642 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7643 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7645 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7646 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7647 | } |
| 7648 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | final long identity = Binder.clearCallingIdentity(); |
| 7650 | try { |
| 7651 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7652 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7653 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7654 | } |
| 7655 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7656 | } finally { |
| 7657 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7658 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7659 | } |
| 7660 | |
| 7661 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7662 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7663 | * |
| 7664 | * @throws SecurityException if the caller does not have the required permission |
| 7665 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7666 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7667 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7668 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7669 | } |
| 7670 | |
| 7671 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7672 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7673 | * permission. |
| 7674 | * |
| 7675 | * @throws SecurityException if the caller does not have the required permission |
| 7676 | */ |
| 7677 | private void enforceSendSmsPermission() { |
| 7678 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7679 | } |
| 7680 | |
| 7681 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7682 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7683 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7684 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7685 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7686 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7690 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7691 | if (componentName == null) { |
| 7692 | throw new SecurityException( |
| 7693 | "Caller not current active visual voicemail package[null]"); |
| 7694 | } |
| 7695 | String vvmPackage = componentName.getPackageName(); |
| 7696 | if (!callingPackage.equals(vvmPackage)) { |
| 7697 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7698 | + vvmPackage + "]"); |
| 7699 | } |
| 7700 | } finally { |
| 7701 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7702 | } |
| 7703 | } |
| 7704 | |
| 7705 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7706 | * Return the application ID for the app type. |
| 7707 | * |
| 7708 | * @param subId the subscription ID that this request applies to. |
| 7709 | * @param appType the uicc app type. |
| 7710 | * @return Application ID for specificied app type, or null if no uicc. |
| 7711 | */ |
| 7712 | @Override |
| 7713 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7714 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7715 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7716 | |
| 7717 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7718 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | if (phone == null) { |
| 7720 | return null; |
| 7721 | } |
| 7722 | String aid = null; |
| 7723 | try { |
| 7724 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7725 | .getApplicationByType(appType).getAid(); |
| 7726 | } catch (Exception e) { |
| 7727 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7728 | } |
| 7729 | return aid; |
| 7730 | } finally { |
| 7731 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7732 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7733 | } |
| 7734 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7735 | /** |
| 7736 | * Return the Electronic Serial Number. |
| 7737 | * |
| 7738 | * @param subId the subscription ID that this request applies to. |
| 7739 | * @return ESN or null if error. |
| 7740 | */ |
| 7741 | @Override |
| 7742 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7743 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7744 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7745 | |
| 7746 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7747 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7748 | if (phone == null) { |
| 7749 | return null; |
| 7750 | } |
| 7751 | String esn = null; |
| 7752 | try { |
| 7753 | esn = phone.getEsn(); |
| 7754 | } catch (Exception e) { |
| 7755 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7756 | } |
| 7757 | return esn; |
| 7758 | } finally { |
| 7759 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7760 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7761 | } |
| 7762 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7763 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7764 | * Return the Preferred Roaming List Version. |
| 7765 | * |
| 7766 | * @param subId the subscription ID that this request applies to. |
| 7767 | * @return PRLVersion or null if error. |
| 7768 | */ |
| 7769 | @Override |
| 7770 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7771 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7772 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | |
| 7774 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7775 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | if (phone == null) { |
| 7777 | return null; |
| 7778 | } |
| 7779 | String cdmaPrlVersion = null; |
| 7780 | try { |
| 7781 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7782 | } catch (Exception e) { |
| 7783 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7784 | } |
| 7785 | return cdmaPrlVersion; |
| 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7788 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
| 7791 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7792 | * Get snapshot of Telephony histograms |
| 7793 | * @return List of Telephony histograms |
| 7794 | * @hide |
| 7795 | */ |
| 7796 | @Override |
| 7797 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7799 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | |
| 7801 | final long identity = Binder.clearCallingIdentity(); |
| 7802 | try { |
| 7803 | return RIL.getTelephonyRILTimingHistograms(); |
| 7804 | } finally { |
| 7805 | Binder.restoreCallingIdentity(identity); |
| 7806 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7807 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7808 | |
| 7809 | /** |
| 7810 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7811 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7812 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7813 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7814 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7815 | * @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] | 7816 | */ |
| 7817 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7818 | @TelephonyManager.SetCarrierRestrictionResult |
| 7819 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7820 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7821 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7822 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7823 | if (carrierRestrictionRules == null) { |
| 7824 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7825 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | final long identity = Binder.clearCallingIdentity(); |
| 7828 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7829 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7830 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7831 | } finally { |
| 7832 | Binder.restoreCallingIdentity(identity); |
| 7833 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7834 | } |
| 7835 | |
| 7836 | /** |
| 7837 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7838 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7839 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7840 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7841 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7842 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7843 | */ |
| 7844 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7845 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7846 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7847 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7848 | |
| 7849 | final long identity = Binder.clearCallingIdentity(); |
| 7850 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7851 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7852 | if (response instanceof CarrierRestrictionRules) { |
| 7853 | return (CarrierRestrictionRules) response; |
| 7854 | } |
| 7855 | // Response is an Exception of some kind, |
| 7856 | // which is signalled to the user as a NULL retval |
| 7857 | return null; |
| 7858 | } catch (Exception e) { |
| 7859 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7860 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
| 7863 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7864 | } |
| 7865 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7866 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7867 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7868 | * @param subId the subscription ID that this action applies to. |
| 7869 | * @param enabled control enable or disable radio. |
| 7870 | * {@hide} |
| 7871 | */ |
| 7872 | @Override |
| 7873 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7874 | enforceModifyPermission(); |
| 7875 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7876 | |
| 7877 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7878 | if (phone == null) { |
| 7879 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7880 | return; |
| 7881 | } |
| 7882 | try { |
| 7883 | phone.carrierActionSetRadioEnabled(enabled); |
| 7884 | } catch (Exception e) { |
| 7885 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7886 | } finally { |
| 7887 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7888 | } |
| 7889 | } |
| 7890 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7891 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7892 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7893 | * network status based on which carrier apps could apply actions accordingly, |
| 7894 | * enable/disable default url handler for example. |
| 7895 | * |
| 7896 | * @param subId the subscription ID that this action applies to. |
| 7897 | * @param report control start/stop reporting the default network status. |
| 7898 | * {@hide} |
| 7899 | */ |
| 7900 | @Override |
| 7901 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7902 | enforceModifyPermission(); |
| 7903 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7904 | |
| 7905 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7906 | if (phone == null) { |
| 7907 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7908 | return; |
| 7909 | } |
| 7910 | try { |
| 7911 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7912 | } catch (Exception e) { |
| 7913 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7914 | } finally { |
| 7915 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7920 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7921 | * @param subId the subscription ID that this action applies to. |
| 7922 | * {@hide} |
| 7923 | */ |
| 7924 | @Override |
| 7925 | public void carrierActionResetAll(int subId) { |
| 7926 | enforceModifyPermission(); |
| 7927 | final Phone phone = getPhone(subId); |
| 7928 | if (phone == null) { |
| 7929 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7930 | return; |
| 7931 | } |
| 7932 | try { |
| 7933 | phone.carrierActionResetAll(); |
| 7934 | } catch (Exception e) { |
| 7935 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7936 | } |
| 7937 | } |
| 7938 | |
| 7939 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7940 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7941 | * bug report is being generated. |
| 7942 | */ |
| 7943 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7944 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7945 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7946 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7947 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7948 | + Binder.getCallingPid() |
| 7949 | + ", uid=" + Binder.getCallingUid() |
| 7950 | + "without permission " |
| 7951 | + android.Manifest.permission.DUMP); |
| 7952 | return; |
| 7953 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7954 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7955 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7956 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7957 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7958 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7959 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7960 | @NonNull String[] args) { |
| 7961 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7962 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7963 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7964 | } |
| 7965 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7966 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7967 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7968 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7969 | * @param reason the reason the data enable change is taking place |
| 7970 | * @param enabled True if enabling the data, otherwise disabling. |
| 7971 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7972 | */ |
| 7973 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7974 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7975 | boolean enabled) { |
| 7976 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7977 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7978 | try { |
| 7979 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7980 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7981 | } catch (SecurityException se) { |
| 7982 | enforceModifyPermission(); |
| 7983 | } |
| 7984 | } else { |
| 7985 | enforceModifyPermission(); |
| 7986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7987 | |
| 7988 | final long identity = Binder.clearCallingIdentity(); |
| 7989 | try { |
| 7990 | Phone phone = getPhone(subId); |
| 7991 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7992 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7993 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7994 | } else { |
| 7995 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7997 | } |
| 7998 | } finally { |
| 7999 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8000 | } |
| 8001 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8002 | |
| 8003 | /** |
| 8004 | * Get Client request stats |
| 8005 | * @return List of Client Request Stats |
| 8006 | * @hide |
| 8007 | */ |
| 8008 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8009 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8010 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8012 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8013 | return null; |
| 8014 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8015 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8017 | final long identity = Binder.clearCallingIdentity(); |
| 8018 | try { |
| 8019 | if (phone != null) { |
| 8020 | return phone.getClientRequestStats(); |
| 8021 | } |
| 8022 | |
| 8023 | return null; |
| 8024 | } finally { |
| 8025 | Binder.restoreCallingIdentity(identity); |
| 8026 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8027 | } |
| 8028 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8029 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8030 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8031 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8032 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8033 | |
| 8034 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8035 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8036 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8037 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8038 | * @param state State of SIM (power down, power up, pass through) |
| 8039 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8040 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8041 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8042 | * |
| 8043 | **/ |
| 8044 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8045 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8046 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8047 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8048 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8049 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8051 | final long identity = Binder.clearCallingIdentity(); |
| 8052 | try { |
| 8053 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8054 | phone.setSimPowerState(state, null, workSource); |
| 8055 | } |
| 8056 | } finally { |
| 8057 | Binder.restoreCallingIdentity(identity); |
| 8058 | } |
| 8059 | } |
| 8060 | |
| 8061 | /** |
| 8062 | * Set SIM card power state. |
| 8063 | * |
| 8064 | * @param slotIndex SIM slot id. |
| 8065 | * @param state State of SIM (power down, power up, pass through) |
| 8066 | * @param callback callback to trigger after success or failure |
| 8067 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8068 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8069 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8070 | * |
| 8071 | **/ |
| 8072 | @Override |
| 8073 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8074 | IIntegerConsumer callback) { |
| 8075 | enforceModifyPermission(); |
| 8076 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8077 | |
| 8078 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8079 | |
| 8080 | final long identity = Binder.clearCallingIdentity(); |
| 8081 | try { |
| 8082 | if (phone != null) { |
| 8083 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8084 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8085 | } |
| 8086 | } finally { |
| 8087 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8088 | } |
| 8089 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8090 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8091 | private boolean isUssdApiAllowed(int subId) { |
| 8092 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8093 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8094 | if (configManager == null) { |
| 8095 | return false; |
| 8096 | } |
| 8097 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8098 | if (pb == null) { |
| 8099 | return false; |
| 8100 | } |
| 8101 | return pb.getBoolean( |
| 8102 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8103 | } |
| 8104 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8105 | /** |
| 8106 | * Check if phone is in emergency callback mode |
| 8107 | * @return true if phone is in emergency callback mode |
| 8108 | * @param subId sub id |
| 8109 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8110 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8111 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8112 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8113 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | |
| 8115 | final long identity = Binder.clearCallingIdentity(); |
| 8116 | try { |
| 8117 | if (phone != null) { |
| 8118 | return phone.isInEcm(); |
| 8119 | } else { |
| 8120 | return false; |
| 8121 | } |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8124 | } |
| 8125 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8126 | |
| 8127 | /** |
| 8128 | * Get the current signal strength information for the given subscription. |
| 8129 | * Because this information is not updated when the device is in a low power state |
| 8130 | * it should not be relied-upon to be current. |
| 8131 | * @param subId Subscription index |
| 8132 | * @return the most recent cached signal strength info from the modem |
| 8133 | */ |
| 8134 | @Override |
| 8135 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8136 | final long identity = Binder.clearCallingIdentity(); |
| 8137 | try { |
| 8138 | Phone p = getPhone(subId); |
| 8139 | if (p == null) { |
| 8140 | return null; |
| 8141 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | return p.getSignalStrength(); |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8147 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8148 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8149 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8150 | * Get the current modem radio state for the given slot. |
| 8151 | * @param slotIndex slot index. |
| 8152 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8153 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8154 | * @return the current radio power state from the modem |
| 8155 | */ |
| 8156 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8157 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8158 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8159 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8160 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8161 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8162 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8163 | } |
| 8164 | |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
| 8167 | return phone.getRadioPowerState(); |
| 8168 | } finally { |
| 8169 | Binder.restoreCallingIdentity(identity); |
| 8170 | } |
| 8171 | } |
| 8172 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8173 | } |
| 8174 | |
| 8175 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8176 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8177 | * |
| 8178 | * <p>Requires one of the following permissions: |
| 8179 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8180 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8181 | * privileges. |
| 8182 | * |
| 8183 | * @param subId subscription id |
| 8184 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8185 | * {@code false}. |
| 8186 | */ |
| 8187 | @Override |
| 8188 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8189 | try { |
| 8190 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8191 | null); |
| 8192 | } catch (Exception e) { |
| 8193 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8194 | mApp, subId, "isDataRoamingEnabled"); |
| 8195 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8196 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8197 | boolean isEnabled = false; |
| 8198 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8199 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8200 | Phone phone = getPhone(subId); |
| 8201 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8204 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8205 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8206 | } |
| 8207 | |
| 8208 | |
| 8209 | /** |
| 8210 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8211 | * |
| 8212 | * <p> Requires permission: |
| 8213 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8214 | * privileges. |
| 8215 | * |
| 8216 | * @param subId subscription id |
| 8217 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8218 | */ |
| 8219 | @Override |
| 8220 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8222 | mApp, subId, "setDataRoamingEnabled"); |
| 8223 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8224 | final long identity = Binder.clearCallingIdentity(); |
| 8225 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8226 | Phone phone = getPhone(subId); |
| 8227 | if (phone != null) { |
| 8228 | phone.setDataRoamingEnabled(isEnabled); |
| 8229 | } |
| 8230 | } finally { |
| 8231 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8232 | } |
| 8233 | } |
| 8234 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8235 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8236 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8237 | TelephonyPermissions |
| 8238 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8239 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8240 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8241 | boolean isAllowed = true; |
| 8242 | final long identity = Binder.clearCallingIdentity(); |
| 8243 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8244 | Phone phone = getPhone(subId); |
| 8245 | if (phone != null) { |
| 8246 | isAllowed = phone.isCspPlmnEnabled(); |
| 8247 | } |
| 8248 | } finally { |
| 8249 | Binder.restoreCallingIdentity(identity); |
| 8250 | } |
| 8251 | return isAllowed; |
| 8252 | } |
| 8253 | |
| 8254 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8255 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8256 | // Verify that tha callingPackage belongs to the calling UID |
| 8257 | mApp.getSystemService(AppOpsManager.class) |
| 8258 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8259 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8260 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8261 | try { |
| 8262 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8263 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8264 | } catch (SecurityException e) { |
| 8265 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8266 | // has carrier privileges on an active UICC |
| 8267 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8268 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8269 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8270 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8271 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8272 | |
| 8273 | final long identity = Binder.clearCallingIdentity(); |
| 8274 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8275 | UiccController uiccController = UiccController.getInstance(); |
| 8276 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8277 | if (hasReadPermission) { |
| 8278 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8279 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8280 | |
| 8281 | // Remove private info if the caller doesn't have access |
| 8282 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8283 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8284 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8285 | // is available |
| 8286 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8287 | if (card == null || card.getUiccProfile() == null) { |
| 8288 | // assume no access if the card or profile is unavailable |
| 8289 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8290 | continue; |
| 8291 | } |
| 8292 | UiccProfile profile = card.getUiccProfile(); |
| 8293 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8294 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8295 | filteredInfos.add(cardInfo); |
| 8296 | } else { |
| 8297 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8298 | } |
| 8299 | } |
| 8300 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
| 8304 | } |
| 8305 | |
| 8306 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8307 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8308 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8309 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8310 | final long identity = Binder.clearCallingIdentity(); |
| 8311 | try { |
| 8312 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8313 | if (slots == null) { |
| 8314 | Rlog.i(LOG_TAG, "slots is null."); |
| 8315 | return null; |
| 8316 | } |
| 8317 | |
| 8318 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8319 | for (int i = 0; i < slots.length; i++) { |
| 8320 | UiccSlot slot = slots[i]; |
| 8321 | if (slot == null) { |
| 8322 | continue; |
| 8323 | } |
| 8324 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8325 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8326 | UiccCard card = slot.getUiccCard(); |
| 8327 | if (card != null) { |
| 8328 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8329 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8330 | cardId = slot.getEid(); |
| 8331 | if (TextUtils.isEmpty(cardId)) { |
| 8332 | cardId = slot.getIccId(); |
| 8333 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | } |
| 8335 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8336 | if (cardId != null) { |
| 8337 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8338 | // if cardId is an EID, it's all digits so this is fine |
| 8339 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8340 | } |
| 8341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8342 | int cardState = 0; |
| 8343 | switch (slot.getCardState()) { |
| 8344 | case CARDSTATE_ABSENT: |
| 8345 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8346 | break; |
| 8347 | case CARDSTATE_PRESENT: |
| 8348 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8349 | break; |
| 8350 | case CARDSTATE_ERROR: |
| 8351 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8352 | break; |
| 8353 | case CARDSTATE_RESTRICTED: |
| 8354 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8355 | break; |
| 8356 | default: |
| 8357 | break; |
| 8358 | |
| 8359 | } |
| 8360 | |
| 8361 | infos[i] = new UiccSlotInfo( |
| 8362 | slot.isActive(), |
| 8363 | slot.isEuicc(), |
| 8364 | cardId, |
| 8365 | cardState, |
| 8366 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8367 | slot.isExtendedApduSupported(), |
| 8368 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8369 | } |
| 8370 | return infos; |
| 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8373 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | @Override |
| 8377 | public boolean switchSlots(int[] physicalSlots) { |
| 8378 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8379 | |
| 8380 | final long identity = Binder.clearCallingIdentity(); |
| 8381 | try { |
| 8382 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8383 | } finally { |
| 8384 | Binder.restoreCallingIdentity(identity); |
| 8385 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8386 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8387 | |
| 8388 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8389 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8390 | final long identity = Binder.clearCallingIdentity(); |
| 8391 | try { |
| 8392 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
| 8396 | } |
| 8397 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8398 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8399 | * A test API to reload the UICC profile. |
| 8400 | * |
| 8401 | * <p>Requires that the calling app has permission |
| 8402 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8403 | * @hide |
| 8404 | */ |
| 8405 | @Override |
| 8406 | public void refreshUiccProfile(int subId) { |
| 8407 | enforceModifyPermission(); |
| 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
| 8411 | Phone phone = getPhone(subId); |
| 8412 | if (phone == null) { |
| 8413 | return; |
| 8414 | } |
| 8415 | UiccCard uiccCard = phone.getUiccCard(); |
| 8416 | if (uiccCard == null) { |
| 8417 | return; |
| 8418 | } |
| 8419 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8420 | if (uiccProfile == null) { |
| 8421 | return; |
| 8422 | } |
| 8423 | uiccProfile.refresh(); |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
| 8426 | } |
| 8427 | } |
| 8428 | |
| 8429 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8430 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8431 | */ |
| 8432 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8433 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8434 | } |
| 8435 | |
| 8436 | /** |
| 8437 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8438 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8439 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8440 | */ |
| 8441 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8442 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8443 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8444 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8445 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8446 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8447 | return isDataRoamingEnabled; |
| 8448 | } |
| 8449 | |
| 8450 | /** |
| 8451 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8452 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8453 | */ |
| 8454 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8455 | List<Integer> list = TelephonyProperties.default_network(); |
| 8456 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8457 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8458 | return list.get(phoneId); |
| 8459 | } |
| 8460 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8461 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8462 | |
| 8463 | @Override |
| 8464 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8465 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8466 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8467 | |
| 8468 | final long identity = Binder.clearCallingIdentity(); |
| 8469 | try { |
| 8470 | final Phone phone = getPhone(subId); |
| 8471 | if (phone == null) { |
| 8472 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8473 | return; |
| 8474 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8475 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8476 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8477 | if (carrierPrivilegeRules == null) { |
| 8478 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8479 | } else { |
| 8480 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8482 | } finally { |
| 8483 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8484 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | @Override |
| 8488 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8489 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8490 | |
| 8491 | final long identity = Binder.clearCallingIdentity(); |
| 8492 | try { |
| 8493 | final Phone phone = getPhone(subId); |
| 8494 | if (phone == null) { |
| 8495 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8496 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8497 | } |
| 8498 | return phone.getCarrierIdListVersion(); |
| 8499 | } finally { |
| 8500 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8501 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8502 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8503 | |
| 8504 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8505 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8506 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8507 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8508 | mApp, subId, callingPackage, callingFeatureId, |
| 8509 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8510 | return -1; |
| 8511 | } |
| 8512 | |
| 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
| 8518 | } |
| 8519 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8520 | |
| 8521 | @Override |
| 8522 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8523 | TelephonyPermissions |
| 8524 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8525 | mApp, subId, "getCdmaRoamingMode"); |
| 8526 | |
| 8527 | final long identity = Binder.clearCallingIdentity(); |
| 8528 | try { |
| 8529 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
| 8533 | } |
| 8534 | |
| 8535 | @Override |
| 8536 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8538 | mApp, subId, "setCdmaRoamingMode"); |
| 8539 | |
| 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
| 8542 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8543 | } finally { |
| 8544 | Binder.restoreCallingIdentity(identity); |
| 8545 | } |
| 8546 | } |
| 8547 | |
| 8548 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8549 | public int getCdmaSubscriptionMode(int subId) { |
| 8550 | TelephonyPermissions |
| 8551 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8552 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8553 | |
| 8554 | final long identity = Binder.clearCallingIdentity(); |
| 8555 | try { |
| 8556 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
| 8562 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8563 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8565 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8566 | |
| 8567 | final long identity = Binder.clearCallingIdentity(); |
| 8568 | try { |
| 8569 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8570 | } finally { |
| 8571 | Binder.restoreCallingIdentity(identity); |
| 8572 | } |
| 8573 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8574 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8575 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8576 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8577 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8578 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8579 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8580 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8581 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8582 | } |
| 8583 | final long identity = Binder.clearCallingIdentity(); |
| 8584 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8585 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8586 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8587 | if (phone.getEmergencyNumberTracker() != null |
| 8588 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8589 | emergencyNumberListInternal.put( |
| 8590 | phone.getSubId(), |
| 8591 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8592 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8593 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8594 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8595 | } finally { |
| 8596 | Binder.restoreCallingIdentity(identity); |
| 8597 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8598 | } |
| 8599 | |
| 8600 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8601 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8602 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8603 | if (!exactMatch) { |
| 8604 | TelephonyPermissions |
| 8605 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8606 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8607 | } |
| 8608 | final long identity = Binder.clearCallingIdentity(); |
| 8609 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8610 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8611 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8612 | && phone.getEmergencyNumberTracker() |
| 8613 | .isEmergencyNumber(number, exactMatch)) { |
| 8614 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8615 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8616 | } |
| 8617 | return false; |
| 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
| 8620 | } |
| 8621 | } |
| 8622 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8623 | /** |
| 8624 | * Update emergency number list for test mode. |
| 8625 | */ |
| 8626 | @Override |
| 8627 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8628 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8629 | "updateEmergencyNumberListTestMode"); |
| 8630 | |
| 8631 | final long identity = Binder.clearCallingIdentity(); |
| 8632 | try { |
| 8633 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8634 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8635 | if (tracker != null) { |
| 8636 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8637 | } |
| 8638 | } |
| 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
| 8641 | } |
| 8642 | } |
| 8643 | |
| 8644 | /** |
| 8645 | * Get the full emergency number list for test mode. |
| 8646 | */ |
| 8647 | @Override |
| 8648 | public List<String> getEmergencyNumberListTestMode() { |
| 8649 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8650 | "getEmergencyNumberListTestMode"); |
| 8651 | |
| 8652 | final long identity = Binder.clearCallingIdentity(); |
| 8653 | try { |
| 8654 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8655 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8656 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8657 | if (tracker != null) { |
| 8658 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8659 | emergencyNumbers.add(num.getNumber()); |
| 8660 | } |
| 8661 | } |
| 8662 | } |
| 8663 | return new ArrayList<>(emergencyNumbers); |
| 8664 | } finally { |
| 8665 | Binder.restoreCallingIdentity(identity); |
| 8666 | } |
| 8667 | } |
| 8668 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8669 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8670 | public int getEmergencyNumberDbVersion(int subId) { |
| 8671 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8672 | |
| 8673 | final long identity = Binder.clearCallingIdentity(); |
| 8674 | try { |
| 8675 | final Phone phone = getPhone(subId); |
| 8676 | if (phone == null) { |
| 8677 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8678 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8679 | } |
| 8680 | return phone.getEmergencyNumberDbVersion(); |
| 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
| 8684 | } |
| 8685 | |
| 8686 | @Override |
| 8687 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8688 | enforceModifyPermission(); |
| 8689 | |
| 8690 | final long identity = Binder.clearCallingIdentity(); |
| 8691 | try { |
| 8692 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8693 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8694 | if (tracker != null) { |
| 8695 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8696 | } |
| 8697 | } |
| 8698 | } finally { |
| 8699 | Binder.restoreCallingIdentity(identity); |
| 8700 | } |
| 8701 | } |
| 8702 | |
| 8703 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8704 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8705 | enforceActiveEmergencySessionPermission(); |
| 8706 | |
| 8707 | final long identity = Binder.clearCallingIdentity(); |
| 8708 | try { |
| 8709 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8710 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8711 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8712 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8713 | } |
| 8714 | } |
| 8715 | } finally { |
| 8716 | Binder.restoreCallingIdentity(identity); |
| 8717 | } |
| 8718 | } |
| 8719 | |
| 8720 | @Override |
| 8721 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8722 | enforceActiveEmergencySessionPermission(); |
| 8723 | |
| 8724 | final long identity = Binder.clearCallingIdentity(); |
| 8725 | try { |
| 8726 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8727 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8728 | if (tracker != null) { |
| 8729 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8730 | } |
| 8731 | } |
| 8732 | } finally { |
| 8733 | Binder.restoreCallingIdentity(identity); |
| 8734 | } |
| 8735 | } |
| 8736 | |
| 8737 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8738 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8739 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8740 | Phone phone = getPhone(subId); |
| 8741 | if (phone == null) { |
| 8742 | return null; |
| 8743 | } |
| 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
| 8746 | UiccProfile profile = UiccController.getInstance() |
| 8747 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8748 | if (profile != null) { |
| 8749 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8750 | } |
| 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
| 8753 | } |
| 8754 | return null; |
| 8755 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8756 | |
| 8757 | /** |
| 8758 | * Enable or disable a modem stack. |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8762 | enforceModifyPermission(); |
| 8763 | |
| 8764 | final long identity = Binder.clearCallingIdentity(); |
| 8765 | try { |
| 8766 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8767 | if (phone == null) { |
| 8768 | return false; |
| 8769 | } else { |
| 8770 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8771 | } |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
| 8775 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8776 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8777 | /** |
| 8778 | * Whether a modem stack is enabled or not. |
| 8779 | */ |
| 8780 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8781 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8782 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8783 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8784 | if (phone == null) return false; |
| 8785 | |
| 8786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8787 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8788 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8789 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8790 | } |
| 8791 | |
| 8792 | final long identity = Binder.clearCallingIdentity(); |
| 8793 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8794 | try { |
| 8795 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8796 | } catch (NoSuchElementException ex) { |
| 8797 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8798 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8799 | } finally { |
| 8800 | Binder.restoreCallingIdentity(identity); |
| 8801 | } |
| 8802 | } |
| 8803 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8804 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8805 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8806 | enforceModifyPermission(); |
| 8807 | |
| 8808 | final long identity = Binder.clearCallingIdentity(); |
| 8809 | try { |
| 8810 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8811 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8812 | .commit(); |
| 8813 | } finally { |
| 8814 | Binder.restoreCallingIdentity(identity); |
| 8815 | } |
| 8816 | } |
| 8817 | |
| 8818 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8819 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8820 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8821 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8822 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8823 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8824 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8825 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8826 | |
| 8827 | final long identity = Binder.clearCallingIdentity(); |
| 8828 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8829 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8830 | } finally { |
| 8831 | Binder.restoreCallingIdentity(identity); |
| 8832 | } |
| 8833 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8834 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8835 | @TelephonyManager.IsMultiSimSupportedResult |
| 8836 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8837 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8838 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8839 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8840 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8841 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8842 | } |
| 8843 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8844 | // supported by the modem, indicate that it is restricted. |
| 8845 | PhoneCapability staticCapability = |
| 8846 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8847 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8848 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8849 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8850 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8851 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8852 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8853 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8854 | } |
| 8855 | // Check if support of multiple SIMs is restricted by carrier |
| 8856 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8857 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8858 | } |
| 8859 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8860 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8861 | } |
| 8862 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8863 | /** |
| 8864 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8865 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8866 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8867 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8868 | * @param numOfSims number of active sims we want to switch to |
| 8869 | */ |
| 8870 | @Override |
| 8871 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8872 | if (numOfSims == 1) { |
| 8873 | enforceModifyPermission(); |
| 8874 | } else { |
| 8875 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8876 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8877 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8878 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8879 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8880 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8881 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8882 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8883 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8884 | return; |
| 8885 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8886 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8887 | } finally { |
| 8888 | Binder.restoreCallingIdentity(identity); |
| 8889 | } |
| 8890 | } |
| 8891 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8892 | @Override |
| 8893 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8894 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8895 | Phone phone = getPhone(subId); |
| 8896 | if (phone == null) { |
| 8897 | return false; |
| 8898 | } |
| 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | UiccCard uiccCard = phone.getUiccCard(); |
| 8902 | if (uiccCard == null) { |
| 8903 | return false; |
| 8904 | } |
| 8905 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8906 | if (uiccProfile == null) { |
| 8907 | return false; |
| 8908 | } |
| 8909 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8910 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8911 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8912 | } |
| 8913 | return false; |
| 8914 | } finally { |
| 8915 | Binder.restoreCallingIdentity(identity); |
| 8916 | } |
| 8917 | } |
| 8918 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8919 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8920 | * Get whether making changes to modem configurations will trigger reboot. |
| 8921 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8922 | */ |
| 8923 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8924 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8925 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8927 | mApp, subId, callingPackage, callingFeatureId, |
| 8928 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8929 | return false; |
| 8930 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8931 | final long identity = Binder.clearCallingIdentity(); |
| 8932 | try { |
| 8933 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8934 | } finally { |
| 8935 | Binder.restoreCallingIdentity(identity); |
| 8936 | } |
| 8937 | } |
| 8938 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8939 | private void updateModemStateMetrics() { |
| 8940 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8941 | // TODO: check the state for each modem if the api is ready. |
| 8942 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8943 | } |
| 8944 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8945 | @Override |
| 8946 | public int[] getSlotsMapping() { |
| 8947 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8948 | |
| 8949 | final long identity = Binder.clearCallingIdentity(); |
| 8950 | try { |
| 8951 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8952 | // All logical slots should have a mapping to a physical slot. |
| 8953 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8954 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8955 | for (int i = 0; i < slotInfos.length; i++) { |
| 8956 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8957 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8958 | } |
| 8959 | } |
| 8960 | return logicalSlotsMapping; |
| 8961 | } finally { |
| 8962 | Binder.restoreCallingIdentity(identity); |
| 8963 | } |
| 8964 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8965 | |
| 8966 | /** |
| 8967 | * Get the IRadio HAL Version |
| 8968 | */ |
| 8969 | @Override |
| 8970 | public int getRadioHalVersion() { |
| 8971 | Phone phone = getDefaultPhone(); |
| 8972 | if (phone == null) return -1; |
| 8973 | HalVersion hv = phone.getHalVersion(); |
| 8974 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8975 | return hv.major * 100 + hv.minor; |
| 8976 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8977 | |
| 8978 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8979 | * Get the current calling package name. |
| 8980 | * @return the current calling package name |
| 8981 | */ |
| 8982 | @Override |
| 8983 | public String getCurrentPackageName() { |
| 8984 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8985 | } |
| 8986 | |
| 8987 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8988 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8989 | * corresponding network requests on a subId. |
| 8990 | * |
| 8991 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8992 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8993 | * 2) APN is un-metered for this subscription, or |
| 8994 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8995 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8996 | * |
| 8997 | * @return whether data is allowed for a apn type. |
| 8998 | * |
| 8999 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9000 | */ |
| 9001 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9002 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9003 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9004 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9005 | |
| 9006 | // Now that all security checks passes, perform the operation as ourselves. |
| 9007 | final long identity = Binder.clearCallingIdentity(); |
| 9008 | try { |
| 9009 | Phone phone = getPhone(subId); |
| 9010 | if (phone == null) return false; |
| 9011 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9012 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9013 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
| 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9020 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9021 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9022 | |
| 9023 | // Now that all security checks passes, perform the operation as ourselves. |
| 9024 | final long identity = Binder.clearCallingIdentity(); |
| 9025 | try { |
| 9026 | Phone phone = getPhone(subId); |
| 9027 | if (phone == null) return true; // By default return true. |
| 9028 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9029 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9030 | } finally { |
| 9031 | Binder.restoreCallingIdentity(identity); |
| 9032 | } |
| 9033 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9034 | |
| 9035 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9036 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9037 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9038 | enforceModifyPermission(); |
| 9039 | long token = Binder.clearCallingIdentity(); |
| 9040 | try { |
| 9041 | Phone phone = getPhone(subscriptionId); |
| 9042 | if (phone == null) { |
| 9043 | try { |
| 9044 | if (resultCallback != null) { |
| 9045 | resultCallback.accept(false); |
| 9046 | } |
| 9047 | } catch (RemoteException e) { |
| 9048 | // ignore |
| 9049 | } |
| 9050 | return; |
| 9051 | } |
| 9052 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9053 | Pair.create(specifiers, (x) -> { |
| 9054 | try { |
| 9055 | if (resultCallback != null) { |
| 9056 | resultCallback.accept(x); |
| 9057 | } |
| 9058 | } catch (RemoteException e) { |
| 9059 | // ignore |
| 9060 | } |
| 9061 | }); |
| 9062 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9063 | } finally { |
| 9064 | Binder.restoreCallingIdentity(token); |
| 9065 | } |
| 9066 | } |
| 9067 | |
| 9068 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9069 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9070 | TelephonyPermissions |
| 9071 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9072 | mApp, subId, "getSystemSelectionChannels"); |
| 9073 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
| 9076 | List<RadioAccessSpecifier> specifiers = |
| 9077 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9078 | null, subId, workSource); |
| 9079 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9080 | return specifiers; |
| 9081 | } finally { |
| 9082 | Binder.restoreCallingIdentity(identity); |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9087 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9088 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9089 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9090 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9091 | if (iccRecords == null) { |
| 9092 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9093 | return false; |
| 9094 | } |
| 9095 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9096 | } |
| 9097 | |
| 9098 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9099 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9100 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9101 | if (callingPackage == null) { |
| 9102 | callingPackage = getCurrentPackageName(); |
| 9103 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9104 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9105 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9106 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9107 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9108 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9109 | } |
| 9110 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9111 | Intent intent = new Intent(); |
| 9112 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9113 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9114 | // Bring up choose default SMS subscription dialog right now |
| 9115 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9116 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9117 | mApp.startActivity(intent); |
| 9118 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9119 | |
| 9120 | @Override |
| 9121 | public String getMmsUAProfUrl(int subId) { |
| 9122 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9123 | final long identity = Binder.clearCallingIdentity(); |
| 9124 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9125 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9126 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9127 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9128 | return carrierUAProfUrl; |
| 9129 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9130 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9131 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
| 9134 | } |
| 9135 | } |
| 9136 | |
| 9137 | @Override |
| 9138 | public String getMmsUserAgent(int subId) { |
| 9139 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9140 | final long identity = Binder.clearCallingIdentity(); |
| 9141 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9142 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9143 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9144 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9145 | return carrierUserAgent; |
| 9146 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9147 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9148 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9149 | } finally { |
| 9150 | Binder.restoreCallingIdentity(identity); |
| 9151 | } |
| 9152 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9153 | |
| 9154 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9155 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9156 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9157 | |
| 9158 | final long identity = Binder.clearCallingIdentity(); |
| 9159 | try { |
| 9160 | Phone phone = getPhone(subscriptionId); |
| 9161 | if (phone == null) return false; |
| 9162 | |
| 9163 | switch (policy) { |
| 9164 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9165 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9166 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9167 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9168 | default: |
| 9169 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9170 | } |
| 9171 | } finally { |
| 9172 | Binder.restoreCallingIdentity(identity); |
| 9173 | } |
| 9174 | } |
| 9175 | |
| 9176 | @Override |
| 9177 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9178 | boolean enabled) { |
| 9179 | enforceModifyPermission(); |
| 9180 | |
| 9181 | final long identity = Binder.clearCallingIdentity(); |
| 9182 | try { |
| 9183 | Phone phone = getPhone(subscriptionId); |
| 9184 | if (phone == null) return; |
| 9185 | |
| 9186 | switch (policy) { |
| 9187 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9188 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9189 | break; |
| 9190 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9191 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9192 | break; |
| 9193 | default: |
| 9194 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9195 | } |
| 9196 | } finally { |
| 9197 | Binder.restoreCallingIdentity(identity); |
| 9198 | } |
| 9199 | } |
| 9200 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9201 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9202 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9203 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9204 | * otherwise. |
| 9205 | */ |
| 9206 | @Override |
| 9207 | public void setCepEnabled(boolean isCepEnabled) { |
| 9208 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9209 | |
| 9210 | final long identity = Binder.clearCallingIdentity(); |
| 9211 | try { |
| 9212 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9213 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9214 | Phone defaultPhone = phone.getImsPhone(); |
| 9215 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9216 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9217 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9218 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9219 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9220 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9221 | + imsPhone.getMsisdn()); |
| 9222 | } |
| 9223 | } |
| 9224 | } finally { |
| 9225 | Binder.restoreCallingIdentity(identity); |
| 9226 | } |
| 9227 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9228 | |
| 9229 | /** |
| 9230 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9231 | * |
| 9232 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9233 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9234 | * before being read. |
| 9235 | */ |
| 9236 | @Override |
| 9237 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9238 | isCompressed) { |
| 9239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9240 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9241 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9242 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9243 | } |
| 9244 | if (!isImsAvailableOnDevice()) { |
| 9245 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9246 | "IMS not available on device."); |
| 9247 | } |
| 9248 | |
| 9249 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9250 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9251 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9252 | } finally { |
| 9253 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9254 | } |
| 9255 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9256 | |
| 9257 | @Override |
| 9258 | public boolean isIccLockEnabled(int subId) { |
| 9259 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9260 | |
| 9261 | // Now that all security checks passes, perform the operation as ourselves. |
| 9262 | final long identity = Binder.clearCallingIdentity(); |
| 9263 | try { |
| 9264 | Phone phone = getPhone(subId); |
| 9265 | if (phone != null && phone.getIccCard() != null) { |
| 9266 | return phone.getIccCard().getIccLockEnabled(); |
| 9267 | } else { |
| 9268 | return false; |
| 9269 | } |
| 9270 | } finally { |
| 9271 | Binder.restoreCallingIdentity(identity); |
| 9272 | } |
| 9273 | } |
| 9274 | |
| 9275 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9276 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9277 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9278 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9279 | * three cases: |
| 9280 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9281 | * successfully. |
| 9282 | * - Positive number and zero for remaining password attempts. |
| 9283 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9284 | * |
| 9285 | */ |
| 9286 | @Override |
| 9287 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9288 | enforceModifyPermission(); |
| 9289 | |
| 9290 | Phone phone = getPhone(subId); |
| 9291 | if (phone == null) { |
| 9292 | return 0; |
| 9293 | } |
| 9294 | // Now that all security checks passes, perform the operation as ourselves. |
| 9295 | final long identity = Binder.clearCallingIdentity(); |
| 9296 | try { |
| 9297 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9298 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9299 | return attemptsRemaining; |
| 9300 | |
| 9301 | } catch (Exception e) { |
| 9302 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9303 | } finally { |
| 9304 | Binder.restoreCallingIdentity(identity); |
| 9305 | } |
| 9306 | return 0; |
| 9307 | } |
| 9308 | |
| 9309 | /** |
| 9310 | * Change the ICC password used in ICC pin lock. |
| 9311 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9312 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9313 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9314 | * - Positive number and zero for remaining password attempts. |
| 9315 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9316 | * |
| 9317 | */ |
| 9318 | @Override |
| 9319 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9320 | enforceModifyPermission(); |
| 9321 | |
| 9322 | Phone phone = getPhone(subId); |
| 9323 | if (phone == null) { |
| 9324 | return 0; |
| 9325 | } |
| 9326 | // Now that all security checks passes, perform the operation as ourselves. |
| 9327 | final long identity = Binder.clearCallingIdentity(); |
| 9328 | try { |
| 9329 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9330 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9331 | return attemptsRemaining; |
| 9332 | |
| 9333 | } catch (Exception e) { |
| 9334 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9335 | } finally { |
| 9336 | Binder.restoreCallingIdentity(identity); |
| 9337 | } |
| 9338 | return 0; |
| 9339 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9340 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9341 | /** |
| 9342 | * Request for receiving user activity notification |
| 9343 | */ |
| 9344 | @Override |
| 9345 | public void requestUserActivityNotification() { |
| 9346 | if (!mNotifyUserActivity.get() |
| 9347 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9348 | mNotifyUserActivity.set(true); |
| 9349 | } |
| 9350 | } |
| 9351 | |
| 9352 | /** |
| 9353 | * Called when userActivity is signalled in the power manager. |
| 9354 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9355 | */ |
| 9356 | @Override |
| 9357 | public void userActivity() { |
| 9358 | // *************************************** |
| 9359 | // * Inherited from PhoneWindowManager * |
| 9360 | // *************************************** |
| 9361 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9362 | // WITH ITS LOCKS HELD. |
| 9363 | // |
| 9364 | // This code must be VERY careful about the locks |
| 9365 | // it acquires. |
| 9366 | // In fact, the current code acquires way too many, |
| 9367 | // and probably has lurking deadlocks. |
| 9368 | |
| 9369 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9370 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9371 | } |
| 9372 | |
| 9373 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9374 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9375 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9376 | } |
| 9377 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9378 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9379 | @Override |
| 9380 | public boolean canConnectTo5GInDsdsMode() { |
| 9381 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9382 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9383 | |
| 9384 | @Override |
| 9385 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9386 | String callingFeatureId) { |
| 9387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9388 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9389 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9390 | } |
| 9391 | |
| 9392 | Phone phone = getPhone(subId); |
| 9393 | if (phone == null) { |
| 9394 | throw new RuntimeException("phone is not available"); |
| 9395 | } |
| 9396 | // Now that all security checks passes, perform the operation as ourselves. |
| 9397 | final long identity = Binder.clearCallingIdentity(); |
| 9398 | try { |
| 9399 | return phone.getEquivalentHomePlmns(); |
| 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
| 9402 | } |
| 9403 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9404 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9405 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9406 | public boolean isRadioInterfaceCapabilitySupported( |
| 9407 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9408 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9409 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9410 | if (radioInterfaceCapabilities == null) { |
| 9411 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9412 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9413 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9414 | } |
| 9415 | } |
| 9416 | |
| 9417 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9418 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9419 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9420 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9421 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9422 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9423 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9424 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9425 | if (DBG) { |
| 9426 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9427 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9428 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9429 | } |
| 9430 | |
| 9431 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9432 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9433 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9434 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9435 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9436 | if (callback != null) { |
| 9437 | try { |
| 9438 | callback.onAuthenticationFailure( |
| 9439 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9440 | } catch (RemoteException exception) { |
| 9441 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9442 | } |
| 9443 | return; |
| 9444 | } |
| 9445 | } |
| 9446 | |
| 9447 | final long token = Binder.clearCallingIdentity(); |
| 9448 | try { |
| 9449 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9450 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9451 | forceBootStrapping, callback)); |
| 9452 | } finally { |
| 9453 | Binder.restoreCallingIdentity(token); |
| 9454 | } |
| 9455 | } |
| 9456 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9457 | /** |
| 9458 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9459 | * requested radio power state will actually be set. See {@link |
| 9460 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9461 | * |
| 9462 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9463 | * @param enable {@code true} if trying to turn radio on. |
| 9464 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9465 | * false}. |
| 9466 | */ |
| 9467 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9468 | Phone phone = getPhone(subId); |
| 9469 | if (phone != null) { |
| 9470 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9471 | return true; |
| 9472 | } |
| 9473 | return false; |
| 9474 | } |
| 9475 | |
| 9476 | private int handleDataThrottlingRequest(int subId, |
| 9477 | DataThrottlingRequest dataThrottlingRequest) { |
| 9478 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9479 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9480 | if (!setRadioPowerForThermal(subId, true)) { |
| 9481 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9482 | } |
| 9483 | |
| 9484 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9485 | |
| 9486 | int thermalMitigationResult = |
| 9487 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9488 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9489 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9490 | } |
| 9491 | return thermalMitigationResult; |
| 9492 | } |
| 9493 | |
| 9494 | /** |
| 9495 | * Thermal mitigation request to control functionalities at modem. |
| 9496 | * |
| 9497 | * @param subId the id of the subscription. |
| 9498 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9499 | * |
| 9500 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9501 | */ |
| 9502 | @Override |
| 9503 | @ThermalMitigationResult |
| 9504 | public int sendThermalMitigationRequest( |
| 9505 | int subId, |
| 9506 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9507 | enforceModifyPermission(); |
| 9508 | |
| 9509 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9510 | final long identity = Binder.clearCallingIdentity(); |
| 9511 | |
| 9512 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9513 | try { |
| 9514 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9515 | switch (thermalMitigationAction) { |
| 9516 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9517 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9518 | handleDataThrottlingRequest(subId, |
| 9519 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9520 | break; |
| 9521 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9522 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9523 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9524 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9525 | } |
| 9526 | |
| 9527 | // Ensure that radio is on. If not able to power on due to phone being |
| 9528 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9529 | if (!setRadioPowerForThermal(subId, true)) { |
| 9530 | thermalMitigationResult = |
| 9531 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9532 | break; |
| 9533 | } |
| 9534 | |
| 9535 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9536 | false); |
| 9537 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9538 | break; |
| 9539 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9540 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9541 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9542 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9543 | } |
| 9544 | |
| 9545 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9546 | if (registry != null) { |
| 9547 | TelephonyConnectionService service = |
| 9548 | registry.getTelephonyConnectionService(); |
| 9549 | Phone phone = getPhone(subId); |
| 9550 | if (phone == null) { |
| 9551 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9552 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9553 | break; |
| 9554 | } |
| 9555 | |
| 9556 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9557 | != TelephonyManager.CALL_STATE_IDLE |
| 9558 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9559 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9560 | String errorMessage = "Phone state is not valid. call state = " |
| 9561 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9562 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9563 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9564 | errorMessage += service == null |
| 9565 | ? " TelephonyConnectionService is null" |
| 9566 | : " isEmergencyCallPending = " |
| 9567 | + service.isEmergencyCallPending(); |
| 9568 | Log.e(LOG_TAG, errorMessage); |
| 9569 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9570 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9571 | break; |
| 9572 | } |
| 9573 | } else { |
| 9574 | thermalMitigationResult = |
| 9575 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9576 | break; |
| 9577 | } |
| 9578 | |
| 9579 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9580 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9581 | if (!setRadioPowerForThermal(subId, false)) { |
| 9582 | thermalMitigationResult = |
| 9583 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9584 | break; |
| 9585 | } |
| 9586 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9587 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9588 | break; |
| 9589 | default: |
| 9590 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9591 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9592 | } |
| 9593 | } catch (IllegalArgumentException e) { |
| 9594 | throw e; |
| 9595 | } catch (Exception e) { |
| 9596 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9597 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9598 | } finally { |
| 9599 | Binder.restoreCallingIdentity(identity); |
| 9600 | } |
| 9601 | |
| 9602 | if (DBG) { |
| 9603 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9604 | + thermalMitigationResult); |
| 9605 | } |
| 9606 | |
| 9607 | return thermalMitigationResult; |
| 9608 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9609 | |
| 9610 | /** |
| 9611 | * Set the GbaService Package Name that Telephony will bind to. |
| 9612 | * |
| 9613 | * @param subId The sim that the GbaService is associated with. |
| 9614 | * @param packageName The name of the package to be replaced with. |
| 9615 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9616 | */ |
| 9617 | @Override |
| 9618 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9619 | enforceModifyPermission(); |
| 9620 | |
| 9621 | final long identity = Binder.clearCallingIdentity(); |
| 9622 | try { |
| 9623 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9624 | } finally { |
| 9625 | Binder.restoreCallingIdentity(identity); |
| 9626 | } |
| 9627 | } |
| 9628 | |
| 9629 | /** |
| 9630 | * Return the package name of the currently bound GbaService. |
| 9631 | * |
| 9632 | * @param subId The sim that the GbaService is associated with. |
| 9633 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9634 | */ |
| 9635 | @Override |
| 9636 | public String getBoundGbaService(int subId) { |
| 9637 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9638 | |
| 9639 | final long identity = Binder.clearCallingIdentity(); |
| 9640 | try { |
| 9641 | return getGbaManager(subId).getServicePackage(); |
| 9642 | } finally { |
| 9643 | Binder.restoreCallingIdentity(identity); |
| 9644 | } |
| 9645 | } |
| 9646 | |
| 9647 | /** |
| 9648 | * Set the release time for telephony to unbind GbaService. |
| 9649 | * |
| 9650 | * @param subId The sim that the GbaService is associated with. |
| 9651 | * @param interval The release time to unbind GbaService by millisecond. |
| 9652 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9653 | */ |
| 9654 | @Override |
| 9655 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9656 | enforceModifyPermission(); |
| 9657 | |
| 9658 | final long identity = Binder.clearCallingIdentity(); |
| 9659 | try { |
| 9660 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9661 | } finally { |
| 9662 | Binder.restoreCallingIdentity(identity); |
| 9663 | } |
| 9664 | } |
| 9665 | |
| 9666 | /** |
| 9667 | * Return the release time for telephony to unbind GbaService. |
| 9668 | * |
| 9669 | * @param subId The sim that the GbaService is associated with. |
| 9670 | * @return The release time to unbind GbaService by millisecond. |
| 9671 | */ |
| 9672 | @Override |
| 9673 | public int getGbaReleaseTime(int subId) { |
| 9674 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9675 | |
| 9676 | final long identity = Binder.clearCallingIdentity(); |
| 9677 | try { |
| 9678 | return getGbaManager(subId).getReleaseTime(); |
| 9679 | } finally { |
| 9680 | Binder.restoreCallingIdentity(identity); |
| 9681 | } |
| 9682 | } |
| 9683 | |
| 9684 | private GbaManager getGbaManager(int subId) { |
| 9685 | GbaManager instance = GbaManager.getInstance(subId); |
| 9686 | if (instance == null) { |
| 9687 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9688 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9689 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9690 | } |
| 9691 | return instance; |
| 9692 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9693 | |
| 9694 | /** |
| 9695 | * indicate whether the device and the carrier can support |
| 9696 | * RCS VoLTE single registration. |
| 9697 | */ |
| 9698 | @Override |
| 9699 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9700 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9701 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9702 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9703 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9704 | |
| 9705 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9706 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9707 | } |
| 9708 | |
| 9709 | final long identity = Binder.clearCallingIdentity(); |
| 9710 | try { |
| 9711 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9712 | if (rpm != null) { |
| 9713 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9714 | } |
| 9715 | return false; |
| 9716 | } finally { |
| 9717 | Binder.restoreCallingIdentity(identity); |
| 9718 | } |
| 9719 | } |
| 9720 | |
| 9721 | /** |
| 9722 | * Register RCS provisioning callback. |
| 9723 | */ |
| 9724 | @Override |
| 9725 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9726 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9727 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9728 | Binder.getCallingUid(), "registerRcsProvisioningChangedCallback", |
| 9729 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9730 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9731 | |
| 9732 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9733 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9734 | } |
| 9735 | if (!isImsAvailableOnDevice()) { |
| 9736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9737 | "IMS not available on device."); |
| 9738 | } |
| 9739 | |
| 9740 | final long identity = Binder.clearCallingIdentity(); |
| 9741 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9742 | if (!RcsProvisioningMonitor.getInstance() |
| 9743 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9744 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9745 | "Service not available for the subscription."); |
| 9746 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9747 | } finally { |
| 9748 | Binder.restoreCallingIdentity(identity); |
| 9749 | } |
| 9750 | } |
| 9751 | |
| 9752 | /** |
| 9753 | * Unregister RCS provisioning callback. |
| 9754 | */ |
| 9755 | @Override |
| 9756 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9757 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9758 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9759 | Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback", |
| 9760 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9761 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9762 | |
| 9763 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9764 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9765 | } |
| 9766 | if (!isImsAvailableOnDevice()) { |
| 9767 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9768 | "IMS not available on device."); |
| 9769 | } |
| 9770 | |
| 9771 | final long identity = Binder.clearCallingIdentity(); |
| 9772 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9773 | RcsProvisioningMonitor.getInstance() |
| 9774 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9775 | } finally { |
| 9776 | Binder.restoreCallingIdentity(identity); |
| 9777 | } |
| 9778 | } |
| 9779 | |
| 9780 | /** |
| 9781 | * trigger RCS reconfiguration. |
| 9782 | */ |
| 9783 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9784 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9785 | "triggerRcsReconfiguration", |
| 9786 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9787 | |
| 9788 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9789 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9790 | } |
| 9791 | if (!isImsAvailableOnDevice()) { |
| 9792 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9793 | "IMS not available on device."); |
| 9794 | } |
| 9795 | |
| 9796 | final long identity = Binder.clearCallingIdentity(); |
| 9797 | try { |
| 9798 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9799 | } finally { |
| 9800 | Binder.restoreCallingIdentity(identity); |
| 9801 | } |
| 9802 | } |
| 9803 | |
| 9804 | /** |
| 9805 | * Provide the client configuration parameters of the RCS application. |
| 9806 | */ |
| 9807 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame^] | 9808 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9809 | "setRcsClientConfiguration", |
| 9810 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9811 | |
| 9812 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9813 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9814 | } |
| 9815 | if (!isImsAvailableOnDevice()) { |
| 9816 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9817 | "IMS not available on device."); |
| 9818 | } |
| 9819 | |
| 9820 | final long identity = Binder.clearCallingIdentity(); |
| 9821 | |
| 9822 | try { |
| 9823 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9824 | if (configBinder == null) { |
| 9825 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9826 | } else { |
| 9827 | configBinder.setRcsClientConfiguration(rcc); |
| 9828 | } |
| 9829 | } catch (RemoteException e) { |
| 9830 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9831 | } finally { |
| 9832 | Binder.restoreCallingIdentity(identity); |
| 9833 | } |
| 9834 | } |
| 9835 | |
| 9836 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9837 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9838 | */ |
| 9839 | @Override |
| 9840 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9841 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9842 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9843 | |
| 9844 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9845 | } |
| 9846 | |
| 9847 | /** |
| 9848 | * Gets the test mode for RCS VoLTE single registration. |
| 9849 | */ |
| 9850 | @Override |
| 9851 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9853 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9854 | |
| 9855 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9856 | } |
| 9857 | |
| 9858 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9859 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9860 | */ |
| 9861 | @Override |
| 9862 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9863 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9864 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9865 | enforceModifyPermission(); |
| 9866 | |
| 9867 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9868 | : Boolean.parseBoolean(enabledStr); |
| 9869 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9870 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9871 | } |
| 9872 | |
| 9873 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9874 | * Sends a device to device communication message. Only usable via shell. |
| 9875 | * @param message message to send. |
| 9876 | * @param value message value. |
| 9877 | */ |
| 9878 | @Override |
| 9879 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9880 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9881 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9882 | enforceModifyPermission(); |
| 9883 | |
| 9884 | final long identity = Binder.clearCallingIdentity(); |
| 9885 | try { |
| 9886 | TelephonyConnectionService service = |
| 9887 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9888 | if (service == null) { |
| 9889 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9890 | return; |
| 9891 | } |
| 9892 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9893 | } finally { |
| 9894 | Binder.restoreCallingIdentity(identity); |
| 9895 | } |
| 9896 | } |
| 9897 | |
| 9898 | |
| 9899 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9900 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9901 | */ |
| 9902 | @Override |
| 9903 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9904 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9905 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9906 | } |
| 9907 | |
| 9908 | /** |
| 9909 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9910 | */ |
| 9911 | @Override |
| 9912 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9913 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9914 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9915 | enforceModifyPermission(); |
| 9916 | |
| 9917 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9918 | : Boolean.parseBoolean(enabledStr); |
| 9919 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9920 | subId, enabled); |
| 9921 | } |
| 9922 | |
| 9923 | /** |
| 9924 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9925 | */ |
| 9926 | @Override |
| 9927 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9928 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9929 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9930 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9931 | |
| 9932 | /** |
| 9933 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9934 | * their mobile plan. |
| 9935 | */ |
| 9936 | @Override |
| 9937 | public String getMobileProvisioningUrl() { |
| 9938 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9939 | final long identity = Binder.clearCallingIdentity(); |
| 9940 | try { |
| 9941 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9942 | } finally { |
| 9943 | Binder.restoreCallingIdentity(identity); |
| 9944 | } |
| 9945 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9946 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9947 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9948 | * Get the EAB contact from the EAB database. |
| 9949 | */ |
| 9950 | @Override |
| 9951 | public String getContactFromEab(String contact) { |
| 9952 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9953 | enforceModifyPermission(); |
| 9954 | final long identity = Binder.clearCallingIdentity(); |
| 9955 | try { |
| 9956 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9957 | } finally { |
| 9958 | Binder.restoreCallingIdentity(identity); |
| 9959 | } |
| 9960 | } |
| 9961 | |
| 9962 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9963 | * Remove the EAB contacts from the EAB database. |
| 9964 | */ |
| 9965 | @Override |
| 9966 | public int removeContactFromEab(int subId, String contacts) { |
| 9967 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9968 | enforceModifyPermission(); |
| 9969 | final long identity = Binder.clearCallingIdentity(); |
| 9970 | try { |
| 9971 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9972 | } finally { |
| 9973 | Binder.restoreCallingIdentity(identity); |
| 9974 | } |
| 9975 | } |
| 9976 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9977 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9978 | public boolean getDeviceUceEnabled() { |
| 9979 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9980 | final long identity = Binder.clearCallingIdentity(); |
| 9981 | try { |
| 9982 | return mApp.getDeviceUceEnabled(); |
| 9983 | } finally { |
| 9984 | Binder.restoreCallingIdentity(identity); |
| 9985 | } |
| 9986 | } |
| 9987 | |
| 9988 | @Override |
| 9989 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9990 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | mApp.setDeviceUceEnabled(isEnabled); |
| 9994 | } finally { |
| 9995 | Binder.restoreCallingIdentity(identity); |
| 9996 | } |
| 9997 | } |
| 9998 | |
| 9999 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10000 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10001 | String callingPackage) { |
| 10002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10003 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10004 | |
| 10005 | final int callingUid = Binder.getCallingUid(); |
| 10006 | // Verify that tha callingPackage belongs to the calling UID |
| 10007 | mApp.getSystemService(AppOpsManager.class) |
| 10008 | .checkPackage(callingUid, callingPackage); |
| 10009 | |
| 10010 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10011 | |
| 10012 | final long identity = Binder.clearCallingIdentity(); |
| 10013 | try { |
| 10014 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10015 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10016 | |
| 10017 | if (result instanceof IllegalStateException) { |
| 10018 | throw (IllegalStateException) result; |
| 10019 | } |
| 10020 | } finally { |
| 10021 | Binder.restoreCallingIdentity(identity); |
| 10022 | } |
| 10023 | } |
| 10024 | |
| 10025 | @Override |
| 10026 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10027 | String callingPackage) { |
| 10028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10029 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10030 | |
| 10031 | final int callingUid = Binder.getCallingUid(); |
| 10032 | // Verify that tha callingPackage belongs to the calling UID |
| 10033 | mApp.getSystemService(AppOpsManager.class) |
| 10034 | .checkPackage(callingUid, callingPackage); |
| 10035 | |
| 10036 | final long identity = Binder.clearCallingIdentity(); |
| 10037 | try { |
| 10038 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10039 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10040 | |
| 10041 | if (result instanceof IllegalStateException) { |
| 10042 | throw (IllegalStateException) result; |
| 10043 | } |
| 10044 | } finally { |
| 10045 | Binder.restoreCallingIdentity(identity); |
| 10046 | } |
| 10047 | } |
| 10048 | |
| 10049 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10050 | int callingUid) { |
| 10051 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10052 | // phone/system process do not have further restriction on request |
| 10053 | return; |
| 10054 | } |
| 10055 | |
| 10056 | // Applications has restrictions on how to use the request: |
| 10057 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10058 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10059 | // This is not system caller which has been checked above |
| 10060 | throw new IllegalArgumentException( |
| 10061 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10062 | } |
| 10063 | |
| 10064 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10065 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10066 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10067 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10068 | || info.isEnabled()) { |
| 10069 | throw new IllegalArgumentException( |
| 10070 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10071 | } |
| 10072 | |
| 10073 | // Thresholds length for each RAN need in range. This has been validated in |
| 10074 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10075 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10076 | final int[] thresholds = info.getThresholds(); |
| 10077 | Objects.requireNonNull(thresholds); |
| 10078 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10079 | || thresholds.length |
| 10080 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10081 | throw new IllegalArgumentException( |
| 10082 | "thresholds length is out of range: " + thresholds.length); |
| 10083 | } |
| 10084 | } |
| 10085 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10086 | |
| 10087 | /** |
| 10088 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10089 | * required to be done shortly after the API is invoked. |
| 10090 | */ |
| 10091 | @Override |
| 10092 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10093 | public int prepareForUnattendedReboot() { |
| 10094 | enforceRebootPermission(); |
| 10095 | |
| 10096 | final long identity = Binder.clearCallingIdentity(); |
| 10097 | try { |
| 10098 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10099 | } finally { |
| 10100 | Binder.restoreCallingIdentity(identity); |
| 10101 | } |
| 10102 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10103 | } |