Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 34 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 35 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 36 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 37 | import android.net.Uri; |
| 38 | import android.os.AsyncResult; |
| 39 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 40 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 43 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.os.Looper; |
| 45 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 46 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 48 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 49 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 50 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 51 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 52 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 53 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 54 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrengthUpdateRequest; |
| 94 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 101 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 102 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 103 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 104 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 105 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 106 | import android.telephony.data.ApnSetting; |
| 107 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 108 | import android.telephony.gba.GbaAuthRequest; |
| 109 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 110 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 112 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 113 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 120 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 126 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 127 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 130 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 131 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 132 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 133 | import com.android.ims.rcs.uce.eab.EabUtil; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 173 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 187 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 189 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 191 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 193 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 194 | import com.android.services.telephony.TelecomAccountRegistry; |
| 195 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 196 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 197 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 198 | import java.io.FileDescriptor; |
| 199 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 201 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 202 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 203 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 204 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 205 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 207 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 208 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 210 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 211 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * Implementation of the ITelephony interface. |
| 215 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 216 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 217 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 218 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 219 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 220 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 221 | |
| 222 | // Message codes used with mMainThreadHandler |
| 223 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 224 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 225 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | private static final int CMD_OPEN_CHANNEL = 9; |
| 227 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 228 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 229 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 230 | private static final int CMD_NV_READ_ITEM = 13; |
| 231 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 232 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 233 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 234 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 235 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 236 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 237 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 238 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 239 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 240 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 241 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 242 | private static final int CMD_SEND_ENVELOPE = 25; |
| 243 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 244 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 245 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 246 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 247 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 248 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 249 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 250 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 251 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 252 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 253 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 255 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 256 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 257 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 258 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 259 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 260 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 261 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 262 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 263 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 264 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 265 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 266 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 267 | private static final int CMD_SWITCH_SLOTS = 50; |
| 268 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 269 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 270 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 271 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 272 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 273 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 274 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 275 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 276 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 277 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 278 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 279 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 280 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 281 | private static final int CMD_MODEM_REBOOT = 64; |
| 282 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 283 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 284 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 285 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 286 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 287 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 288 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 289 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 290 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 291 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 292 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 293 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 294 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 295 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 296 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 297 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 298 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 299 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 300 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 301 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 302 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 303 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 304 | private static final int CMD_GET_CALL_WAITING = 87; |
| 305 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 306 | private static final int CMD_SET_CALL_WAITING = 89; |
| 307 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 308 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 309 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 310 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 311 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 312 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 313 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 314 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 315 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 316 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 317 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 318 | private static final int CMD_SET_SIM_POWER = 101; |
| 319 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 320 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 321 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 322 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 323 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 324 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 325 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 326 | // Parameters of select command. |
| 327 | private static final int SELECT_COMMAND = 0xA4; |
| 328 | private static final int SELECT_P1 = 0x04; |
| 329 | private static final int SELECT_P2 = 0; |
| 330 | private static final int SELECT_P3 = 0x10; |
| 331 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 332 | /** The singleton instance. */ |
| 333 | private static PhoneInterfaceManager sInstance; |
| 334 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 335 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 336 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 337 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 338 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 339 | private AppOpsManager mAppOps; |
| 340 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 341 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 342 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 343 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 344 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 345 | /** User Activity */ |
| 346 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 347 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 348 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 349 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 350 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 351 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 352 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 353 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 354 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 355 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 356 | // String to store multi SIM allowed |
| 357 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 358 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 359 | // The AID of ISD-R. |
| 360 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 361 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 362 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 363 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 364 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 365 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 366 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 367 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 368 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 369 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 370 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 371 | */ |
| 372 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 373 | "reset_network_erase_modem_config_enabled"; |
| 374 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 375 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 376 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 377 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 378 | * A request object to use for transmitting data to an ICC. |
| 379 | */ |
| 380 | private static final class IccAPDUArgument { |
| 381 | public int channel, cla, command, p1, p2, p3; |
| 382 | public String data; |
| 383 | |
| 384 | public IccAPDUArgument(int channel, int cla, int command, |
| 385 | int p1, int p2, int p3, String data) { |
| 386 | this.channel = channel; |
| 387 | this.cla = cla; |
| 388 | this.command = command; |
| 389 | this.p1 = p1; |
| 390 | this.p2 = p2; |
| 391 | this.p3 = p3; |
| 392 | this.data = data; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 397 | * A request object to use for transmitting data to an ICC. |
| 398 | */ |
| 399 | private static final class ManualNetworkSelectionArgument { |
| 400 | public OperatorInfo operatorInfo; |
| 401 | public boolean persistSelection; |
| 402 | |
| 403 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 404 | this.operatorInfo = operatorInfo; |
| 405 | this.persistSelection = persistSelection; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 410 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 411 | * request after sending. The main thread will notify the request when it is complete. |
| 412 | */ |
| 413 | private static final class MainThreadRequest { |
| 414 | /** The argument to use for the request */ |
| 415 | public Object argument; |
| 416 | /** The result of the request that is run on the main thread */ |
| 417 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 418 | // The subscriber id that this request applies to. Defaults to |
| 419 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 420 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 422 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 423 | public Phone phone; |
| 424 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 425 | public WorkSource workSource; |
| 426 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | public MainThreadRequest(Object argument) { |
| 428 | this.argument = argument; |
| 429 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 430 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 431 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 432 | this.argument = argument; |
| 433 | if (phone != null) { |
| 434 | this.phone = phone; |
| 435 | } |
| 436 | this.workSource = workSource; |
| 437 | } |
| 438 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 439 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 440 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 441 | if (subId != null) { |
| 442 | this.subId = subId; |
| 443 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 444 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 445 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 448 | private static final class IncomingThirdPartyCallArgs { |
| 449 | public final ComponentName component; |
| 450 | public final String callId; |
| 451 | public final String callerDisplayName; |
| 452 | |
| 453 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 454 | String callerDisplayName) { |
| 455 | this.component = component; |
| 456 | this.callId = callId; |
| 457 | this.callerDisplayName = callerDisplayName; |
| 458 | } |
| 459 | } |
| 460 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 461 | /** |
| 462 | * A handler that processes messages on the main thread in the phone process. Since many |
| 463 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 464 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 465 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 466 | * on, which will be notified when the operation completes and will contain the result of the |
| 467 | * request. |
| 468 | * |
| 469 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 470 | * note that request.result must be set to something non-null for the calling thread to |
| 471 | * unblock. |
| 472 | */ |
| 473 | private final class MainThreadHandler extends Handler { |
| 474 | @Override |
| 475 | public void handleMessage(Message msg) { |
| 476 | MainThreadRequest request; |
| 477 | Message onCompleted; |
| 478 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 479 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 480 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 481 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | |
| 483 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 484 | case CMD_HANDLE_USSD_REQUEST: { |
| 485 | request = (MainThreadRequest) msg.obj; |
| 486 | final Phone phone = getPhoneFromRequest(request); |
| 487 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 488 | String ussdRequest = ussdObject.first; |
| 489 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 490 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 491 | if (!isUssdApiAllowed(request.subId)) { |
| 492 | // Carrier does not support use of this API, return failure. |
| 493 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 494 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 495 | Bundle returnData = new Bundle(); |
| 496 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 497 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 498 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | request.result = true; |
| 500 | notifyRequester(request); |
| 501 | return; |
| 502 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 503 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | try { |
| 505 | request.result = phone != null |
| 506 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 507 | } catch (CallStateException cse) { |
| 508 | request.result = false; |
| 509 | } |
| 510 | // Wake up the requesting thread |
| 511 | notifyRequester(request); |
| 512 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 515 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 516 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 517 | final Phone phone = getPhoneFromRequest(request); |
| 518 | request.result = phone != null ? |
| 519 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 520 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 522 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 524 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 527 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 529 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | if (uiccCard == null) { |
| 531 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 532 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 536 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 539 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | break; |
| 543 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | ar = (AsyncResult) msg.obj; |
| 546 | request = (MainThreadRequest) ar.userObj; |
| 547 | if (ar.exception == null && ar.result != null) { |
| 548 | request.result = ar.result; |
| 549 | } else { |
| 550 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 551 | if (ar.result == null) { |
| 552 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 553 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 554 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 555 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 556 | } else { |
| 557 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 558 | } |
| 559 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 561 | break; |
| 562 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 564 | request = (MainThreadRequest) msg.obj; |
| 565 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 566 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | if (uiccCard == null) { |
| 568 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 569 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | } else { |
| 572 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 573 | request); |
| 574 | uiccCard.iccTransmitApduBasicChannel( |
| 575 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 576 | iccArgument.p3, iccArgument.data, onCompleted); |
| 577 | } |
| 578 | break; |
| 579 | |
| 580 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 581 | ar = (AsyncResult) msg.obj; |
| 582 | request = (MainThreadRequest) ar.userObj; |
| 583 | if (ar.exception == null && ar.result != null) { |
| 584 | request.result = ar.result; |
| 585 | } else { |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 587 | if (ar.result == null) { |
| 588 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 589 | } else if (ar.exception instanceof CommandException) { |
| 590 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 591 | ar.exception); |
| 592 | } else { |
| 593 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 594 | } |
| 595 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
| 599 | case CMD_EXCHANGE_SIM_IO: |
| 600 | request = (MainThreadRequest) msg.obj; |
| 601 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 602 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | if (uiccCard == null) { |
| 604 | loge("iccExchangeSimIO: No UICC"); |
| 605 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | } else { |
| 608 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 609 | request); |
| 610 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 611 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 612 | iccArgument.data, onCompleted); |
| 613 | } |
| 614 | break; |
| 615 | |
| 616 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 617 | ar = (AsyncResult) msg.obj; |
| 618 | request = (MainThreadRequest) ar.userObj; |
| 619 | if (ar.exception == null && ar.result != null) { |
| 620 | request.result = ar.result; |
| 621 | } else { |
| 622 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 623 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 624 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | case CMD_SEND_ENVELOPE: |
| 628 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 629 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | if (uiccCard == null) { |
| 631 | loge("sendEnvelopeWithStatus: No UICC"); |
| 632 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 633 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | } else { |
| 635 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 636 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 637 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case EVENT_SEND_ENVELOPE_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 645 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 647 | if (ar.result == null) { |
| 648 | loge("sendEnvelopeWithStatus: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 654 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 657 | break; |
| 658 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | case CMD_OPEN_CHANNEL: |
| 660 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 661 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 662 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | if (uiccCard == null) { |
| 664 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 665 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 666 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | } else { |
| 669 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 670 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 671 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EVENT_OPEN_CHANNEL_DONE: |
| 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | int[] result = (int[]) ar.result; |
| 681 | int channelId = result[0]; |
| 682 | byte[] selectResponse = null; |
| 683 | if (result.length > 1) { |
| 684 | selectResponse = new byte[result.length - 1]; |
| 685 | for (int i = 1; i < result.length; ++i) { |
| 686 | selectResponse[i - 1] = (byte) result[i]; |
| 687 | } |
| 688 | } |
| 689 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 690 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | if (ar.result == null) { |
| 693 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 694 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | if (ar.exception != null) { |
| 696 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 697 | } |
| 698 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 699 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 700 | if (ar.exception instanceof CommandException) { |
| 701 | CommandException.Error error = |
| 702 | ((CommandException) (ar.exception)).getCommandError(); |
| 703 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 704 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 705 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 706 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 710 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 712 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 713 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case CMD_CLOSE_CHANNEL: |
| 717 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 718 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | if (uiccCard == null) { |
| 720 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 721 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | } else { |
| 724 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 725 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 726 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 731 | break; |
| 732 | |
| 733 | case CMD_NV_READ_ITEM: |
| 734 | request = (MainThreadRequest) msg.obj; |
| 735 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 736 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 737 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | ar = (AsyncResult) msg.obj; |
| 742 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | if (ar.exception == null && ar.result != null) { |
| 744 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | request.result = ""; |
| 747 | if (ar.result == null) { |
| 748 | loge("nvReadItem: Empty response"); |
| 749 | } else if (ar.exception instanceof CommandException) { |
| 750 | loge("nvReadItem: CommandException: " + |
| 751 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 752 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 754 | } |
| 755 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 756 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 757 | break; |
| 758 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | case CMD_NV_WRITE_ITEM: |
| 760 | request = (MainThreadRequest) msg.obj; |
| 761 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 762 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 763 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 764 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_NV_WRITE_ITEM_DONE: |
| 768 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 769 | break; |
| 770 | |
| 771 | case CMD_NV_WRITE_CDMA_PRL: |
| 772 | request = (MainThreadRequest) msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 778 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 779 | break; |
| 780 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 781 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 782 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 783 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 784 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 788 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 791 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 792 | request = (MainThreadRequest) msg.obj; |
| 793 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 794 | request); |
| 795 | Phone phone = getPhoneFromRequest(request); |
| 796 | if (phone != null) { |
| 797 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 798 | } else { |
| 799 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 800 | request.result = false; |
| 801 | notifyRequester(request); |
| 802 | } |
| 803 | break; |
| 804 | } |
| 805 | |
| 806 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 807 | ar = (AsyncResult) msg.obj; |
| 808 | request = (MainThreadRequest) ar.userObj; |
| 809 | if (ar.exception == null && ar.result != null) { |
| 810 | request.result = ar.result; |
| 811 | } else { |
| 812 | // request.result must be set to something non-null |
| 813 | // for the calling thread to unblock |
| 814 | if (request.result != null) { |
| 815 | request.result = ar.result; |
| 816 | } else { |
| 817 | request.result = false; |
| 818 | } |
| 819 | if (ar.result == null) { |
| 820 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 821 | } else if (ar.exception instanceof CommandException) { |
| 822 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 823 | + ar.exception); |
| 824 | } else { |
| 825 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 826 | } |
| 827 | } |
| 828 | notifyRequester(request); |
| 829 | break; |
| 830 | |
| 831 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 832 | request = (MainThreadRequest) msg.obj; |
| 833 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 834 | Phone phone = getPhoneFromRequest(request); |
| 835 | if (phone != null) { |
| 836 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 837 | request.workSource); |
| 838 | } else { |
| 839 | loge("enableNrDualConnectivity: No phone object"); |
| 840 | request.result = |
| 841 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 842 | notifyRequester(request); |
| 843 | } |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 848 | ar = (AsyncResult) msg.obj; |
| 849 | request = (MainThreadRequest) ar.userObj; |
| 850 | if (ar.exception == null) { |
| 851 | request.result = |
| 852 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 853 | } else { |
| 854 | request.result = |
| 855 | TelephonyManager |
| 856 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 857 | if (ar.exception instanceof CommandException) { |
| 858 | CommandException.Error error = |
| 859 | ((CommandException) (ar.exception)).getCommandError(); |
| 860 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 861 | request.result = |
| 862 | TelephonyManager |
| 863 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 864 | } |
| 865 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 866 | + ar.exception); |
| 867 | } else { |
| 868 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 869 | } |
| 870 | } |
| 871 | notifyRequester(request); |
| 872 | break; |
| 873 | } |
| 874 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 875 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 876 | request = (MainThreadRequest) msg.obj; |
| 877 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 878 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 879 | break; |
| 880 | |
| 881 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 882 | ar = (AsyncResult) msg.obj; |
| 883 | request = (MainThreadRequest) ar.userObj; |
| 884 | if (ar.exception == null && ar.result != null) { |
| 885 | request.result = ar.result; // Integer |
| 886 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 887 | // request.result must be set to something non-null |
| 888 | // for the calling thread to unblock |
| 889 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 890 | if (ar.result == null) { |
| 891 | loge("getPreferredNetworkType: Empty response"); |
| 892 | } else if (ar.exception instanceof CommandException) { |
| 893 | loge("getPreferredNetworkType: CommandException: " + |
| 894 | ar.exception); |
| 895 | } else { |
| 896 | loge("getPreferredNetworkType: Unknown exception"); |
| 897 | } |
| 898 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 899 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 900 | break; |
| 901 | |
| 902 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 903 | request = (MainThreadRequest) msg.obj; |
| 904 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 905 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 906 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 907 | break; |
| 908 | |
| 909 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 910 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 911 | break; |
| 912 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 913 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 914 | request = (MainThreadRequest)msg.obj; |
| 915 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 916 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 920 | ar = (AsyncResult)msg.obj; |
| 921 | request = (MainThreadRequest)ar.userObj; |
| 922 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 923 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 924 | break; |
| 925 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 926 | case CMD_SET_VOICEMAIL_NUMBER: |
| 927 | request = (MainThreadRequest) msg.obj; |
| 928 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 929 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 930 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 931 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 932 | break; |
| 933 | |
| 934 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 935 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 936 | break; |
| 937 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 938 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 939 | request = (MainThreadRequest) msg.obj; |
| 940 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 941 | request); |
| 942 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 943 | break; |
| 944 | |
| 945 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 946 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 947 | break; |
| 948 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 949 | case CMD_PERFORM_NETWORK_SCAN: |
| 950 | request = (MainThreadRequest) msg.obj; |
| 951 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 952 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 953 | break; |
| 954 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 955 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 956 | request = (MainThreadRequest) msg.obj; |
| 957 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 958 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 959 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 960 | request.argument; |
| 961 | int callForwardingReason = args.first; |
| 962 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 963 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | } |
| 965 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 966 | ar = (AsyncResult) msg.obj; |
| 967 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | TelephonyManager.CallForwardingInfoCallback callback = |
| 969 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 970 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 971 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 972 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 973 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 974 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 975 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 976 | // any service for voice call. |
| 977 | if ((callForwardInfo.serviceClass |
| 978 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 979 | callForwardingInfo = new CallForwardingInfo(true, |
| 980 | callForwardInfo.reason, |
| 981 | callForwardInfo.number, |
| 982 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 983 | break; |
| 984 | } |
| 985 | } |
| 986 | // Didn't find a call forward info for voice call. |
| 987 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 989 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 990 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 991 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 992 | } else { |
| 993 | if (ar.result == null) { |
| 994 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 995 | } |
| 996 | if (ar.exception != null) { |
| 997 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 998 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 999 | int errorCode = TelephonyManager |
| 1000 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1001 | if (ar.exception instanceof CommandException) { |
| 1002 | CommandException.Error error = |
| 1003 | ((CommandException) (ar.exception)).getCommandError(); |
| 1004 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1005 | errorCode = TelephonyManager |
| 1006 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1007 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1008 | errorCode = TelephonyManager |
| 1009 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1010 | } |
| 1011 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1012 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1013 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1014 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1017 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1018 | request = (MainThreadRequest) msg.obj; |
| 1019 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1021 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1023 | request.argument).first; |
| 1024 | request.phone.setCallForwardingOption( |
| 1025 | callForwardingInfoToSet.isEnabled() |
| 1026 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1027 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1028 | callForwardingInfoToSet.getReason(), |
| 1029 | callForwardingInfoToSet.getNumber(), |
| 1030 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1031 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1033 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | Consumer<Integer> callback = |
| 1038 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1039 | request.argument).second; |
| 1040 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1041 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1042 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1043 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | if (ar.exception instanceof CommandException) { |
| 1045 | CommandException.Error error = |
| 1046 | ((CommandException) (ar.exception)).getCommandError(); |
| 1047 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1048 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1049 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1051 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1052 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | callback.accept(errorCode); |
| 1056 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1057 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1059 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1061 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1062 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1063 | request = (MainThreadRequest) msg.obj; |
| 1064 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1065 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1066 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1068 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1070 | ar = (AsyncResult) msg.obj; |
| 1071 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1073 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1074 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1075 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1076 | // Service Class is a bit mask per 3gpp 27.007. |
| 1077 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1078 | if (callForwardResults.length > 1 |
| 1079 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1080 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1081 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1083 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1084 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1086 | } |
| 1087 | } else { |
| 1088 | if (ar.result == null) { |
| 1089 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1090 | } |
| 1091 | if (ar.exception != null) { |
| 1092 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1093 | } |
| 1094 | if (ar.exception instanceof CommandException) { |
| 1095 | CommandException.Error error = |
| 1096 | ((CommandException) (ar.exception)).getCommandError(); |
| 1097 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1098 | callForwardingStatus = |
| 1099 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1104 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1105 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1106 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1108 | request = (MainThreadRequest) msg.obj; |
| 1109 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1111 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1112 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1114 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1116 | ar = (AsyncResult) msg.obj; |
| 1117 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1118 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1119 | Consumer<Integer> callback = |
| 1120 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1121 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1122 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | if (ar.exception instanceof CommandException) { |
| 1124 | CommandException.Error error = |
| 1125 | ((CommandException) (ar.exception)).getCommandError(); |
| 1126 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1127 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1128 | } else { |
| 1129 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1130 | } |
| 1131 | } else { |
| 1132 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1133 | } |
| 1134 | } else { |
| 1135 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1136 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1137 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1138 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1139 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1140 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1141 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1142 | ar = (AsyncResult) msg.obj; |
| 1143 | request = (MainThreadRequest) ar.userObj; |
| 1144 | CellNetworkScanResult cellScanResult; |
| 1145 | if (ar.exception == null && ar.result != null) { |
| 1146 | cellScanResult = new CellNetworkScanResult( |
| 1147 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1148 | (List<OperatorInfo>) ar.result); |
| 1149 | } else { |
| 1150 | if (ar.result == null) { |
| 1151 | loge("getCellNetworkScanResults: Empty response"); |
| 1152 | } |
| 1153 | if (ar.exception != null) { |
| 1154 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1155 | } |
| 1156 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1157 | if (ar.exception instanceof CommandException) { |
| 1158 | CommandException.Error error = |
| 1159 | ((CommandException) (ar.exception)).getCommandError(); |
| 1160 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1161 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1162 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1163 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1164 | } |
| 1165 | } |
| 1166 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1167 | } |
| 1168 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1169 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | |
| 1172 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1173 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1174 | ManualNetworkSelectionArgument selArg = |
| 1175 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1176 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1177 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1178 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1179 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | |
| 1182 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1183 | ar = (AsyncResult) msg.obj; |
| 1184 | request = (MainThreadRequest) ar.userObj; |
| 1185 | if (ar.exception == null) { |
| 1186 | request.result = true; |
| 1187 | } else { |
| 1188 | request.result = false; |
| 1189 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1190 | } |
| 1191 | notifyRequester(request); |
| 1192 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1193 | break; |
| 1194 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1195 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1196 | request = (MainThreadRequest) msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1198 | if (defaultPhone != null) { |
| 1199 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1200 | } else { |
| 1201 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1202 | Bundle bundle = new Bundle(); |
| 1203 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1204 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1205 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1206 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1210 | ar = (AsyncResult) msg.obj; |
| 1211 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1212 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1213 | |
| 1214 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1215 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1216 | // Update the last modem activity info and the result of the request. |
| 1217 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1218 | if (isModemActivityInfoValid(info)) { |
| 1219 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1220 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1221 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1222 | .getTransmitTimeMillis(); |
| 1223 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1224 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1225 | } |
| 1226 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1227 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1228 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1229 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1230 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1231 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1232 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1233 | info.getReceiveTimeMillis() |
| 1234 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1235 | } |
| 1236 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1237 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1238 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1239 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1240 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1241 | } else { |
| 1242 | if (ar.result == null) { |
| 1243 | loge("queryModemActivityInfo: Empty response"); |
| 1244 | } else if (ar.exception instanceof CommandException) { |
| 1245 | loge("queryModemActivityInfo: CommandException: " + |
| 1246 | ar.exception); |
| 1247 | } else { |
| 1248 | loge("queryModemActivityInfo: Unknown exception"); |
| 1249 | } |
| 1250 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1251 | Bundle bundle = new Bundle(); |
| 1252 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1253 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1254 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1255 | break; |
| 1256 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1257 | case CMD_SET_ALLOWED_CARRIERS: |
| 1258 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1259 | CarrierRestrictionRules argument = |
| 1260 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1261 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1262 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1263 | break; |
| 1264 | |
| 1265 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
| 1268 | if (ar.exception == null && ar.result != null) { |
| 1269 | request.result = ar.result; |
| 1270 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1271 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1272 | if (ar.exception instanceof CommandException) { |
| 1273 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1274 | CommandException.Error error = |
| 1275 | ((CommandException) (ar.exception)).getCommandError(); |
| 1276 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1277 | request.result = |
| 1278 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1279 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1280 | } else { |
| 1281 | loge("setAllowedCarriers: Unknown exception"); |
| 1282 | } |
| 1283 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1284 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1285 | break; |
| 1286 | |
| 1287 | case CMD_GET_ALLOWED_CARRIERS: |
| 1288 | request = (MainThreadRequest) msg.obj; |
| 1289 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1290 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1291 | break; |
| 1292 | |
| 1293 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1294 | ar = (AsyncResult) msg.obj; |
| 1295 | request = (MainThreadRequest) ar.userObj; |
| 1296 | if (ar.exception == null && ar.result != null) { |
| 1297 | request.result = ar.result; |
| 1298 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1299 | request.result = new IllegalStateException( |
| 1300 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1301 | if (ar.result == null) { |
| 1302 | loge("getAllowedCarriers: Empty response"); |
| 1303 | } else if (ar.exception instanceof CommandException) { |
| 1304 | loge("getAllowedCarriers: CommandException: " + |
| 1305 | ar.exception); |
| 1306 | } else { |
| 1307 | loge("getAllowedCarriers: Unknown exception"); |
| 1308 | } |
| 1309 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1310 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1311 | break; |
| 1312 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1313 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1314 | ar = (AsyncResult) msg.obj; |
| 1315 | request = (MainThreadRequest) ar.userObj; |
| 1316 | if (ar.exception == null && ar.result != null) { |
| 1317 | request.result = ar.result; |
| 1318 | } else { |
| 1319 | request.result = new IllegalArgumentException( |
| 1320 | "Failed to retrieve Forbidden Plmns"); |
| 1321 | if (ar.result == null) { |
| 1322 | loge("getForbiddenPlmns: Empty response"); |
| 1323 | } else { |
| 1324 | loge("getForbiddenPlmns: Unknown exception"); |
| 1325 | } |
| 1326 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1327 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1328 | break; |
| 1329 | |
| 1330 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1331 | request = (MainThreadRequest) msg.obj; |
| 1332 | uiccCard = getUiccCardFromRequest(request); |
| 1333 | if (uiccCard == null) { |
| 1334 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1335 | request.result = new IllegalArgumentException( |
| 1336 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1337 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | Integer appType = (Integer) request.argument; |
| 1341 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1342 | if (uiccApp == null) { |
| 1343 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1344 | + appType); |
| 1345 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1346 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1347 | break; |
| 1348 | } else { |
| 1349 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1350 | + " specified type -- " + appType); |
| 1351 | } |
| 1352 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1353 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1354 | onCompleted); |
| 1355 | break; |
| 1356 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1357 | case CMD_SWITCH_SLOTS: |
| 1358 | request = (MainThreadRequest) msg.obj; |
| 1359 | int[] physicalSlots = (int[]) request.argument; |
| 1360 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1361 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1362 | break; |
| 1363 | |
| 1364 | case EVENT_SWITCH_SLOTS_DONE: |
| 1365 | ar = (AsyncResult) msg.obj; |
| 1366 | request = (MainThreadRequest) ar.userObj; |
| 1367 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1368 | notifyRequester(request); |
| 1369 | break; |
| 1370 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1371 | request = (MainThreadRequest) msg.obj; |
| 1372 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1373 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1374 | break; |
| 1375 | |
| 1376 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1377 | ar = (AsyncResult) msg.obj; |
| 1378 | request = (MainThreadRequest) ar.userObj; |
| 1379 | if (ar.exception != null) { |
| 1380 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1381 | } else { |
| 1382 | int mode = ((int[]) ar.result)[0]; |
| 1383 | if (mode == 0) { |
| 1384 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1385 | } else { |
| 1386 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1387 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1388 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1389 | notifyRequester(request); |
| 1390 | break; |
| 1391 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1392 | request = (MainThreadRequest) msg.obj; |
| 1393 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1394 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1395 | break; |
| 1396 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1397 | ar = (AsyncResult) msg.obj; |
| 1398 | request = (MainThreadRequest) ar.userObj; |
| 1399 | if (ar.exception != null) { |
| 1400 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1401 | } else { |
| 1402 | request.result = ((int[]) ar.result)[0]; |
| 1403 | } |
| 1404 | notifyRequester(request); |
| 1405 | break; |
| 1406 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1407 | request = (MainThreadRequest) msg.obj; |
| 1408 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1409 | int mode = (int) request.argument; |
| 1410 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1411 | break; |
| 1412 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1413 | ar = (AsyncResult) msg.obj; |
| 1414 | request = (MainThreadRequest) ar.userObj; |
| 1415 | request.result = ar.exception == null; |
| 1416 | notifyRequester(request); |
| 1417 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1418 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1419 | request = (MainThreadRequest) msg.obj; |
| 1420 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1421 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1422 | break; |
| 1423 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
| 1426 | if (ar.exception != null) { |
| 1427 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1428 | } else { |
| 1429 | request.result = ((int[]) ar.result)[0]; |
| 1430 | } |
| 1431 | notifyRequester(request); |
| 1432 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1433 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1434 | request = (MainThreadRequest) msg.obj; |
| 1435 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1436 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1437 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1438 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1439 | break; |
| 1440 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1441 | ar = (AsyncResult) msg.obj; |
| 1442 | request = (MainThreadRequest) ar.userObj; |
| 1443 | request.result = ar.exception == null; |
| 1444 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1445 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1446 | case CMD_GET_ALL_CELL_INFO: |
| 1447 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1448 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1449 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1450 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1451 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1452 | ar = (AsyncResult) msg.obj; |
| 1453 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1454 | // If a timeout occurs, the response will be null |
| 1455 | request.result = (ar.exception == null && ar.result != null) |
| 1456 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1457 | synchronized (request) { |
| 1458 | request.notifyAll(); |
| 1459 | } |
| 1460 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1461 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1462 | request = (MainThreadRequest) msg.obj; |
| 1463 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1464 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1465 | break; |
| 1466 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1467 | ar = (AsyncResult) msg.obj; |
| 1468 | request = (MainThreadRequest) ar.userObj; |
| 1469 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1470 | try { |
| 1471 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1472 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1473 | cb.onError( |
| 1474 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1475 | ar.exception.getClass().getName(), |
| 1476 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1477 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1478 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1479 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1480 | } else { |
| 1481 | // use the result as returned |
| 1482 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1483 | } |
| 1484 | } catch (RemoteException re) { |
| 1485 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1486 | } |
| 1487 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1488 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1489 | request = (MainThreadRequest) msg.obj; |
| 1490 | WorkSource ws = (WorkSource) request.argument; |
| 1491 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1492 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1493 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1494 | } |
| 1495 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1496 | ar = (AsyncResult) msg.obj; |
| 1497 | request = (MainThreadRequest) ar.userObj; |
| 1498 | if (ar.exception == null) { |
| 1499 | request.result = ar.result; |
| 1500 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1501 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1502 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1503 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | synchronized (request) { |
| 1507 | request.notifyAll(); |
| 1508 | } |
| 1509 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1510 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1511 | case CMD_MODEM_REBOOT: |
| 1512 | request = (MainThreadRequest) msg.obj; |
| 1513 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1514 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1515 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1516 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1517 | handleNullReturnEvent(msg, "rebootModem"); |
| 1518 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1519 | case CMD_REQUEST_ENABLE_MODEM: |
| 1520 | request = (MainThreadRequest) msg.obj; |
| 1521 | boolean enable = (boolean) request.argument; |
| 1522 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1523 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1524 | PhoneConfigurationManager.getInstance() |
| 1525 | .enablePhone(request.phone, enable, onCompleted); |
| 1526 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1527 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1528 | ar = (AsyncResult) msg.obj; |
| 1529 | request = (MainThreadRequest) ar.userObj; |
| 1530 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1531 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1532 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1533 | if ((boolean) request.result) { |
| 1534 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1535 | updateModemStateMetrics(); |
| 1536 | } else { |
| 1537 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1538 | + ar.exception); |
| 1539 | } |
| 1540 | notifyRequester(request); |
| 1541 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1542 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1543 | case CMD_GET_MODEM_STATUS: |
| 1544 | request = (MainThreadRequest) msg.obj; |
| 1545 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1546 | PhoneConfigurationManager.getInstance() |
| 1547 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1548 | break; |
| 1549 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1550 | ar = (AsyncResult) msg.obj; |
| 1551 | request = (MainThreadRequest) ar.userObj; |
| 1552 | int id = request.phone.getPhoneId(); |
| 1553 | if (ar.exception == null && ar.result != null) { |
| 1554 | request.result = ar.result; |
| 1555 | //update the cache as modem status has changed |
| 1556 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1557 | (boolean) request.result); |
| 1558 | } else { |
| 1559 | // Return true if modem status cannot be retrieved. For most cases, |
| 1560 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1561 | // and disable modem are not supported. Modem is always on. |
| 1562 | // TODO: this should be fixed in R to support a third |
| 1563 | // status UNKNOWN b/131631629 |
| 1564 | request.result = true; |
| 1565 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1566 | + ar.exception); |
| 1567 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1568 | notifyRequester(request); |
| 1569 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1570 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1571 | request = (MainThreadRequest) msg.obj; |
| 1572 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1573 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1574 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1575 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1576 | break; |
| 1577 | } |
| 1578 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1579 | ar = (AsyncResult) msg.obj; |
| 1580 | request = (MainThreadRequest) ar.userObj; |
| 1581 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1582 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1583 | args.second.accept(ar.exception == null); |
| 1584 | notifyRequester(request); |
| 1585 | break; |
| 1586 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1587 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1588 | request = (MainThreadRequest) msg.obj; |
| 1589 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1590 | Phone phone = getPhoneFromRequest(request); |
| 1591 | if (phone != null) { |
| 1592 | phone.getSystemSelectionChannels(onCompleted); |
| 1593 | } else { |
| 1594 | loge("getSystemSelectionChannels: No phone object"); |
| 1595 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1596 | notifyRequester(request); |
| 1597 | } |
| 1598 | break; |
| 1599 | } |
| 1600 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1601 | ar = (AsyncResult) msg.obj; |
| 1602 | request = (MainThreadRequest) ar.userObj; |
| 1603 | if (ar.exception == null && ar.result != null) { |
| 1604 | request.result = ar.result; |
| 1605 | } else { |
| 1606 | request.result = new IllegalArgumentException( |
| 1607 | "Failed to retrieve system selection channels"); |
| 1608 | if (ar.result == null) { |
| 1609 | loge("getSystemSelectionChannels: Empty response"); |
| 1610 | } else { |
| 1611 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1612 | } |
| 1613 | } |
| 1614 | notifyRequester(request); |
| 1615 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1616 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1617 | ar = (AsyncResult) msg.obj; |
| 1618 | request = (MainThreadRequest) ar.userObj; |
| 1619 | if (ar.exception == null && ar.result != null) { |
| 1620 | request.result = ar.result; |
| 1621 | } else { |
| 1622 | request.result = -1; |
| 1623 | loge("Failed to set Forbidden Plmns"); |
| 1624 | if (ar.result == null) { |
| 1625 | loge("setForbidenPlmns: Empty response"); |
| 1626 | } else if (ar.exception != null) { |
| 1627 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1628 | request.result = -1; |
| 1629 | } else { |
| 1630 | loge("setForbiddenPlmns: Unknown exception"); |
| 1631 | } |
| 1632 | } |
| 1633 | notifyRequester(request); |
| 1634 | break; |
| 1635 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1636 | request = (MainThreadRequest) msg.obj; |
| 1637 | uiccCard = getUiccCardFromRequest(request); |
| 1638 | if (uiccCard == null) { |
| 1639 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1640 | request.result = -1; |
| 1641 | notifyRequester(request); |
| 1642 | break; |
| 1643 | } |
| 1644 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1645 | (Pair<Integer, List<String>>) request.argument; |
| 1646 | appType = setFplmnsArgs.first; |
| 1647 | List<String> fplmns = setFplmnsArgs.second; |
| 1648 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1649 | if (uiccApp == null) { |
| 1650 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1651 | request.result = -1; |
| 1652 | loge("Failed to get UICC App"); |
| 1653 | notifyRequester(request); |
| 1654 | } else { |
| 1655 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1656 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1657 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1658 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1659 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1660 | case CMD_ERASE_MODEM_CONFIG: |
| 1661 | request = (MainThreadRequest) msg.obj; |
| 1662 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1663 | defaultPhone.eraseModemConfig(onCompleted); |
| 1664 | break; |
| 1665 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1666 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1667 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1668 | |
| 1669 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1670 | request = (MainThreadRequest) msg.obj; |
| 1671 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1672 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1673 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1674 | changed.first, changed.second, onCompleted); |
| 1675 | break; |
| 1676 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1677 | ar = (AsyncResult) msg.obj; |
| 1678 | request = (MainThreadRequest) ar.userObj; |
| 1679 | if (ar.exception == null) { |
| 1680 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1681 | // If the operation is successful, update the PIN storage |
| 1682 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1683 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1684 | UiccController.getInstance().getPinStorage() |
| 1685 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1686 | } else { |
| 1687 | request.result = msg.arg1; |
| 1688 | } |
| 1689 | notifyRequester(request); |
| 1690 | break; |
| 1691 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1692 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1695 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1696 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1697 | enabled.first, enabled.second, onCompleted); |
| 1698 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1699 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1700 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1701 | ar = (AsyncResult) msg.obj; |
| 1702 | request = (MainThreadRequest) ar.userObj; |
| 1703 | if (ar.exception == null) { |
| 1704 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1705 | // If the operation is successful, update the PIN storage |
| 1706 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1707 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1708 | if (enabled.first) { |
| 1709 | UiccController.getInstance().getPinStorage() |
| 1710 | .storePin(enabled.second, phoneId); |
| 1711 | } else { |
| 1712 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1713 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1714 | } else { |
| 1715 | request.result = msg.arg1; |
| 1716 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1717 | |
| 1718 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1719 | notifyRequester(request); |
| 1720 | break; |
| 1721 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1722 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1723 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1724 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1725 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1726 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1727 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1728 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1729 | |
| 1730 | case CMD_SET_DATA_THROTTLING: { |
| 1731 | request = (MainThreadRequest) msg.obj; |
| 1732 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1733 | DataThrottlingRequest dataThrottlingRequest = |
| 1734 | (DataThrottlingRequest) request.argument; |
| 1735 | Phone phone = getPhoneFromRequest(request); |
| 1736 | if (phone != null) { |
| 1737 | phone.setDataThrottling(onCompleted, |
| 1738 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1739 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1740 | } else { |
| 1741 | loge("setDataThrottling: No phone object"); |
| 1742 | request.result = |
| 1743 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1744 | notifyRequester(request); |
| 1745 | } |
| 1746 | |
| 1747 | break; |
| 1748 | } |
| 1749 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1750 | ar = (AsyncResult) msg.obj; |
| 1751 | request = (MainThreadRequest) ar.userObj; |
| 1752 | |
| 1753 | if (ar.exception == null) { |
| 1754 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1755 | } else if (ar.exception instanceof CommandException) { |
| 1756 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1757 | CommandException.Error error = |
| 1758 | ((CommandException) (ar.exception)).getCommandError(); |
| 1759 | |
| 1760 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1761 | request.result = TelephonyManager |
| 1762 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1763 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1764 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1765 | } else { |
| 1766 | request.result = |
| 1767 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1768 | } |
| 1769 | } else { |
| 1770 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1771 | } |
| 1772 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1773 | notifyRequester(request); |
| 1774 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1775 | |
| 1776 | case CMD_SET_SIM_POWER: { |
| 1777 | request = (MainThreadRequest) msg.obj; |
| 1778 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1779 | request = (MainThreadRequest) msg.obj; |
| 1780 | int stateToSet = |
| 1781 | ((Pair<Integer, IIntegerConsumer>) |
| 1782 | request.argument).first; |
| 1783 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1784 | break; |
| 1785 | } |
| 1786 | case EVENT_SET_SIM_POWER_DONE: { |
| 1787 | ar = (AsyncResult) msg.obj; |
| 1788 | request = (MainThreadRequest) ar.userObj; |
| 1789 | IIntegerConsumer callback = |
| 1790 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1791 | if (ar.exception != null) { |
| 1792 | loge("setSimPower exception: " + ar.exception); |
| 1793 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1794 | .RESULT_ERROR_UNKNOWN; |
| 1795 | if (ar.exception instanceof CommandException) { |
| 1796 | CommandException.Error error = |
| 1797 | ((CommandException) (ar.exception)).getCommandError(); |
| 1798 | if (error == CommandException.Error.SIM_ERR) { |
| 1799 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1800 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1801 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1802 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1803 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1804 | } else { |
| 1805 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1806 | } |
| 1807 | } |
| 1808 | try { |
| 1809 | callback.accept(errorCode); |
| 1810 | } catch (RemoteException e) { |
| 1811 | // Ignore if the remote process is no longer available to call back. |
| 1812 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1813 | } |
| 1814 | } else { |
| 1815 | try { |
| 1816 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1817 | } catch (RemoteException e) { |
| 1818 | // Ignore if the remote process is no longer available to call back. |
| 1819 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1820 | } |
| 1821 | } |
| 1822 | break; |
| 1823 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1824 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | |
| 1827 | final Phone phone = getPhoneFromRequest(request); |
| 1828 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1829 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1830 | notifyRequester(request); |
| 1831 | break; |
| 1832 | } |
| 1833 | |
| 1834 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1835 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1836 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1837 | request); |
| 1838 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1839 | request.subId, pair.first /*callingUid*/, |
| 1840 | pair.second /*request*/, onCompleted); |
| 1841 | break; |
| 1842 | } |
| 1843 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1844 | ar = (AsyncResult) msg.obj; |
| 1845 | request = (MainThreadRequest) ar.userObj; |
| 1846 | // request.result will be the exception of ar if present, true otherwise. |
| 1847 | // Be cautious not to leave result null which will wait() forever |
| 1848 | request.result = ar.exception != null ? ar.exception : true; |
| 1849 | notifyRequester(request); |
| 1850 | break; |
| 1851 | } |
| 1852 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1853 | request = (MainThreadRequest) msg.obj; |
| 1854 | |
| 1855 | Phone phone = getPhoneFromRequest(request); |
| 1856 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1857 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1858 | notifyRequester(request); |
| 1859 | break; |
| 1860 | } |
| 1861 | |
| 1862 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1863 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1864 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1865 | request); |
| 1866 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1867 | request.subId, pair.first /*callingUid*/, |
| 1868 | pair.second /*request*/, onCompleted); |
| 1869 | break; |
| 1870 | } |
| 1871 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1872 | ar = (AsyncResult) msg.obj; |
| 1873 | request = (MainThreadRequest) ar.userObj; |
| 1874 | request.result = ar.exception != null ? ar.exception : true; |
| 1875 | notifyRequester(request); |
| 1876 | break; |
| 1877 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1878 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1879 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1880 | request = (MainThreadRequest) msg.obj; |
| 1881 | request.result = |
| 1882 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1883 | notifyRequester(request); |
| 1884 | break; |
| 1885 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1886 | default: |
| 1887 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1888 | break; |
| 1889 | } |
| 1890 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1891 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1892 | private void notifyRequester(MainThreadRequest request) { |
| 1893 | synchronized (request) { |
| 1894 | request.notifyAll(); |
| 1895 | } |
| 1896 | } |
| 1897 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1898 | private void handleNullReturnEvent(Message msg, String command) { |
| 1899 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1900 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1901 | if (ar.exception == null) { |
| 1902 | request.result = true; |
| 1903 | } else { |
| 1904 | request.result = false; |
| 1905 | if (ar.exception instanceof CommandException) { |
| 1906 | loge(command + ": CommandException: " + ar.exception); |
| 1907 | } else { |
| 1908 | loge(command + ": Unknown exception"); |
| 1909 | } |
| 1910 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1911 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | /** |
| 1916 | * Posts the specified command to be executed on the main thread, |
| 1917 | * waits for the request to complete, and returns the result. |
| 1918 | * @see #sendRequestAsync |
| 1919 | */ |
| 1920 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1921 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1922 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | /** |
| 1926 | * Posts the specified command to be executed on the main thread, |
| 1927 | * waits for the request to complete, and returns the result. |
| 1928 | * @see #sendRequestAsync |
| 1929 | */ |
| 1930 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1931 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1932 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Posts the specified command to be executed on the main thread, |
| 1937 | * waits for the request to complete, and returns the result. |
| 1938 | * @see #sendRequestAsync |
| 1939 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1940 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1941 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1942 | } |
| 1943 | |
| 1944 | /** |
| 1945 | * Posts the specified command to be executed on the main thread, |
| 1946 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1947 | * if not timeout or null otherwise. |
| 1948 | * @see #sendRequestAsync |
| 1949 | */ |
| 1950 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1951 | long timeoutInMs) { |
| 1952 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1953 | } |
| 1954 | |
| 1955 | /** |
| 1956 | * Posts the specified command to be executed on the main thread, |
| 1957 | * waits for the request to complete, and returns the result. |
| 1958 | * @see #sendRequestAsync |
| 1959 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1960 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1961 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | /** |
| 1965 | * Posts the specified command to be executed on the main thread, |
| 1966 | * waits for the request to complete, and returns the result. |
| 1967 | * @see #sendRequestAsync |
| 1968 | */ |
| 1969 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1970 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1971 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1975 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1976 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1977 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1978 | * @see #sendRequestAsync |
| 1979 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1980 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1981 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1983 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1984 | } |
| 1985 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1986 | MainThreadRequest request = null; |
| 1987 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1988 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1989 | } else if (phone != null) { |
| 1990 | request = new MainThreadRequest(argument, phone, workSource); |
| 1991 | } else { |
| 1992 | request = new MainThreadRequest(argument, subId, workSource); |
| 1993 | } |
| 1994 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1996 | msg.sendToTarget(); |
| 1997 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1998 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2000 | if (timeoutInMs >= 0) { |
| 2001 | // Wait for at least timeoutInMs before returning null request result |
| 2002 | long now = SystemClock.elapsedRealtime(); |
| 2003 | long deadline = now + timeoutInMs; |
| 2004 | while (request == null && now < deadline) { |
| 2005 | try { |
| 2006 | request.wait(deadline - now); |
| 2007 | } catch (InterruptedException e) { |
| 2008 | // Do nothing, go back and check if request is completed or timeout |
| 2009 | } finally { |
| 2010 | now = SystemClock.elapsedRealtime(); |
| 2011 | } |
| 2012 | } |
| 2013 | } else { |
| 2014 | // Wait for the request to complete |
| 2015 | while (request.result == null) { |
| 2016 | try { |
| 2017 | request.wait(); |
| 2018 | } catch (InterruptedException e) { |
| 2019 | // Do nothing, go back and wait until the request is complete |
| 2020 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2024 | if (request.result == null) { |
| 2025 | Log.wtf(LOG_TAG, |
| 2026 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2028 | return request.result; |
| 2029 | } |
| 2030 | |
| 2031 | /** |
| 2032 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2033 | * Posts the specified command to be executed on the main thread, and |
| 2034 | * returns immediately. |
| 2035 | * @see #sendRequest |
| 2036 | */ |
| 2037 | private void sendRequestAsync(int command) { |
| 2038 | mMainThreadHandler.sendEmptyMessage(command); |
| 2039 | } |
| 2040 | |
| 2041 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2042 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2043 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2044 | */ |
| 2045 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2046 | sendRequestAsync(command, argument, null, null); |
| 2047 | } |
| 2048 | |
| 2049 | /** |
| 2050 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2051 | * @see {@link #sendRequest(int,Object)} |
| 2052 | */ |
| 2053 | private void sendRequestAsync( |
| 2054 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2055 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2056 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2057 | msg.sendToTarget(); |
| 2058 | } |
| 2059 | |
| 2060 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2061 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2062 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2063 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2064 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2065 | synchronized (PhoneInterfaceManager.class) { |
| 2066 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2067 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2068 | } else { |
| 2069 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2070 | } |
| 2071 | return sInstance; |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2076 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2077 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2079 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2080 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2082 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2083 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2084 | mTelephonySharedPreferences = |
| 2085 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2086 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2087 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2088 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2089 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2090 | publish(); |
| 2091 | } |
| 2092 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2093 | private Phone getDefaultPhone() { |
| 2094 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2095 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2096 | } |
| 2097 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | private void publish() { |
| 2099 | if (DBG) log("publish: " + this); |
| 2100 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2101 | TelephonyFrameworkInitializer |
| 2102 | .getTelephonyServiceManager() |
| 2103 | .getTelephonyServiceRegisterer() |
| 2104 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2107 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2108 | if (request.phone != null) { |
| 2109 | return request.phone; |
| 2110 | } else { |
| 2111 | return getPhoneFromSubId(request.subId); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | private Phone getPhoneFromSubId(int subId) { |
| 2116 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2117 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2118 | } |
| 2119 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2120 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2121 | Phone phone = getPhoneFromRequest(request); |
| 2122 | return phone == null ? null : |
| 2123 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2124 | } |
| 2125 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2126 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2127 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2128 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2129 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2130 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2131 | private void sendEraseModemConfig(Phone phone) { |
| 2132 | if (phone != null) { |
| 2133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2134 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2135 | final long identity = Binder.clearCallingIdentity(); |
| 2136 | try { |
| 2137 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2138 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2139 | } finally { |
| 2140 | Binder.restoreCallingIdentity(identity); |
| 2141 | } |
| 2142 | } |
| 2143 | } |
| 2144 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2145 | private boolean isImsAvailableOnDevice() { |
| 2146 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2147 | if (pm == null) { |
| 2148 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2149 | // so do not throw error and allow. |
| 2150 | return true; |
| 2151 | } |
| 2152 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2153 | } |
| 2154 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2156 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2159 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | if (DBG) log("dial: " + number); |
| 2161 | // No permission check needed here: This is just a wrapper around the |
| 2162 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2163 | // the UI before it does anything. |
| 2164 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
| 2167 | String url = createTelUrl(number); |
| 2168 | if (url == null) { |
| 2169 | return; |
| 2170 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2172 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2173 | PhoneConstants.State state = mCM.getState(subId); |
| 2174 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2175 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2176 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2177 | mApp.startActivity(intent); |
| 2178 | } |
| 2179 | } finally { |
| 2180 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2185 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2188 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2189 | if (DBG) log("call: " + number); |
| 2190 | |
| 2191 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2192 | // need to do a permission check since we're calling startActivity() |
| 2193 | // from the context of the phone app. |
| 2194 | enforceCallPermission(); |
| 2195 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2196 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | != AppOpsManager.MODE_ALLOWED) { |
| 2198 | return; |
| 2199 | } |
| 2200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2201 | final long identity = Binder.clearCallingIdentity(); |
| 2202 | try { |
| 2203 | String url = createTelUrl(number); |
| 2204 | if (url == null) { |
| 2205 | return; |
| 2206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 | boolean isValid = false; |
| 2209 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2210 | if (slist != null) { |
| 2211 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2212 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2213 | isValid = true; |
| 2214 | break; |
| 2215 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2216 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2217 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2218 | if (!isValid) { |
| 2219 | return; |
| 2220 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2221 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2222 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2223 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2224 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2225 | mApp.startActivity(intent); |
| 2226 | } finally { |
| 2227 | Binder.restoreCallingIdentity(identity); |
| 2228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2231 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2232 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2233 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2234 | } |
| 2235 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2236 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2237 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2238 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2239 | } |
| 2240 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2241 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2243 | |
| 2244 | final long identity = Binder.clearCallingIdentity(); |
| 2245 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2246 | Phone phone = getPhone(subId); |
| 2247 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2248 | checkSimPin.start(); |
| 2249 | return checkSimPin.unlockSim(null, pin); |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
| 2252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2255 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | |
| 2258 | final long identity = Binder.clearCallingIdentity(); |
| 2259 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2260 | Phone phone = getPhone(subId); |
| 2261 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | checkSimPuk.start(); |
| 2263 | return checkSimPuk.unlockSim(puk, pin); |
| 2264 | } finally { |
| 2265 | Binder.restoreCallingIdentity(identity); |
| 2266 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2270 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | * a synchronous one. |
| 2272 | */ |
| 2273 | private static class UnlockSim extends Thread { |
| 2274 | |
| 2275 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2276 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | |
| 2278 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2279 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2280 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | |
| 2282 | // For replies from SimCard interface |
| 2283 | private Handler mHandler; |
| 2284 | |
| 2285 | // For async handler to identify request type |
| 2286 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2287 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2288 | UnlockSim(int phoneId, IccCard simCard) { |
| 2289 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | mSimCard = simCard; |
| 2291 | } |
| 2292 | |
| 2293 | @Override |
| 2294 | public void run() { |
| 2295 | Looper.prepare(); |
| 2296 | synchronized (UnlockSim.this) { |
| 2297 | mHandler = new Handler() { |
| 2298 | @Override |
| 2299 | public void handleMessage(Message msg) { |
| 2300 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2301 | switch (msg.what) { |
| 2302 | case SUPPLY_PIN_COMPLETE: |
| 2303 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2304 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2305 | mRetryCount = msg.arg1; |
| 2306 | if (ar.exception != null) { |
| 2307 | if (ar.exception instanceof CommandException && |
| 2308 | ((CommandException)(ar.exception)).getCommandError() |
| 2309 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2310 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2311 | } //When UiccCardApp dispose,handle message and return exception |
| 2312 | else if (ar.exception instanceof CommandException && |
| 2313 | ((CommandException) (ar.exception)).getCommandError() |
| 2314 | == CommandException.Error.ABORTED) { |
| 2315 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2316 | } else { |
| 2317 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2318 | } |
| 2319 | } else { |
| 2320 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2321 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | mDone = true; |
| 2323 | UnlockSim.this.notifyAll(); |
| 2324 | } |
| 2325 | break; |
| 2326 | } |
| 2327 | } |
| 2328 | }; |
| 2329 | UnlockSim.this.notifyAll(); |
| 2330 | } |
| 2331 | Looper.loop(); |
| 2332 | } |
| 2333 | |
| 2334 | /* |
| 2335 | * Use PIN or PUK to unlock SIM card |
| 2336 | * |
| 2337 | * If PUK is null, unlock SIM card with PIN |
| 2338 | * |
| 2339 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2340 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2341 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | |
| 2343 | while (mHandler == null) { |
| 2344 | try { |
| 2345 | wait(); |
| 2346 | } catch (InterruptedException e) { |
| 2347 | Thread.currentThread().interrupt(); |
| 2348 | } |
| 2349 | } |
| 2350 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2351 | |
| 2352 | if (puk == null) { |
| 2353 | mSimCard.supplyPin(pin, callback); |
| 2354 | } else { |
| 2355 | mSimCard.supplyPuk(puk, pin, callback); |
| 2356 | } |
| 2357 | |
| 2358 | while (!mDone) { |
| 2359 | try { |
| 2360 | Log.d(LOG_TAG, "wait for done"); |
| 2361 | wait(); |
| 2362 | } catch (InterruptedException e) { |
| 2363 | // Restore the interrupted status |
| 2364 | Thread.currentThread().interrupt(); |
| 2365 | } |
| 2366 | } |
| 2367 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2368 | int[] resultArray = new int[2]; |
| 2369 | resultArray[0] = mResult; |
| 2370 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2373 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2374 | } |
| 2375 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2376 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | } |
| 2378 | } |
| 2379 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2380 | /** |
| 2381 | * This method has been removed due to privacy and stability concerns. |
| 2382 | */ |
| 2383 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2384 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2385 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2386 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2389 | @Override |
| 2390 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2391 | mApp.getSystemService(AppOpsManager.class) |
| 2392 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2393 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2394 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2395 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2396 | // Callers targeting S have no business invoking this method. |
| 2397 | return; |
| 2398 | } |
| 2399 | |
| 2400 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2401 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2402 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2403 | .setCallingPackage(callingPackage) |
| 2404 | .setCallingFeatureId(null) |
| 2405 | .setCallingPid(Binder.getCallingPid()) |
| 2406 | .setCallingUid(Binder.getCallingUid()) |
| 2407 | .setMethod("updateServiceLocation") |
| 2408 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2409 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2410 | .build()); |
| 2411 | // Apps that lack location permission have no business calling this method; |
| 2412 | // however, because no permission was declared in the public API, denials must |
| 2413 | // all be "soft". |
| 2414 | switch (locationResult) { |
| 2415 | case DENIED_HARD: /* fall through */ |
| 2416 | case DENIED_SOFT: |
| 2417 | return; |
| 2418 | } |
| 2419 | |
| 2420 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | final long identity = Binder.clearCallingIdentity(); |
| 2422 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2423 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2424 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2425 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | } |
| 2427 | } finally { |
| 2428 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2429 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2432 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2433 | @Override |
| 2434 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2435 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2438 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2439 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2440 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2441 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2442 | callingFeatureId); |
| 2443 | } |
| 2444 | |
| 2445 | @Deprecated |
| 2446 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2447 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2448 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2449 | } |
| 2450 | |
| 2451 | @Override |
| 2452 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2453 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2454 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2455 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2456 | return false; |
| 2457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2458 | |
| 2459 | final long identity = Binder.clearCallingIdentity(); |
| 2460 | try { |
| 2461 | return isRadioOnForSubscriber(subId); |
| 2462 | } finally { |
| 2463 | Binder.restoreCallingIdentity(identity); |
| 2464 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | final long identity = Binder.clearCallingIdentity(); |
| 2469 | try { |
| 2470 | final Phone phone = getPhone(subId); |
| 2471 | if (phone != null) { |
| 2472 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2473 | } else { |
| 2474 | return false; |
| 2475 | } |
| 2476 | } finally { |
| 2477 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2482 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2484 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2485 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2487 | |
| 2488 | final long identity = Binder.clearCallingIdentity(); |
| 2489 | try { |
| 2490 | final Phone phone = getPhone(subId); |
| 2491 | if (phone != null) { |
| 2492 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2493 | } |
| 2494 | } finally { |
| 2495 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2496 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2500 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2503 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2504 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | final Phone phone = getPhone(subId); |
| 2509 | if (phone == null) { |
| 2510 | return false; |
| 2511 | } |
| 2512 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2513 | toggleRadioOnOffForSubscriber(subId); |
| 2514 | } |
| 2515 | return true; |
| 2516 | } finally { |
| 2517 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2518 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2519 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2520 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2521 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2522 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2523 | /* |
| 2524 | * If any of the Radios are available, it will need to be |
| 2525 | * shutdown. So return true if any Radio is available. |
| 2526 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2527 | final long identity = Binder.clearCallingIdentity(); |
| 2528 | try { |
| 2529 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2530 | Phone phone = PhoneFactory.getPhone(i); |
| 2531 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2532 | } |
| 2533 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2534 | return false; |
| 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2537 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2540 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2541 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | enforceModifyPermission(); |
| 2543 | |
| 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2547 | logv("Shutting down Phone " + i); |
| 2548 | shutdownRadioUsingPhoneId(i); |
| 2549 | } |
| 2550 | } finally { |
| 2551 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2556 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2557 | if (phone != null && phone.isRadioAvailable()) { |
| 2558 | phone.shutdownRadio(); |
| 2559 | } |
| 2560 | } |
| 2561 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2568 | if (defaultPhone != null) { |
| 2569 | defaultPhone.setRadioPower(turnOn); |
| 2570 | return true; |
| 2571 | } else { |
| 2572 | loge("There's no default phone."); |
| 2573 | return false; |
| 2574 | } |
| 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2577 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2580 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | final Phone phone = getPhone(subId); |
| 2586 | if (phone != null) { |
| 2587 | phone.setRadioPower(turnOn); |
| 2588 | return true; |
| 2589 | } else { |
| 2590 | return false; |
| 2591 | } |
| 2592 | } finally { |
| 2593 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2594 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2597 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2598 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | public boolean enableDataConnectivity() { |
| 2600 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | |
| 2602 | final long identity = Binder.clearCallingIdentity(); |
| 2603 | try { |
| 2604 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2605 | final Phone phone = getPhone(subId); |
| 2606 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2607 | phone.getDataEnabledSettings().setDataEnabled( |
| 2608 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | return true; |
| 2610 | } else { |
| 2611 | return false; |
| 2612 | } |
| 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2618 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2619 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | public boolean disableDataConnectivity() { |
| 2621 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | |
| 2623 | final long identity = Binder.clearCallingIdentity(); |
| 2624 | try { |
| 2625 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2626 | final Phone phone = getPhone(subId); |
| 2627 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2628 | phone.getDataEnabledSettings().setDataEnabled( |
| 2629 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | return true; |
| 2631 | } else { |
| 2632 | return false; |
| 2633 | } |
| 2634 | } finally { |
| 2635 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2636 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2639 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2640 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | final Phone phone = getPhone(subId); |
| 2644 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2645 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | } else { |
| 2647 | return false; |
| 2648 | } |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2655 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2658 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | enforceCallPermission(); |
| 2660 | |
| 2661 | final long identity = Binder.clearCallingIdentity(); |
| 2662 | try { |
| 2663 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2664 | return; |
| 2665 | } |
| 2666 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2667 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
| 2670 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2671 | }; |
| 2672 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2673 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2674 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | |
| 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
| 2678 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2679 | return false; |
| 2680 | } |
| 2681 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2682 | } finally { |
| 2683 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2684 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2688 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2689 | } |
| 2690 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2691 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | final long identity = Binder.clearCallingIdentity(); |
| 2693 | try { |
| 2694 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2695 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2696 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2697 | } finally { |
| 2698 | Binder.restoreCallingIdentity(identity); |
| 2699 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2702 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2703 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2704 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2705 | } |
| 2706 | |
| 2707 | @Override |
| 2708 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2711 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | if (phone != null) { |
| 2713 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2714 | } else { |
| 2715 | return PhoneConstantConversions.convertDataState( |
| 2716 | PhoneConstants.DataState.DISCONNECTED); |
| 2717 | } |
| 2718 | } finally { |
| 2719 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2720 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2724 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2725 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2726 | } |
| 2727 | |
| 2728 | @Override |
| 2729 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | final long identity = Binder.clearCallingIdentity(); |
| 2731 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2732 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2733 | if (phone != null) { |
| 2734 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2735 | } else { |
| 2736 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2737 | } |
| 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2740 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2744 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2745 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2746 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2747 | |
| 2748 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2749 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2750 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2751 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2752 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2753 | .setCallingPid(Binder.getCallingPid()) |
| 2754 | .setCallingUid(Binder.getCallingUid()) |
| 2755 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2756 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2757 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2758 | .build()); |
| 2759 | switch (locationResult) { |
| 2760 | case DENIED_HARD: |
| 2761 | throw new SecurityException("Not allowed to access cell location"); |
| 2762 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2763 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2764 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | } |
| 2766 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2767 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2768 | final long identity = Binder.clearCallingIdentity(); |
| 2769 | try { |
| 2770 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2771 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2772 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
| 2775 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2778 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2779 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2780 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2781 | // registered cell info, so return a NULL country instead. |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2784 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2785 | // Get default phone in this case. |
| 2786 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2787 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2788 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2789 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2790 | if (phone == null) return ""; |
| 2791 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2792 | if (sst == null) return ""; |
| 2793 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2794 | if (lt == null) return ""; |
| 2795 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2796 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2797 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2798 | } finally { |
| 2799 | Binder.restoreCallingIdentity(identity); |
| 2800 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2803 | /** |
| 2804 | * This method was removed due to potential issues caused by performing partial |
| 2805 | * updates of service state, and lack of a credible use case. |
| 2806 | * |
| 2807 | * This has the ability to break the telephony implementation by disabling notification of |
| 2808 | * changes in device connectivity. DO NOT USE THIS! |
| 2809 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2810 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | public void enableLocationUpdates() { |
| 2812 | mApp.enforceCallingOrSelfPermission( |
| 2813 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2816 | /** |
| 2817 | * This method was removed due to potential issues caused by performing partial |
| 2818 | * updates of service state, and lack of a credible use case. |
| 2819 | * |
| 2820 | * This has the ability to break the telephony implementation by disabling notification of |
| 2821 | * changes in device connectivity. DO NOT USE THIS! |
| 2822 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2823 | @Override |
| 2824 | public void disableLocationUpdates() { |
| 2825 | mApp.enforceCallingOrSelfPermission( |
| 2826 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | @Override |
| 2830 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2831 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2832 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2833 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2834 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2835 | throw new SecurityException( |
| 2836 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2837 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2838 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2839 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2841 | return null; |
| 2842 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2843 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2844 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2846 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2847 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2848 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2849 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2850 | for (CellInfo ci : info) { |
| 2851 | if (ci instanceof CellInfoGsm) { |
| 2852 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2853 | } else if (ci instanceof CellInfoWcdma) { |
| 2854 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2855 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2856 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2857 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2858 | } |
| 2859 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2860 | private List<CellInfo> getCachedCellInfo() { |
| 2861 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2862 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2863 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2864 | if (info != null) cellInfos.addAll(info); |
| 2865 | } |
| 2866 | return cellInfos; |
| 2867 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2868 | |
| 2869 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2870 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2871 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2872 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2873 | |
| 2874 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2875 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2876 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2877 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2878 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2879 | .setCallingPid(Binder.getCallingPid()) |
| 2880 | .setCallingUid(Binder.getCallingUid()) |
| 2881 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2882 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2883 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2884 | .build()); |
| 2885 | switch (locationResult) { |
| 2886 | case DENIED_HARD: |
| 2887 | throw new SecurityException("Not allowed to access cell info"); |
| 2888 | case DENIED_SOFT: |
| 2889 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | } |
| 2891 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2892 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2893 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2894 | return getCachedCellInfo(); |
| 2895 | } |
| 2896 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2897 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2898 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
| 2901 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2902 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2903 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2904 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2905 | if (info != null) cellInfos.addAll(info); |
| 2906 | } |
| 2907 | return cellInfos; |
| 2908 | } finally { |
| 2909 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2913 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2914 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2915 | String callingFeatureId) { |
| 2916 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2917 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2921 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2922 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2923 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2924 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2925 | } |
| 2926 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2927 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2928 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2929 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2930 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2931 | |
| 2932 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2933 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2934 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2935 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2936 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2937 | .setCallingPid(Binder.getCallingPid()) |
| 2938 | .setCallingUid(Binder.getCallingUid()) |
| 2939 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2940 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2941 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2942 | .build()); |
| 2943 | switch (locationResult) { |
| 2944 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2945 | if (TelephonyPermissions |
| 2946 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2947 | // Safetynet logging for b/154934934 |
| 2948 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2949 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2950 | throw new SecurityException("Not allowed to access cell info"); |
| 2951 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2952 | if (TelephonyPermissions |
| 2953 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2954 | // Safetynet logging for b/154934934 |
| 2955 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2956 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2957 | try { |
| 2958 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2959 | } catch (RemoteException re) { |
| 2960 | // Drop without consequences |
| 2961 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2962 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2965 | |
| 2966 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2967 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2968 | |
| 2969 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2974 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2975 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
| 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2979 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(identity); |
| 2982 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2985 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2986 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2987 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2988 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2989 | return null; |
| 2990 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2991 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2992 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2993 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2994 | return null; |
| 2995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | |
| 2997 | final long identity = Binder.clearCallingIdentity(); |
| 2998 | try { |
| 2999 | return phone.getImei(); |
| 3000 | } finally { |
| 3001 | Binder.restoreCallingIdentity(identity); |
| 3002 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3006 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3007 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3008 | String tac = null; |
| 3009 | if (phone != null) { |
| 3010 | String imei = phone.getImei(); |
| 3011 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3012 | } |
| 3013 | return tac; |
| 3014 | } |
| 3015 | |
| 3016 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3017 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3018 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3019 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3020 | return null; |
| 3021 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3022 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3023 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3024 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3025 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3026 | return null; |
| 3027 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | |
| 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | return phone.getMeid(); |
| 3032 | } finally { |
| 3033 | Binder.restoreCallingIdentity(identity); |
| 3034 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3038 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3039 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3040 | String manufacturerCode = null; |
| 3041 | if (phone != null) { |
| 3042 | String meid = phone.getMeid(); |
| 3043 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3044 | } |
| 3045 | return manufacturerCode; |
| 3046 | } |
| 3047 | |
| 3048 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3049 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3050 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3051 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3052 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3053 | return null; |
| 3054 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3055 | int subId = phone.getSubId(); |
| 3056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3057 | mApp, subId, callingPackage, callingFeatureId, |
| 3058 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3059 | return null; |
| 3060 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3061 | |
| 3062 | final long identity = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | return phone.getDeviceSvn(); |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(identity); |
| 3067 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3070 | @Override |
| 3071 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | final long identity = Binder.clearCallingIdentity(); |
| 3073 | try { |
| 3074 | final Phone phone = getPhone(subId); |
| 3075 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3076 | } finally { |
| 3077 | Binder.restoreCallingIdentity(identity); |
| 3078 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | @Override |
| 3082 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | final Phone phone = getPhone(subId); |
| 3086 | return phone == null ? null : phone.getCarrierName(); |
| 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3090 | } |
| 3091 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3092 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3093 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3094 | final long identity = Binder.clearCallingIdentity(); |
| 3095 | try { |
| 3096 | final Phone phone = getPhone(subId); |
| 3097 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3098 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(identity); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3105 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
| 3108 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3109 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(identity); |
| 3112 | } |
| 3113 | } |
| 3114 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3115 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3116 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3117 | if (!isSubscriptionMccMnc) { |
| 3118 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3119 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3120 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3121 | if (phone == null) { |
| 3122 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3123 | } |
| 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
| 3130 | } |
| 3131 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3132 | // |
| 3133 | // Internal helper methods. |
| 3134 | // |
| 3135 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3136 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3137 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3138 | * |
| 3139 | * @throws SecurityException if the caller does not have the required permission |
| 3140 | */ |
| 3141 | private void enforceModifyPermission() { |
| 3142 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3143 | } |
| 3144 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3145 | /** |
| 3146 | * Make sure the caller is system. |
| 3147 | * |
| 3148 | * @throws SecurityException if the caller is not system. |
| 3149 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3150 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3151 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3152 | throw new SecurityException("Caller must be system"); |
| 3153 | } |
| 3154 | } |
| 3155 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3156 | private void enforceActiveEmergencySessionPermission() { |
| 3157 | mApp.enforceCallingOrSelfPermission( |
| 3158 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3159 | } |
| 3160 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3161 | /** |
| 3162 | * Make sure the caller has the CALL_PHONE permission. |
| 3163 | * |
| 3164 | * @throws SecurityException if the caller does not have the required permission |
| 3165 | */ |
| 3166 | private void enforceCallPermission() { |
| 3167 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3168 | } |
| 3169 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3170 | private void enforceSettingsPermission() { |
| 3171 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3174 | private void enforceRebootPermission() { |
| 3175 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3176 | } |
| 3177 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3178 | private String createTelUrl(String number) { |
| 3179 | if (TextUtils.isEmpty(number)) { |
| 3180 | return null; |
| 3181 | } |
| 3182 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3183 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3186 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3187 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3188 | } |
| 3189 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3190 | private static void logv(String msg) { |
| 3191 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3192 | } |
| 3193 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3194 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3195 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3196 | } |
| 3197 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3198 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3199 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3200 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3203 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3204 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | final long identity = Binder.clearCallingIdentity(); |
| 3206 | try { |
| 3207 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3208 | if (phone == null) { |
| 3209 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3210 | } else { |
| 3211 | return phone.getPhoneType(); |
| 3212 | } |
| 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | /** |
| 3219 | * Returns the CDMA ERI icon index to display |
| 3220 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3221 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3222 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3223 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3224 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3225 | } |
| 3226 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3227 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3228 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3229 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3230 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3231 | mApp, subId, callingPackage, callingFeatureId, |
| 3232 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3233 | return -1; |
| 3234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | |
| 3236 | final long identity = Binder.clearCallingIdentity(); |
| 3237 | try { |
| 3238 | final Phone phone = getPhone(subId); |
| 3239 | if (phone != null) { |
| 3240 | return phone.getCdmaEriIconIndex(); |
| 3241 | } else { |
| 3242 | return -1; |
| 3243 | } |
| 3244 | } finally { |
| 3245 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3246 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | /** |
| 3250 | * Returns the CDMA ERI icon mode, |
| 3251 | * 0 - ON |
| 3252 | * 1 - FLASHING |
| 3253 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3254 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3255 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3256 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3257 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3260 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3261 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3262 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3263 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3264 | mApp, subId, callingPackage, callingFeatureId, |
| 3265 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3266 | return -1; |
| 3267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3268 | |
| 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
| 3271 | final Phone phone = getPhone(subId); |
| 3272 | if (phone != null) { |
| 3273 | return phone.getCdmaEriIconMode(); |
| 3274 | } else { |
| 3275 | return -1; |
| 3276 | } |
| 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /** |
| 3283 | * Returns the CDMA ERI text, |
| 3284 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3285 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3286 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3287 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3288 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3289 | } |
| 3290 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3291 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3292 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3293 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3294 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3295 | mApp, subId, callingPackage, callingFeatureId, |
| 3296 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3297 | return null; |
| 3298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3299 | |
| 3300 | final long identity = Binder.clearCallingIdentity(); |
| 3301 | try { |
| 3302 | final Phone phone = getPhone(subId); |
| 3303 | if (phone != null) { |
| 3304 | return phone.getCdmaEriText(); |
| 3305 | } else { |
| 3306 | return null; |
| 3307 | } |
| 3308 | } finally { |
| 3309 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3310 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3314 | * Returns the CDMA MDN. |
| 3315 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3316 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3317 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3318 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3319 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3320 | |
| 3321 | final long identity = Binder.clearCallingIdentity(); |
| 3322 | try { |
| 3323 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3324 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3325 | return phone.getLine1Number(); |
| 3326 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3327 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3328 | return null; |
| 3329 | } |
| 3330 | } finally { |
| 3331 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3332 | } |
| 3333 | } |
| 3334 | |
| 3335 | /** |
| 3336 | * Returns the CDMA MIN. |
| 3337 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3338 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3339 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3341 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | |
| 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | final Phone phone = getPhone(subId); |
| 3346 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3347 | return phone.getCdmaMin(); |
| 3348 | } else { |
| 3349 | return null; |
| 3350 | } |
| 3351 | } finally { |
| 3352 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3353 | } |
| 3354 | } |
| 3355 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3356 | @Override |
| 3357 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3358 | INumberVerificationCallback callback, String callingPackage) { |
| 3359 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3360 | != PERMISSION_GRANTED) { |
| 3361 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3362 | } |
| 3363 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3364 | |
| 3365 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3366 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3367 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3368 | + "calling package: " + callingPackage |
| 3369 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | if (range == null) { |
| 3373 | throw new NullPointerException("Range must be non-null"); |
| 3374 | } |
| 3375 | |
| 3376 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3377 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3378 | |
| 3379 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3380 | } |
| 3381 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3382 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | * Returns true if CDMA provisioning needs to run. |
| 3384 | */ |
| 3385 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3386 | final long identity = Binder.clearCallingIdentity(); |
| 3387 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3388 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
| 3391 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3395 | * Sets the voice mail number of a given subId. |
| 3396 | */ |
| 3397 | @Override |
| 3398 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3399 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3400 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3401 | |
| 3402 | final long identity = Binder.clearCallingIdentity(); |
| 3403 | try { |
| 3404 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3405 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3406 | return success; |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3410 | } |
| 3411 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3412 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3413 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3414 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3415 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3416 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3417 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3418 | throw new SecurityException("caller must be system dialer"); |
| 3419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3424 | if (phoneAccountHandle == null) { |
| 3425 | return null; |
| 3426 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3427 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3430 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3434 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3435 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3436 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3437 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3438 | mApp, subId, callingPackage, callingFeatureId, |
| 3439 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3440 | return null; |
| 3441 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3442 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3443 | final long identity = Binder.clearCallingIdentity(); |
| 3444 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3445 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3446 | } finally { |
| 3447 | Binder.restoreCallingIdentity(identity); |
| 3448 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3452 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3453 | VisualVoicemailSmsFilterSettings settings) { |
| 3454 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3455 | |
| 3456 | final long identity = Binder.clearCallingIdentity(); |
| 3457 | try { |
| 3458 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3459 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3460 | } finally { |
| 3461 | Binder.restoreCallingIdentity(identity); |
| 3462 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3466 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3467 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | |
| 3469 | final long identity = Binder.clearCallingIdentity(); |
| 3470 | try { |
| 3471 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3472 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | } finally { |
| 3474 | Binder.restoreCallingIdentity(identity); |
| 3475 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3479 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3480 | String callingPackage, int subId) { |
| 3481 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3482 | |
| 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3486 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3487 | } finally { |
| 3488 | Binder.restoreCallingIdentity(identity); |
| 3489 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3493 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3495 | |
| 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3499 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3500 | } finally { |
| 3501 | Binder.restoreCallingIdentity(identity); |
| 3502 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3506 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3507 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3508 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3509 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3510 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3511 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3512 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3513 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3514 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3515 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3516 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3517 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3518 | * Sets the voice activation state of a given subId. |
| 3519 | */ |
| 3520 | @Override |
| 3521 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3522 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3523 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3524 | |
| 3525 | final long identity = Binder.clearCallingIdentity(); |
| 3526 | try { |
| 3527 | final Phone phone = getPhone(subId); |
| 3528 | if (phone != null) { |
| 3529 | phone.setVoiceActivationState(activationState); |
| 3530 | } else { |
| 3531 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3532 | } |
| 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | /** |
| 3539 | * Sets the data activation state of a given subId. |
| 3540 | */ |
| 3541 | @Override |
| 3542 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3543 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3544 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | |
| 3546 | final long identity = Binder.clearCallingIdentity(); |
| 3547 | try { |
| 3548 | final Phone phone = getPhone(subId); |
| 3549 | if (phone != null) { |
| 3550 | phone.setDataActivationState(activationState); |
| 3551 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3552 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3553 | } |
| 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3556 | } |
| 3557 | } |
| 3558 | |
| 3559 | /** |
| 3560 | * Returns the voice activation state of a given subId. |
| 3561 | */ |
| 3562 | @Override |
| 3563 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3564 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3566 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3567 | final long identity = Binder.clearCallingIdentity(); |
| 3568 | try { |
| 3569 | if (phone != null) { |
| 3570 | return phone.getVoiceActivationState(); |
| 3571 | } else { |
| 3572 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3573 | } |
| 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | /** |
| 3580 | * Returns the data activation state of a given subId. |
| 3581 | */ |
| 3582 | @Override |
| 3583 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3584 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3585 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3586 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3587 | final long identity = Binder.clearCallingIdentity(); |
| 3588 | try { |
| 3589 | if (phone != null) { |
| 3590 | return phone.getDataActivationState(); |
| 3591 | } else { |
| 3592 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3593 | } |
| 3594 | } finally { |
| 3595 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3600 | * Returns the unread count of voicemails for a subId |
| 3601 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3602 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3603 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3604 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3605 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3606 | mApp, subId, callingPackage, callingFeatureId, |
| 3607 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3608 | return 0; |
| 3609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3610 | final long identity = Binder.clearCallingIdentity(); |
| 3611 | try { |
| 3612 | final Phone phone = getPhone(subId); |
| 3613 | if (phone != null) { |
| 3614 | return phone.getVoiceMessageCount(); |
| 3615 | } else { |
| 3616 | return 0; |
| 3617 | } |
| 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3620 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3624 | * returns true, if the device is in a state where both voice and data |
| 3625 | * are supported simultaneously. This can change based on location or network condition. |
| 3626 | */ |
| 3627 | @Override |
| 3628 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3629 | final long identity = Binder.clearCallingIdentity(); |
| 3630 | try { |
| 3631 | final Phone phone = getPhone(subId); |
| 3632 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(identity); |
| 3635 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3639 | * Send the dialer code if called from the current default dialer or the caller has |
| 3640 | * carrier privilege. |
| 3641 | * @param inputCode The dialer code to send |
| 3642 | */ |
| 3643 | @Override |
| 3644 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3645 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3646 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3647 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3648 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3649 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3650 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3651 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3653 | |
| 3654 | final long identity = Binder.clearCallingIdentity(); |
| 3655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3656 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3660 | } |
| 3661 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3662 | @Override |
| 3663 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3664 | TelephonyPermissions |
| 3665 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3666 | mApp, subId, "getNetworkSelectionMode"); |
| 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | if (!isActiveSubscription(subId)) { |
| 3670 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3671 | } |
| 3672 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3673 | } finally { |
| 3674 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3675 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3678 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3679 | public boolean isInEmergencySmsMode() { |
| 3680 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3684 | if (phone.isInEmergencySmsMode()) { |
| 3685 | return true; |
| 3686 | } |
| 3687 | } |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | return false; |
| 3692 | } |
| 3693 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3694 | /** |
| 3695 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3696 | * @param subId The subscription to use to check the configuration. |
| 3697 | * @param c The callback that will be used to send the result. |
| 3698 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3699 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3700 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3701 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3702 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3703 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3704 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3705 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3706 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3707 | "IMS not available on device."); |
| 3708 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3709 | final long token = Binder.clearCallingIdentity(); |
| 3710 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3711 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3712 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3713 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3714 | } catch (ImsException e) { |
| 3715 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3716 | } finally { |
| 3717 | Binder.restoreCallingIdentity(token); |
| 3718 | } |
| 3719 | } |
| 3720 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3721 | /** |
| 3722 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3723 | * @param subId The subscription to use to check the configuration. |
| 3724 | * @param c The callback that will be used to send the result. |
| 3725 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3726 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3727 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3728 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3729 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3730 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3731 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3732 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3733 | final long token = Binder.clearCallingIdentity(); |
| 3734 | try { |
| 3735 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3736 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3737 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3738 | } catch (ImsException e) { |
| 3739 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3740 | + "is inactive, ignoring unregister."); |
| 3741 | // If the subscription is no longer active, just return, since the callback |
| 3742 | // will already have been removed internally. |
| 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(token); |
| 3745 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3748 | /** |
| 3749 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3750 | */ |
| 3751 | @Override |
| 3752 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3753 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3754 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3756 | "IMS not available on device."); |
| 3757 | } |
| 3758 | final long token = Binder.clearCallingIdentity(); |
| 3759 | try { |
| 3760 | Phone phone = getPhone(subId); |
| 3761 | if (phone == null) { |
| 3762 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3763 | + subId + "'"); |
| 3764 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3765 | } |
| 3766 | phone.getImsRegistrationState(regState -> { |
| 3767 | try { |
| 3768 | consumer.accept((regState == null) |
| 3769 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3770 | } catch (RemoteException e) { |
| 3771 | // Ignore if the remote process is no longer available to call back. |
| 3772 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3773 | } |
| 3774 | }); |
| 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(token); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | /** |
| 3781 | * Get the transport type for the IMS service registration state. |
| 3782 | */ |
| 3783 | @Override |
| 3784 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3785 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3786 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3787 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3789 | "IMS not available on device."); |
| 3790 | } |
| 3791 | final long token = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | Phone phone = getPhone(subId); |
| 3794 | if (phone == null) { |
| 3795 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3796 | + subId + "'"); |
| 3797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3798 | } |
| 3799 | phone.getImsRegistrationTech(regTech -> { |
| 3800 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3801 | int regTechConverted = (regTech == null) |
| 3802 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3803 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3804 | regTechConverted); |
| 3805 | try { |
| 3806 | consumer.accept(regTechConverted); |
| 3807 | } catch (RemoteException e) { |
| 3808 | // Ignore if the remote process is no longer available to call back. |
| 3809 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3810 | } |
| 3811 | }); |
| 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(token); |
| 3814 | } |
| 3815 | } |
| 3816 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3817 | /** |
| 3818 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3819 | * @param subId The subscription to use to check the configuration. |
| 3820 | * @param c The callback that will be used to send the result. |
| 3821 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3823 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3824 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3825 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3826 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3827 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3828 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3829 | "IMS not available on device."); |
| 3830 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3832 | final long token = Binder.clearCallingIdentity(); |
| 3833 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3834 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3835 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3836 | } catch (ImsException e) { |
| 3837 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | } finally { |
| 3839 | Binder.restoreCallingIdentity(token); |
| 3840 | } |
| 3841 | } |
| 3842 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3843 | /** |
| 3844 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3845 | * @param subId The subscription to use to check the configuration. |
| 3846 | * @param c The callback that will be used to send the result. |
| 3847 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3848 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3849 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3850 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3851 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3852 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3853 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3854 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3855 | |
| 3856 | final long token = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3859 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3860 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3861 | } catch (ImsException e) { |
| 3862 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3863 | + "is inactive, ignoring unregister."); |
| 3864 | // If the subscription is no longer active, just return, since the callback |
| 3865 | // will already have been removed internally. |
| 3866 | } finally { |
| 3867 | Binder.restoreCallingIdentity(token); |
| 3868 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3872 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3873 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3874 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3875 | final long token = Binder.clearCallingIdentity(); |
| 3876 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3877 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3879 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3881 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3882 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3883 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3884 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | } finally { |
| 3886 | Binder.restoreCallingIdentity(token); |
| 3887 | } |
| 3888 | } |
| 3889 | |
| 3890 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3891 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3892 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | final long token = Binder.clearCallingIdentity(); |
| 3894 | try { |
| 3895 | Phone phone = getPhone(subId); |
| 3896 | if (phone == null) return false; |
| 3897 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3898 | } catch (com.android.ims.ImsException e) { |
| 3899 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3900 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | } finally { |
| 3902 | Binder.restoreCallingIdentity(token); |
| 3903 | } |
| 3904 | } |
| 3905 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3906 | /** |
| 3907 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3908 | * subscription. |
| 3909 | * @param subId The subscription to use to check the configuration. |
| 3910 | * @param callback The callback that will be used to send the result. |
| 3911 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3912 | * @param transportType The transport type of the MmTelFeature capability. |
| 3913 | */ |
| 3914 | @Override |
| 3915 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3916 | int transportType) { |
| 3917 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3918 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3919 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3920 | "IMS not available on device."); |
| 3921 | } |
| 3922 | final long token = Binder.clearCallingIdentity(); |
| 3923 | try { |
| 3924 | int slotId = getSlotIndex(subId); |
| 3925 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3926 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3927 | + subId + "'"); |
| 3928 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3929 | } |
| 3930 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3931 | transportType, aBoolean -> { |
| 3932 | try { |
| 3933 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3934 | } catch (RemoteException e) { |
| 3935 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3936 | + "running. Ignore"); |
| 3937 | } |
| 3938 | }); |
| 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(token); |
| 3941 | } |
| 3942 | } |
| 3943 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3944 | /** |
| 3945 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3946 | * @param subId The subscription to use to check the configuration. |
| 3947 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | @Override |
| 3949 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3950 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3951 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3952 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3953 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3954 | final long token = Binder.clearCallingIdentity(); |
| 3955 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3956 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3957 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3958 | } catch (ImsException e) { |
| 3959 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3960 | } finally { |
| 3961 | Binder.restoreCallingIdentity(token); |
| 3962 | } |
| 3963 | } |
| 3964 | |
| 3965 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3966 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3968 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3972 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3973 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3974 | } catch (ImsException e) { |
| 3975 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(identity); |
| 3978 | } |
| 3979 | } |
| 3980 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3981 | /** |
| 3982 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3983 | * @param subId The subscription to use to check the configuration. |
| 3984 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3986 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3987 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3988 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | final long identity = Binder.clearCallingIdentity(); |
| 3990 | try { |
| 3991 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3992 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3993 | } catch (ImsException e) { |
| 3994 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | } finally { |
| 3996 | Binder.restoreCallingIdentity(identity); |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4001 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4003 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4004 | final long identity = Binder.clearCallingIdentity(); |
| 4005 | try { |
| 4006 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4007 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4008 | } catch (ImsException e) { |
| 4009 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
| 4012 | } |
| 4013 | } |
| 4014 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4015 | /** |
| 4016 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4017 | * @param subId The subscription to use to check the configuration. |
| 4018 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4019 | @Override |
| 4020 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4021 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4022 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4023 | final long identity = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4026 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4027 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4028 | } catch (ImsException e) { |
| 4029 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4030 | } finally { |
| 4031 | Binder.restoreCallingIdentity(identity); |
| 4032 | } |
| 4033 | } |
| 4034 | |
| 4035 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4036 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4038 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | final long identity = Binder.clearCallingIdentity(); |
| 4040 | try { |
| 4041 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4042 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4043 | } catch (ImsException e) { |
| 4044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(identity); |
| 4047 | } |
| 4048 | } |
| 4049 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4050 | /** |
| 4051 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4052 | * @param subId The subscription to use to check the configuration. |
| 4053 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4054 | @Override |
| 4055 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4056 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4057 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4058 | final long identity = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4061 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4062 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4063 | } catch (ImsException e) { |
| 4064 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4065 | } finally { |
| 4066 | Binder.restoreCallingIdentity(identity); |
| 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4071 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4073 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4077 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4078 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4079 | } catch (ImsException e) { |
| 4080 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4081 | } finally { |
| 4082 | Binder.restoreCallingIdentity(identity); |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | @Override |
| 4087 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4089 | "setVoWiFiNonPersistent"); |
| 4090 | final long identity = Binder.clearCallingIdentity(); |
| 4091 | try { |
| 4092 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4093 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4094 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4095 | } catch (ImsException e) { |
| 4096 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(identity); |
| 4099 | } |
| 4100 | } |
| 4101 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4102 | /** |
| 4103 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4104 | * @param subId The subscription to use to check the configuration. |
| 4105 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4106 | @Override |
| 4107 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4108 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4109 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4110 | final long identity = Binder.clearCallingIdentity(); |
| 4111 | try { |
| 4112 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4113 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4114 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4115 | } catch (ImsException e) { |
| 4116 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4117 | } finally { |
| 4118 | Binder.restoreCallingIdentity(identity); |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | @Override |
| 4123 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4125 | "setVoWiFiModeSetting"); |
| 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4129 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4130 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4131 | } catch (ImsException e) { |
| 4132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | @Override |
| 4139 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4140 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4144 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4146 | } catch (ImsException e) { |
| 4147 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4148 | } finally { |
| 4149 | Binder.restoreCallingIdentity(identity); |
| 4150 | } |
| 4151 | } |
| 4152 | |
| 4153 | @Override |
| 4154 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4155 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4156 | "setVoWiFiRoamingModeSetting"); |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4160 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4162 | } catch (ImsException e) { |
| 4163 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | @Override |
| 4170 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4172 | "setRttCapabilityEnabled"); |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4176 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4177 | } catch (ImsException e) { |
| 4178 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4179 | } finally { |
| 4180 | Binder.restoreCallingIdentity(identity); |
| 4181 | } |
| 4182 | } |
| 4183 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4184 | /** |
| 4185 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4186 | * @param subId The subscription to use to check the configuration. |
| 4187 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4188 | @Override |
| 4189 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4190 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4191 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
| 4194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4195 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4197 | } catch (ImsException e) { |
| 4198 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4199 | } finally { |
| 4200 | Binder.restoreCallingIdentity(identity); |
| 4201 | } |
| 4202 | } |
| 4203 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4204 | @Override |
| 4205 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4206 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4207 | final long identity = Binder.clearCallingIdentity(); |
| 4208 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4209 | if (!isImsAvailableOnDevice()) { |
| 4210 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4211 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4212 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4213 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4214 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4215 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4216 | } catch (ImsException e) { |
| 4217 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
| 4221 | } |
| 4222 | |
| 4223 | @Override |
| 4224 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4225 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4226 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4227 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4228 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4229 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4230 | try { |
| 4231 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4232 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4233 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4234 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4235 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4236 | + "is inactive, ignoring unregister."); |
| 4237 | // If the subscription is no longer active, just return, since the callback will already |
| 4238 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(identity); |
| 4241 | } |
| 4242 | } |
| 4243 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4244 | |
| 4245 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4246 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4247 | message); |
| 4248 | } |
| 4249 | |
| 4250 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4251 | boolean isMmtelCapability) { |
| 4252 | Phone phone = getPhone(subId); |
| 4253 | if (phone == null) { |
| 4254 | loge("phone instance null for subid " + subId); |
| 4255 | return false; |
| 4256 | } |
| 4257 | if (isMmtelCapability) { |
| 4258 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4259 | return false; |
| 4260 | } |
| 4261 | } else { |
| 4262 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4263 | return false; |
| 4264 | } |
| 4265 | } |
| 4266 | return true; |
| 4267 | } |
| 4268 | |
| 4269 | @Override |
| 4270 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4271 | boolean isProvisioned) { |
| 4272 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4273 | |
| 4274 | final long identity = Binder.clearCallingIdentity(); |
| 4275 | try { |
| 4276 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4277 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4278 | return; |
| 4279 | } |
| 4280 | |
| 4281 | // this capability requires provisioning, route to the correct API. |
| 4282 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4283 | switch (capability) { |
| 4284 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4285 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4286 | ims.setEabProvisioned(isProvisioned); |
| 4287 | break; |
| 4288 | default: { |
| 4289 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4290 | + "rcs capability '" + capability + "', which does not require " |
| 4291 | + "provisioning."); |
| 4292 | } |
| 4293 | } |
| 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(identity); |
| 4296 | } |
| 4297 | |
| 4298 | } |
| 4299 | |
| 4300 | |
| 4301 | @Override |
| 4302 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4303 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
| 4306 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4307 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4308 | return true; |
| 4309 | } |
| 4310 | |
| 4311 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4312 | switch (capability) { |
| 4313 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4314 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4315 | return ims.isEabProvisionedOnDevice(); |
| 4316 | |
| 4317 | default: { |
| 4318 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4319 | + "capability '" + capability + "', which does not require " |
| 4320 | + "provisioning."); |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | } finally { |
| 4325 | Binder.restoreCallingIdentity(identity); |
| 4326 | } |
| 4327 | } |
| 4328 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4329 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4330 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4331 | boolean isProvisioned) { |
| 4332 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4333 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4334 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4335 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4336 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4337 | final long identity = Binder.clearCallingIdentity(); |
| 4338 | try { |
| 4339 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4340 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4341 | return; |
| 4342 | } |
| 4343 | |
| 4344 | // this capability requires provisioning, route to the correct API. |
| 4345 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4346 | switch (capability) { |
| 4347 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4348 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4349 | ims.setVolteProvisioned(isProvisioned); |
| 4350 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4351 | ims.setWfcProvisioned(isProvisioned); |
| 4352 | } |
| 4353 | break; |
| 4354 | } |
| 4355 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4356 | // There is currently no difference in VT provisioning type. |
| 4357 | ims.setVtProvisioned(isProvisioned); |
| 4358 | break; |
| 4359 | } |
| 4360 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4361 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4362 | // change the capability of the feature instead if needed. |
| 4363 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4364 | == isProvisioned) { |
| 4365 | // No change in provisioning. |
| 4366 | return; |
| 4367 | } |
| 4368 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4369 | try { |
| 4370 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4371 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4372 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4373 | + ", Exception" + e.getMessage()); |
| 4374 | } |
| 4375 | break; |
| 4376 | } |
| 4377 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4378 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4379 | + "MmTel capability '" + capability + "', which does not require " |
| 4380 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(identity); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | @Override |
| 4390 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4391 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4392 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4393 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4394 | } |
| 4395 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4396 | final long identity = Binder.clearCallingIdentity(); |
| 4397 | try { |
| 4398 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4399 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4400 | return true; |
| 4401 | } |
| 4402 | |
| 4403 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4404 | switch (capability) { |
| 4405 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4406 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4407 | return ims.isVolteProvisionedOnDevice(); |
| 4408 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4409 | return ims.isWfcProvisionedOnDevice(); |
| 4410 | } |
| 4411 | // This should never happen, since we are checking tech above to make sure it |
| 4412 | // is either LTE or IWLAN. |
| 4413 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4414 | + "capability."); |
| 4415 | } |
| 4416 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4417 | // There is currently no difference in VT provisioning type. |
| 4418 | return ims.isVtProvisionedOnDevice(); |
| 4419 | } |
| 4420 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4421 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4422 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4423 | } |
| 4424 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4425 | throw new IllegalArgumentException( |
| 4426 | "Tried to get provisioning for MmTel capability '" + capability |
| 4427 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | @Override |
| 4437 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4438 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4439 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4440 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4441 | } |
| 4442 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4443 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4444 | return (provisionedBits & capability) > 0; |
| 4445 | } |
| 4446 | |
| 4447 | @Override |
| 4448 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4449 | boolean isProvisioned) { |
| 4450 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4451 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4452 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4453 | } |
| 4454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4455 | "setProvisioningStatusForCapability"); |
| 4456 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4457 | // If the current provisioning status for capability already matches isProvisioned, |
| 4458 | // do nothing. |
| 4459 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4460 | return; |
| 4461 | } |
| 4462 | if (isProvisioned) { |
| 4463 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4464 | } else { |
| 4465 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | /** |
| 4470 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4471 | * technology. The bitfield should mirror the bitfield defined by |
| 4472 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4473 | */ |
| 4474 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4475 | String key = getMmTelProvisioningKey(subId, tech); |
| 4476 | // Default is no capabilities are provisioned. |
| 4477 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4478 | } |
| 4479 | |
| 4480 | /** |
| 4481 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4482 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4483 | * technology specified. |
| 4484 | * |
| 4485 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4486 | */ |
| 4487 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4488 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4489 | String key = getMmTelProvisioningKey(subId, tech); |
| 4490 | editor.putInt(key, newField); |
| 4491 | editor.commit(); |
| 4492 | } |
| 4493 | |
| 4494 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4495 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4496 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4497 | } |
| 4498 | |
| 4499 | /** |
| 4500 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4501 | * carrier associated with the subscription id. |
| 4502 | */ |
| 4503 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4504 | int capability) { |
| 4505 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4506 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4507 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4508 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4509 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4510 | false); |
| 4511 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4512 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4513 | |
| 4514 | // First check to make sure that the capability requires provisioning. |
| 4515 | switch (capability) { |
| 4516 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4517 | // intentional fallthrough |
| 4518 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4519 | if (requireVoiceVtProvisioning) { |
| 4520 | // Voice and Video requires provisioning |
| 4521 | return true; |
| 4522 | } |
| 4523 | break; |
| 4524 | } |
| 4525 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4526 | if (requireUtProvisioning) { |
| 4527 | // UT requires provisioning |
| 4528 | return true; |
| 4529 | } |
| 4530 | break; |
| 4531 | } |
| 4532 | } |
| 4533 | return false; |
| 4534 | } |
| 4535 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4536 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4537 | int capability) { |
| 4538 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4539 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4540 | |
| 4541 | boolean requireRcsProvisioning = c.getBoolean( |
| 4542 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4543 | |
| 4544 | // First check to make sure that the capability requires provisioning. |
| 4545 | switch (capability) { |
| 4546 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4547 | // intentional fallthrough |
| 4548 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4549 | if (requireRcsProvisioning) { |
| 4550 | // OPTION or PRESENCE requires provisioning |
| 4551 | return true; |
| 4552 | } |
| 4553 | break; |
| 4554 | } |
| 4555 | } |
| 4556 | return false; |
| 4557 | } |
| 4558 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4559 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4560 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4561 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4562 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4563 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4564 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4565 | final long identity = Binder.clearCallingIdentity(); |
| 4566 | try { |
| 4567 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4568 | int slotId = getSlotIndex(subId); |
| 4569 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4570 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4571 | + subId + "' for key:" + key); |
| 4572 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4573 | } |
| 4574 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4575 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4576 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4577 | + subId + "' for key:" + key); |
| 4578 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | @Override |
| 4585 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4586 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4587 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4588 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4589 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4590 | final long identity = Binder.clearCallingIdentity(); |
| 4591 | try { |
| 4592 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4593 | int slotId = getSlotIndex(subId); |
| 4594 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4595 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4596 | + subId + "' for key:" + key); |
| 4597 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4598 | } |
| 4599 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4600 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4601 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4602 | + subId + "' for key:" + key); |
| 4603 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4604 | } finally { |
| 4605 | Binder.restoreCallingIdentity(identity); |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | @Override |
| 4610 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4611 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4612 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4613 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4615 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4616 | final long identity = Binder.clearCallingIdentity(); |
| 4617 | try { |
| 4618 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4619 | int slotId = getSlotIndex(subId); |
| 4620 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4621 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4622 | + subId + "' for key:" + key); |
| 4623 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4624 | } |
| 4625 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4626 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4627 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4628 | + "' for key:" + key); |
| 4629 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4630 | } finally { |
| 4631 | Binder.restoreCallingIdentity(identity); |
| 4632 | } |
| 4633 | } |
| 4634 | |
| 4635 | @Override |
| 4636 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4637 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4638 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4639 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4641 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4642 | final long identity = Binder.clearCallingIdentity(); |
| 4643 | try { |
| 4644 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4645 | int slotId = getSlotIndex(subId); |
| 4646 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4647 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4648 | + subId + "' for key:" + key); |
| 4649 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4650 | } |
| 4651 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4652 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4653 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4654 | + "' for key:" + key); |
| 4655 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4656 | } finally { |
| 4657 | Binder.restoreCallingIdentity(identity); |
| 4658 | } |
| 4659 | } |
| 4660 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4661 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4662 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4663 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4664 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4665 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | } |
| 4667 | return slotId; |
| 4668 | } |
| 4669 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4670 | private int getSlotIndex(int subId) { |
| 4671 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4672 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4673 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4674 | } |
| 4675 | return slotId; |
| 4676 | } |
| 4677 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4678 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4679 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4680 | */ |
| 4681 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4682 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4683 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4684 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4685 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4686 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4687 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4688 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4689 | mApp, subId, callingPackage, callingFeatureId, |
| 4690 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4691 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4692 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4694 | final long identity = Binder.clearCallingIdentity(); |
| 4695 | try { |
| 4696 | final Phone phone = getPhone(subId); |
| 4697 | if (phone != null) { |
| 4698 | return phone.getServiceState().getDataNetworkType(); |
| 4699 | } else { |
| 4700 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4701 | } |
| 4702 | } finally { |
| 4703 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4704 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | /** |
| 4708 | * Returns the data network type |
| 4709 | */ |
| 4710 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4711 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4712 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4713 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | /** |
| 4717 | * Returns the data network type for a subId |
| 4718 | */ |
| 4719 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4720 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4721 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4722 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4723 | mApp, subId, callingPackage, callingFeatureId, |
| 4724 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4725 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4726 | } |
| 4727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4728 | final long identity = Binder.clearCallingIdentity(); |
| 4729 | try { |
| 4730 | final Phone phone = getPhone(subId); |
| 4731 | if (phone != null) { |
| 4732 | return phone.getServiceState().getDataNetworkType(); |
| 4733 | } else { |
| 4734 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4735 | } |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4739 | } |
| 4740 | |
| 4741 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4742 | * Returns the Voice network type for a subId |
| 4743 | */ |
| 4744 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4745 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4746 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4747 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4748 | mApp, subId, callingPackage, callingFeatureId, |
| 4749 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4750 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4751 | } |
| 4752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4753 | final long identity = Binder.clearCallingIdentity(); |
| 4754 | try { |
| 4755 | final Phone phone = getPhone(subId); |
| 4756 | if (phone != null) { |
| 4757 | return phone.getServiceState().getVoiceNetworkType(); |
| 4758 | } else { |
| 4759 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4760 | } |
| 4761 | } finally { |
| 4762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * @return true if a ICC card is present |
| 4768 | */ |
| 4769 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4770 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4771 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4772 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4773 | } |
| 4774 | |
| 4775 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4776 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4777 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4778 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4779 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4780 | final long identity = Binder.clearCallingIdentity(); |
| 4781 | try { |
| 4782 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4783 | if (phone != null) { |
| 4784 | return phone.getIccCard().hasIccCard(); |
| 4785 | } else { |
| 4786 | return false; |
| 4787 | } |
| 4788 | } finally { |
| 4789 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4790 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
| 4793 | /** |
| 4794 | * Return if the current radio is LTE on CDMA. This |
| 4795 | * is a tri-state return value as for a period of time |
| 4796 | * the mode may be unknown. |
| 4797 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4798 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4799 | * @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] | 4800 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4801 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4802 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4803 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4804 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4805 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4806 | } |
| 4807 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4808 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4809 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4810 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4811 | try { |
| 4812 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4813 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4814 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4815 | } |
| 4816 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4817 | final long identity = Binder.clearCallingIdentity(); |
| 4818 | try { |
| 4819 | final Phone phone = getPhone(subId); |
| 4820 | if (phone == null) { |
| 4821 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4822 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4823 | return TelephonyProperties.lte_on_cdma_device() |
| 4824 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4825 | } |
| 4826 | } finally { |
| 4827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4828 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4829 | } |
| 4830 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4831 | /** |
| 4832 | * {@hide} |
| 4833 | * Returns Default subId, 0 in the case of single standby. |
| 4834 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4835 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4836 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4837 | } |
| 4838 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4839 | private int getSlotForDefaultSubscription() { |
| 4840 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4841 | } |
| 4842 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4843 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4844 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4845 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4846 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4847 | private boolean isActiveSubscription(int subId) { |
| 4848 | return mSubscriptionController.isActiveSubId(subId); |
| 4849 | } |
| 4850 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4851 | /** |
| 4852 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4853 | */ |
| 4854 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4855 | final long identity = Binder.clearCallingIdentity(); |
| 4856 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4857 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4858 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4859 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
| 4862 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | /** |
| 4866 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4867 | */ |
| 4868 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | final long identity = Binder.clearCallingIdentity(); |
| 4870 | try { |
| 4871 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4872 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4873 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4874 | } finally { |
| 4875 | Binder.restoreCallingIdentity(identity); |
| 4876 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4877 | } |
| 4878 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4879 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4880 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4881 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4882 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4883 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4884 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4885 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4886 | if (phoneId == -1) { |
| 4887 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4888 | + " does not correspond to an active phone"); |
| 4889 | } |
| 4890 | return PhoneFactory.getPhone(phoneId); |
| 4891 | } |
| 4892 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4893 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4894 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4895 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4896 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4897 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4898 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4899 | if (DBG) { |
| 4900 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4901 | } |
| 4902 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4903 | p2); |
| 4904 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4905 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4906 | |
| 4907 | @Override |
| 4908 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4909 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4910 | enforceModifyPermission(); |
| 4911 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4912 | if (DBG) { |
| 4913 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4914 | } |
| 4915 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4916 | callingPackage, aid, p2); |
| 4917 | } |
| 4918 | |
| 4919 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4920 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | final long identity = Binder.clearCallingIdentity(); |
| 4922 | try { |
| 4923 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4924 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4925 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4926 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | if (bestComponent == null |
| 4928 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4929 | loge("The calling package is not allowed to access ISD-R."); |
| 4930 | throw new SecurityException( |
| 4931 | "The calling package is not allowed to access ISD-R."); |
| 4932 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4933 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4935 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4936 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4937 | null /* workSource */); |
| 4938 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | return response; |
| 4940 | } finally { |
| 4941 | Binder.restoreCallingIdentity(identity); |
| 4942 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4946 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4948 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4949 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4950 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4951 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4952 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4953 | @Override |
| 4954 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4955 | enforceModifyPermission(); |
| 4956 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4957 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4958 | channel); |
| 4959 | } |
| 4960 | |
| 4961 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4964 | if (channel < 0) { |
| 4965 | return false; |
| 4966 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4967 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4968 | null /* workSource */); |
| 4969 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | return success; |
| 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4973 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4977 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4978 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4979 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4980 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4981 | if (DBG) { |
| 4982 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4983 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4984 | + p3 + " data=" + data); |
| 4985 | } |
| 4986 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4987 | command, p1, p2, p3, data); |
| 4988 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4989 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4990 | @Override |
| 4991 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4992 | int command, int p1, int p2, int p3, String data) { |
| 4993 | enforceModifyPermission(); |
| 4994 | if (DBG) { |
| 4995 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4996 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4997 | + p3 + " data=" + data); |
| 4998 | } |
| 4999 | return iccTransmitApduLogicalChannelWithPermission( |
| 5000 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5001 | data); |
| 5002 | } |
| 5003 | |
| 5004 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5005 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5008 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | return ""; |
| 5010 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5013 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5014 | null /* workSource */); |
| 5015 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | // Append the returned status code to the end of the response payload. |
| 5018 | String s = Integer.toHexString( |
| 5019 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5020 | if (response.payload != null) { |
| 5021 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5022 | } |
| 5023 | return s; |
| 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5026 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5027 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5028 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5029 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5030 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5031 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5032 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5033 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5034 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5035 | if (DBG) { |
| 5036 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5037 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5038 | } |
| 5039 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5040 | cla, command, p1, p2, p3, data); |
| 5041 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5042 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5043 | @Override |
| 5044 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5045 | int command, int p1, int p2, int p3, String data) { |
| 5046 | enforceModifyPermission(); |
| 5047 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5048 | if (DBG) { |
| 5049 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5050 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5051 | + " data=" + data); |
| 5052 | } |
| 5053 | |
| 5054 | return iccTransmitApduBasicChannelWithPermission( |
| 5055 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5056 | p2, p3, data); |
| 5057 | } |
| 5058 | |
| 5059 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5060 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5061 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | final long identity = Binder.clearCallingIdentity(); |
| 5063 | try { |
| 5064 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5065 | && TextUtils.equals(ISDR_AID, data)) { |
| 5066 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5067 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5068 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | if (bestComponent == null |
| 5070 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5071 | loge("The calling package is not allowed to select ISD-R."); |
| 5072 | throw new SecurityException( |
| 5073 | "The calling package is not allowed to select ISD-R."); |
| 5074 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5075 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5077 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5078 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5079 | null /* workSource */); |
| 5080 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5081 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5082 | // Append the returned status code to the end of the response payload. |
| 5083 | String s = Integer.toHexString( |
| 5084 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5085 | if (response.payload != null) { |
| 5086 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5087 | } |
| 5088 | return s; |
| 5089 | } finally { |
| 5090 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5091 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5095 | 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] | 5096 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5098 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5099 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5100 | final long identity = Binder.clearCallingIdentity(); |
| 5101 | try { |
| 5102 | if (DBG) { |
| 5103 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5104 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5105 | } |
| 5106 | |
| 5107 | IccIoResult response = |
| 5108 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5109 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5110 | subId); |
| 5111 | |
| 5112 | if (DBG) { |
| 5113 | log("Exchange SIM_IO [R]" + response); |
| 5114 | } |
| 5115 | |
| 5116 | byte[] result = null; |
| 5117 | int length = 2; |
| 5118 | if (response.payload != null) { |
| 5119 | length = 2 + response.payload.length; |
| 5120 | result = new byte[length]; |
| 5121 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5122 | } else { |
| 5123 | result = new byte[length]; |
| 5124 | } |
| 5125 | |
| 5126 | result[length - 1] = (byte) response.sw2; |
| 5127 | result[length - 2] = (byte) response.sw1; |
| 5128 | return result; |
| 5129 | } finally { |
| 5130 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5131 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5134 | /** |
| 5135 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5136 | * on a particular subscription |
| 5137 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5138 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5139 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5141 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5142 | return null; |
| 5143 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | |
| 5145 | final long identity = Binder.clearCallingIdentity(); |
| 5146 | try { |
| 5147 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5148 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5149 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5150 | return null; |
| 5151 | } |
| 5152 | Object response = sendRequest( |
| 5153 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5154 | if (response instanceof String[]) { |
| 5155 | return (String[]) response; |
| 5156 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5157 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5159 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | } finally { |
| 5161 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5162 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5163 | } |
| 5164 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5165 | /** |
| 5166 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5167 | * subscription. |
| 5168 | * |
| 5169 | * @param subId the id of the subscription. |
| 5170 | * @param appType the uicc app type, must be USIM or SIM. |
| 5171 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5172 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5173 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5174 | * @return number of fplmns that is successfully written to the SIM. |
| 5175 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5176 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5177 | String callingFeatureId) { |
| 5178 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5179 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5180 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5181 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5182 | } |
| 5183 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5184 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5185 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5186 | } |
| 5187 | if (fplmns == null) { |
| 5188 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5189 | } |
| 5190 | for (String fplmn : fplmns) { |
| 5191 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5192 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5193 | } |
| 5194 | } |
| 5195 | final long identity = Binder.clearCallingIdentity(); |
| 5196 | try { |
| 5197 | Object response = sendRequest( |
| 5198 | CMD_SET_FORBIDDEN_PLMNS, |
| 5199 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5200 | subId); |
| 5201 | return (int) response; |
| 5202 | } finally { |
| 5203 | Binder.restoreCallingIdentity(identity); |
| 5204 | } |
| 5205 | } |
| 5206 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5207 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5208 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5210 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5211 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | final long identity = Binder.clearCallingIdentity(); |
| 5213 | try { |
| 5214 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5215 | if (response.payload == null) { |
| 5216 | return ""; |
| 5217 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | // Append the returned status code to the end of the response payload. |
| 5220 | String s = Integer.toHexString( |
| 5221 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5222 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5223 | return s; |
| 5224 | } finally { |
| 5225 | Binder.restoreCallingIdentity(identity); |
| 5226 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5227 | } |
| 5228 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5229 | /** |
| 5230 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5231 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5232 | * |
| 5233 | * @param itemID the ID of the item to read |
| 5234 | * @return the NV item as a String, or null on error. |
| 5235 | */ |
| 5236 | @Override |
| 5237 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5238 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5240 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | |
| 5242 | final long identity = Binder.clearCallingIdentity(); |
| 5243 | try { |
| 5244 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5245 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5247 | return value; |
| 5248 | } finally { |
| 5249 | Binder.restoreCallingIdentity(identity); |
| 5250 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | /** |
| 5254 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5255 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5256 | * |
| 5257 | * @param itemID the ID of the item to read |
| 5258 | * @param itemValue the value to write, as a String |
| 5259 | * @return true on success; false on any failure |
| 5260 | */ |
| 5261 | @Override |
| 5262 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5265 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5266 | |
| 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5270 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5271 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5272 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5273 | return success; |
| 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | /** |
| 5280 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5281 | * Used for device configuration by some CDMA operators. |
| 5282 | * |
| 5283 | * @param preferredRoamingList byte array containing the new PRL |
| 5284 | * @return true on success; false on any failure |
| 5285 | */ |
| 5286 | @Override |
| 5287 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5288 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5289 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | |
| 5291 | final long identity = Binder.clearCallingIdentity(); |
| 5292 | try { |
| 5293 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5294 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5295 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5296 | return success; |
| 5297 | } finally { |
| 5298 | Binder.restoreCallingIdentity(identity); |
| 5299 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
| 5302 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5303 | * 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] | 5304 | * Used for device configuration by some CDMA operators. |
| 5305 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5306 | * @param slotIndex - device slot. |
| 5307 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5308 | * @return true on success; false on any failure |
| 5309 | */ |
| 5310 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5311 | public boolean resetModemConfig(int slotIndex) { |
| 5312 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5313 | if (phone != null) { |
| 5314 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5315 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5316 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5317 | final long identity = Binder.clearCallingIdentity(); |
| 5318 | try { |
| 5319 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5320 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5321 | return success; |
| 5322 | } finally { |
| 5323 | Binder.restoreCallingIdentity(identity); |
| 5324 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5326 | return false; |
| 5327 | } |
| 5328 | |
| 5329 | /** |
| 5330 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5331 | * |
| 5332 | * @param slotIndex - device slot. |
| 5333 | * |
| 5334 | * @return true on success; false on any failure |
| 5335 | */ |
| 5336 | @Override |
| 5337 | public boolean rebootModem(int slotIndex) { |
| 5338 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5339 | if (phone != null) { |
| 5340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5341 | mApp, phone.getSubId(), "rebootModem"); |
| 5342 | |
| 5343 | final long identity = Binder.clearCallingIdentity(); |
| 5344 | try { |
| 5345 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5346 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5347 | return success; |
| 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
| 5351 | } |
| 5352 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5353 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5354 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5355 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5356 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5357 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5358 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5359 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5360 | return new String[0]; |
| 5361 | } |
| 5362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | final long identity = Binder.clearCallingIdentity(); |
| 5364 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5365 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5366 | } finally { |
| 5367 | Binder.restoreCallingIdentity(identity); |
| 5368 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5371 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5372 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5373 | * {@link #disableIms(int)}. |
| 5374 | * @param slotIndex device slot. |
| 5375 | */ |
| 5376 | public void resetIms(int slotIndex) { |
| 5377 | enforceModifyPermission(); |
| 5378 | |
| 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| 5381 | if (mImsResolver == null) { |
| 5382 | // may happen if the does not support IMS. |
| 5383 | return; |
| 5384 | } |
| 5385 | mImsResolver.disableIms(slotIndex); |
| 5386 | mImsResolver.enableIms(slotIndex); |
| 5387 | } finally { |
| 5388 | Binder.restoreCallingIdentity(identity); |
| 5389 | } |
| 5390 | } |
| 5391 | |
| 5392 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5393 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5394 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5395 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5396 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5397 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | |
| 5399 | final long identity = Binder.clearCallingIdentity(); |
| 5400 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5401 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5402 | // may happen if the device does not support IMS. |
| 5403 | return; |
| 5404 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5405 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | } finally { |
| 5407 | Binder.restoreCallingIdentity(identity); |
| 5408 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5412 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5413 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5414 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5415 | public void disableIms(int slotId) { |
| 5416 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | |
| 5418 | final long identity = Binder.clearCallingIdentity(); |
| 5419 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5420 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5421 | // may happen if the device does not support IMS. |
| 5422 | return; |
| 5423 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5424 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | } finally { |
| 5426 | Binder.restoreCallingIdentity(identity); |
| 5427 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5431 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5432 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5433 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5434 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5435 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5436 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5437 | |
| 5438 | final long identity = Binder.clearCallingIdentity(); |
| 5439 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5441 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5442 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5443 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5444 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | } finally { |
| 5446 | Binder.restoreCallingIdentity(identity); |
| 5447 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5448 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5449 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5450 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5451 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5452 | @Override |
| 5453 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5454 | enforceModifyPermission(); |
| 5455 | |
| 5456 | final long identity = Binder.clearCallingIdentity(); |
| 5457 | try { |
| 5458 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5459 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
| 5463 | } |
| 5464 | |
| 5465 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5466 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5467 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5468 | */ |
| 5469 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5470 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5471 | |
| 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5474 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5475 | // may happen if the device does not support IMS. |
| 5476 | return null; |
| 5477 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5478 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5482 | } |
| 5483 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5484 | /** |
| 5485 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5486 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5487 | */ |
| 5488 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5489 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | |
| 5491 | final long identity = Binder.clearCallingIdentity(); |
| 5492 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5493 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5494 | // may happen if the device does not support IMS. |
| 5495 | return null; |
| 5496 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5497 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5498 | } finally { |
| 5499 | Binder.restoreCallingIdentity(identity); |
| 5500 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5501 | } |
| 5502 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5503 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5504 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5505 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5506 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5507 | * @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] | 5508 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5509 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5510 | * @param packageName The name of the package that the current configuration will be replaced |
| 5511 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5512 | * @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] | 5513 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5514 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5515 | int[] featureTypes, String packageName) { |
| 5516 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5517 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5519 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5520 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5524 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5525 | // may happen if the device does not support IMS. |
| 5526 | return false; |
| 5527 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5528 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5529 | for (int featureType : featureTypes) { |
| 5530 | featureConfig.put(featureType, packageName); |
| 5531 | } |
| 5532 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5533 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5534 | } finally { |
| 5535 | Binder.restoreCallingIdentity(identity); |
| 5536 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5540 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5541 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5542 | * |
| 5543 | * This should only be used for testing. |
| 5544 | * |
| 5545 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5546 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5547 | */ |
| 5548 | @Override |
| 5549 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5550 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5551 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5552 | "clearCarrierImsServiceOverride"); |
| 5553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5554 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5555 | "clearCarrierImsServiceOverride"); |
| 5556 | |
| 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
| 5559 | if (mImsResolver == null) { |
| 5560 | // may happen if the device does not support IMS. |
| 5561 | return false; |
| 5562 | } |
| 5563 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5564 | } finally { |
| 5565 | Binder.restoreCallingIdentity(identity); |
| 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5570 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5571 | * |
| 5572 | * @param slotId The slot that the ImsService is associated with. |
| 5573 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5574 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5575 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5576 | * @return the package name of the ImsService configuration. |
| 5577 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5578 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5579 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5580 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5581 | TelephonyPermissions |
| 5582 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5583 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5584 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | final long identity = Binder.clearCallingIdentity(); |
| 5587 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5588 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5589 | // may happen if the device does not support IMS. |
| 5590 | return ""; |
| 5591 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5592 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5593 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5594 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5598 | } |
| 5599 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5600 | /** |
| 5601 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5602 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5603 | * @param callback A callback with an integer containing the |
| 5604 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5605 | */ |
| 5606 | @Override |
| 5607 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5608 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5609 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5610 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5611 | "IMS not available on device."); |
| 5612 | } |
| 5613 | final long token = Binder.clearCallingIdentity(); |
| 5614 | try { |
| 5615 | int slotId = getSlotIndex(subId); |
| 5616 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5617 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5618 | + subId + "'"); |
| 5619 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5620 | } |
| 5621 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5622 | try { |
| 5623 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5624 | } catch (RemoteException e) { |
| 5625 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5626 | + "Ignore"); |
| 5627 | } |
| 5628 | }); |
| 5629 | } finally { |
| 5630 | Binder.restoreCallingIdentity(token); |
| 5631 | } |
| 5632 | } |
| 5633 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5634 | /** |
| 5635 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5636 | */ |
| 5637 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5638 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5642 | // NOTE: Before S, this method only set the default phone. |
| 5643 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5644 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5645 | phone.setImsRegistrationState(registered); |
| 5646 | } |
| 5647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | } finally { |
| 5649 | Binder.restoreCallingIdentity(identity); |
| 5650 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5651 | } |
| 5652 | |
| 5653 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5654 | * Set the network selection mode to automatic. |
| 5655 | * |
| 5656 | */ |
| 5657 | @Override |
| 5658 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5660 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | |
| 5662 | final long identity = Binder.clearCallingIdentity(); |
| 5663 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5664 | if (!isActiveSubscription(subId)) { |
| 5665 | return; |
| 5666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5668 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5669 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | } finally { |
| 5671 | Binder.restoreCallingIdentity(identity); |
| 5672 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5673 | } |
| 5674 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5675 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5676 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5677 | * |
| 5678 | * @param subId the id of the subscription. |
| 5679 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5680 | * the operator to attach to. |
| 5681 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5682 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5683 | * normal network selection next time. |
| 5684 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5685 | */ |
| 5686 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5687 | public boolean setNetworkSelectionModeManual( |
| 5688 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5690 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5691 | |
| 5692 | if (!isActiveSubscription(subId)) { |
| 5693 | return false; |
| 5694 | } |
| 5695 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | final long identity = Binder.clearCallingIdentity(); |
| 5697 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5698 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5700 | if (DBG) { |
| 5701 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5702 | + " operator: " + operatorInfo); |
| 5703 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5708 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5709 | /** |
| 5710 | * Get the manual network selection |
| 5711 | * |
| 5712 | * @param subId the id of the subscription. |
| 5713 | * |
| 5714 | * @return the previously saved user selected PLMN |
| 5715 | */ |
| 5716 | @Override |
| 5717 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5718 | TelephonyPermissions |
| 5719 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5720 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5721 | |
| 5722 | final long identity = Binder.clearCallingIdentity(); |
| 5723 | try { |
| 5724 | if (!isActiveSubscription(subId)) { |
| 5725 | return ""; |
| 5726 | } |
| 5727 | |
| 5728 | final Phone phone = getPhone(subId); |
| 5729 | if (phone == null) { |
| 5730 | return ""; |
| 5731 | } |
| 5732 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5733 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5734 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5735 | } finally { |
| 5736 | Binder.restoreCallingIdentity(identity); |
| 5737 | } |
| 5738 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5739 | |
| 5740 | /** |
| 5741 | * Scans for available networks. |
| 5742 | */ |
| 5743 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5744 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5745 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5747 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5748 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5749 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5750 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5751 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5752 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5753 | .setCallingPid(Binder.getCallingPid()) |
| 5754 | .setCallingUid(Binder.getCallingUid()) |
| 5755 | .setMethod("getCellNetworkScanResults") |
| 5756 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5757 | .build()); |
| 5758 | switch (locationResult) { |
| 5759 | case DENIED_HARD: |
| 5760 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5761 | case DENIED_SOFT: |
| 5762 | return null; |
| 5763 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5765 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | try { |
| 5767 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5768 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | } finally { |
| 5771 | Binder.restoreCallingIdentity(identity); |
| 5772 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5773 | } |
| 5774 | |
| 5775 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5776 | * Get the call forwarding info, given the call forwarding reason. |
| 5777 | */ |
| 5778 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5779 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5780 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5781 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5782 | long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
| 5784 | if (DBG) { |
| 5785 | log("getCallForwarding: subId " + subId |
| 5786 | + " callForwardingReason" + callForwardingReason); |
| 5787 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5788 | |
| 5789 | Phone phone = getPhone(subId); |
| 5790 | if (phone == null) { |
| 5791 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5792 | callback.onError( |
| 5793 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5794 | } catch (RemoteException e) { |
| 5795 | // ignore |
| 5796 | } |
| 5797 | return; |
| 5798 | } |
| 5799 | |
| 5800 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5801 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5802 | @Override |
| 5803 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5804 | try { |
| 5805 | callback.onCallForwardingInfoAvailable(info); |
| 5806 | } catch (RemoteException e) { |
| 5807 | // ignore |
| 5808 | } |
| 5809 | } |
| 5810 | |
| 5811 | @Override |
| 5812 | public void onError(int error) { |
| 5813 | try { |
| 5814 | callback.onError(error); |
| 5815 | } catch (RemoteException e) { |
| 5816 | // ignore |
| 5817 | } |
| 5818 | } |
| 5819 | }); |
| 5820 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5821 | } finally { |
| 5822 | Binder.restoreCallingIdentity(identity); |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | /** |
| 5827 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5828 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5829 | */ |
| 5830 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5831 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5832 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5833 | enforceModifyPermission(); |
| 5834 | long identity = Binder.clearCallingIdentity(); |
| 5835 | try { |
| 5836 | if (DBG) { |
| 5837 | log("setCallForwarding: subId " + subId |
| 5838 | + " callForwardingInfo" + callForwardingInfo); |
| 5839 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5840 | |
| 5841 | Phone phone = getPhone(subId); |
| 5842 | if (phone == null) { |
| 5843 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5844 | callback.accept( |
| 5845 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5846 | } catch (RemoteException e) { |
| 5847 | // ignore |
| 5848 | } |
| 5849 | return; |
| 5850 | } |
| 5851 | |
| 5852 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5853 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5854 | |
| 5855 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5856 | } finally { |
| 5857 | Binder.restoreCallingIdentity(identity); |
| 5858 | } |
| 5859 | } |
| 5860 | |
| 5861 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5862 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5863 | */ |
| 5864 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5865 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5866 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5867 | long identity = Binder.clearCallingIdentity(); |
| 5868 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5869 | |
| 5870 | Phone phone = getPhone(subId); |
| 5871 | if (phone == null) { |
| 5872 | try { |
| 5873 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5874 | } catch (RemoteException e) { |
| 5875 | // ignore |
| 5876 | } |
| 5877 | return; |
| 5878 | } |
| 5879 | |
| 5880 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5881 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5882 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5883 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5884 | } finally { |
| 5885 | Binder.restoreCallingIdentity(identity); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5890 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5891 | */ |
| 5892 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5893 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5894 | enforceModifyPermission(); |
| 5895 | long identity = Binder.clearCallingIdentity(); |
| 5896 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5897 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5898 | |
| 5899 | Phone phone = getPhone(subId); |
| 5900 | if (phone == null) { |
| 5901 | try { |
| 5902 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5903 | } catch (RemoteException e) { |
| 5904 | // ignore |
| 5905 | } |
| 5906 | return; |
| 5907 | } |
| 5908 | |
| 5909 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5910 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5911 | |
| 5912 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5913 | } finally { |
| 5914 | Binder.restoreCallingIdentity(identity); |
| 5915 | } |
| 5916 | } |
| 5917 | |
| 5918 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5919 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5920 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5921 | * @param subId id of the subscription |
| 5922 | * @param request contains the radio access networks with bands/channels to scan |
| 5923 | * @param messenger callback messenger for scan results or errors |
| 5924 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5925 | * @return the id of the requested scan which can be used to stop the scan. |
| 5926 | */ |
| 5927 | @Override |
| 5928 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5929 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5930 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5931 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5932 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5933 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5934 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5935 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5936 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5937 | .setCallingPid(Binder.getCallingPid()) |
| 5938 | .setCallingUid(Binder.getCallingUid()) |
| 5939 | .setMethod("requestNetworkScan") |
| 5940 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5941 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5942 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5943 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5944 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5945 | if (e != null) { |
| 5946 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5947 | throw e; |
| 5948 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5949 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5950 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5951 | } |
| 5952 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5954 | int callingUid = Binder.getCallingUid(); |
| 5955 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5956 | final long identity = Binder.clearCallingIdentity(); |
| 5957 | try { |
| 5958 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5959 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5960 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5961 | } finally { |
| 5962 | Binder.restoreCallingIdentity(identity); |
| 5963 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5964 | } |
| 5965 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5966 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5967 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5968 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5969 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5970 | boolean hasNetworkScanPermission = |
| 5971 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5972 | == PERMISSION_GRANTED; |
| 5973 | |
| 5974 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5975 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5976 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
| 5979 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5980 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5981 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5982 | return new SecurityException("Specific channels must not be" |
| 5983 | + " scanned without location access."); |
| 5984 | } |
| 5985 | } |
| 5986 | } |
| 5987 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5988 | return null; |
| 5989 | } |
| 5990 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5991 | /** |
| 5992 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5993 | * |
| 5994 | * @param subId id of the subscription |
| 5995 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5996 | */ |
| 5997 | @Override |
| 5998 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6000 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6002 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6003 | final long identity = Binder.clearCallingIdentity(); |
| 6004 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6005 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | } finally { |
| 6007 | Binder.restoreCallingIdentity(identity); |
| 6008 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6012 | * Get the calculated preferred network type. |
| 6013 | * Used for debugging incorrect network type. |
| 6014 | * |
| 6015 | * @return the preferred network type, defined in RILConstants.java. |
| 6016 | */ |
| 6017 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6018 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6019 | final Phone defaultPhone = getDefaultPhone(); |
| 6020 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6021 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6022 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 6023 | } |
| 6024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
| 6027 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6028 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
| 6031 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6035 | * Get the preferred network type. |
| 6036 | * Used for device configuration by some CDMA operators. |
| 6037 | * |
| 6038 | * @return the preferred network type, defined in RILConstants.java. |
| 6039 | */ |
| 6040 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6041 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6042 | TelephonyPermissions |
| 6043 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6044 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6045 | |
| 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
| 6048 | if (DBG) log("getPreferredNetworkType"); |
| 6049 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 6050 | int networkType = (result != null ? result[0] : -1); |
| 6051 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 6052 | return networkType; |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
| 6055 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | /** |
| 6059 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6060 | * |
| 6061 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 6062 | * @return true on success; false on any failure. |
| 6063 | */ |
| 6064 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6065 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6067 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | |
| 6069 | final long identity = Binder.clearCallingIdentity(); |
| 6070 | try { |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6071 | Boolean success = (Boolean) sendRequest( |
| 6072 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 6073 | |
| 6074 | if (success) { |
| 6075 | Settings.Global.putInt(mApp.getContentResolver(), |
| 6076 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 6077 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6078 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 6079 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | } finally { |
| 6081 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 6082 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6083 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6084 | |
| 6085 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6086 | * Get the allowed network types that store in the telephony provider. |
| 6087 | * |
| 6088 | * @param subId the id of the subscription. |
| 6089 | * @return allowedNetworkTypes the allowed network types. |
| 6090 | */ |
| 6091 | @Override |
| 6092 | public long getAllowedNetworkTypes(int subId) { |
| 6093 | TelephonyPermissions |
| 6094 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6095 | mApp, subId, "getAllowedNetworkTypes"); |
| 6096 | |
| 6097 | final long identity = Binder.clearCallingIdentity(); |
| 6098 | try { |
| 6099 | return SubscriptionManager.getLongSubscriptionProperty( |
| 6100 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
| 6107 | * Set the allowed network types. |
| 6108 | * |
| 6109 | * @param subId the id of the subscription. |
| 6110 | * @param allowedNetworkTypes the allowed network types. |
| 6111 | * @return true on success; false on any failure. |
| 6112 | */ |
| 6113 | @Override |
| 6114 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 6115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6116 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6117 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6118 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6119 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6120 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6121 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6122 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6123 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6124 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6125 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6126 | } |
| 6127 | |
| 6128 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6129 | * Get the allowed network types for certain reason. |
| 6130 | * |
| 6131 | * @param subId the id of the subscription. |
| 6132 | * @param reason the reason the allowed network type change is taking place |
| 6133 | * @return the allowed network types. |
| 6134 | */ |
| 6135 | @Override |
| 6136 | public long getAllowedNetworkTypesForReason(int subId, |
| 6137 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6138 | TelephonyPermissions |
| 6139 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6140 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
| 6143 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6144 | } finally { |
| 6145 | Binder.restoreCallingIdentity(identity); |
| 6146 | } |
| 6147 | } |
| 6148 | |
| 6149 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6150 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6151 | * @param subId subscription id of the sim card |
| 6152 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6153 | * This can be passed following states |
| 6154 | * <ol> |
| 6155 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6156 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6157 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6158 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6159 | * </ol> |
| 6160 | * @return operation result. |
| 6161 | */ |
| 6162 | @Override |
| 6163 | public int setNrDualConnectivityState(int subId, |
| 6164 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6166 | mApp, subId, "enableNRDualConnectivity"); |
| 6167 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6168 | final long identity = Binder.clearCallingIdentity(); |
| 6169 | try { |
| 6170 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6171 | nrDualConnectivityState, subId, |
| 6172 | workSource); |
| 6173 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6174 | return result; |
| 6175 | } finally { |
| 6176 | Binder.restoreCallingIdentity(identity); |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | /** |
| 6181 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6182 | * @return true if dual connectivity is enabled else false |
| 6183 | */ |
| 6184 | @Override |
| 6185 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6186 | TelephonyPermissions |
| 6187 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6188 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6189 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6190 | final long identity = Binder.clearCallingIdentity(); |
| 6191 | try { |
| 6192 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6193 | null, subId, workSource); |
| 6194 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6195 | return isEnabled; |
| 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
| 6199 | } |
| 6200 | |
| 6201 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6202 | * get carrier bandwidth per primary and secondary carrier |
| 6203 | * @param subId subscription id of the sim card |
| 6204 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6205 | */ |
| 6206 | @Override |
| 6207 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6208 | TelephonyPermissions |
| 6209 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6210 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6211 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6212 | final long identity = Binder.clearCallingIdentity(); |
| 6213 | try { |
| 6214 | CarrierBandwidth carrierBandwidth = |
| 6215 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6216 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6217 | return carrierBandwidth; |
| 6218 | } finally { |
| 6219 | Binder.restoreCallingIdentity(identity); |
| 6220 | } |
| 6221 | } |
| 6222 | |
| 6223 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6224 | * Get the effective allowed network types on the device. |
| 6225 | * This API will return an intersection of allowed network types for all reasons, |
| 6226 | * including the configuration done through setAllowedNetworkTypes |
| 6227 | * |
| 6228 | * @param subId the id of the subscription. |
| 6229 | * @return the allowed network types |
| 6230 | */ |
| 6231 | @Override |
| 6232 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6233 | TelephonyPermissions |
| 6234 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6235 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6236 | final long identity = Binder.clearCallingIdentity(); |
| 6237 | try { |
| 6238 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | /** |
| 6245 | * Set the allowed network types of the device and |
| 6246 | * provide the reason triggering the allowed network change. |
| 6247 | * |
| 6248 | * @param subId the id of the subscription. |
| 6249 | * @param reason the reason the allowed network type change is taking place |
| 6250 | * @param allowedNetworkTypes the allowed network types. |
| 6251 | * @return true on success; false on any failure. |
| 6252 | */ |
| 6253 | @Override |
| 6254 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6255 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6256 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6257 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6258 | final long identity = Binder.clearCallingIdentity(); |
| 6259 | try { |
| 6260 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6261 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6262 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6263 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6264 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6265 | } finally { |
| 6266 | Binder.restoreCallingIdentity(identity); |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6271 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6272 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6273 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6274 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6275 | * @hide |
| 6276 | */ |
| 6277 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6278 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6279 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6280 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6281 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6283 | if (phone != null) { |
| 6284 | return phone.hasMatchedTetherApnSetting(); |
| 6285 | } else { |
| 6286 | return false; |
| 6287 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | } finally { |
| 6289 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6290 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6294 | * Enable or disable always reporting signal strength changes from radio. |
| 6295 | * |
| 6296 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6297 | */ |
| 6298 | @Override |
| 6299 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6300 | enforceModifyPermission(); |
| 6301 | enforceSystemCaller(); |
| 6302 | |
| 6303 | final long identity = Binder.clearCallingIdentity(); |
| 6304 | final Phone phone = getPhone(subId); |
| 6305 | try { |
| 6306 | if (phone != null) { |
| 6307 | if (DBG) { |
| 6308 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6309 | + " isEnable=" + isEnable); |
| 6310 | } |
| 6311 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6312 | } else { |
| 6313 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6314 | + subId); |
| 6315 | } |
| 6316 | } finally { |
| 6317 | Binder.restoreCallingIdentity(identity); |
| 6318 | } |
| 6319 | } |
| 6320 | |
| 6321 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6322 | * Get the user enabled state of Mobile Data. |
| 6323 | * |
| 6324 | * TODO: remove and use isUserDataEnabled. |
| 6325 | * This can't be removed now because some vendor codes |
| 6326 | * calls through ITelephony directly while they should |
| 6327 | * use TelephonyManager. |
| 6328 | * |
| 6329 | * @return true on enabled |
| 6330 | */ |
| 6331 | @Override |
| 6332 | public boolean getDataEnabled(int subId) { |
| 6333 | return isUserDataEnabled(subId); |
| 6334 | } |
| 6335 | |
| 6336 | /** |
| 6337 | * Get whether mobile data is enabled per user setting. |
| 6338 | * |
| 6339 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6340 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6341 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6342 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6343 | * |
| 6344 | * @return {@code true} if data is enabled else {@code false} |
| 6345 | */ |
| 6346 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6347 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6348 | try { |
| 6349 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6350 | null); |
| 6351 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6353 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6354 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6355 | |
| 6356 | final long identity = Binder.clearCallingIdentity(); |
| 6357 | try { |
| 6358 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6359 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6360 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6361 | if (phone != null) { |
| 6362 | boolean retVal = phone.isUserDataEnabled(); |
| 6363 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6364 | return retVal; |
| 6365 | } else { |
| 6366 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6367 | return false; |
| 6368 | } |
| 6369 | } finally { |
| 6370 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6371 | } |
| 6372 | } |
| 6373 | |
| 6374 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6375 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6376 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6377 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6378 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6379 | * @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] | 6380 | */ |
| 6381 | @Override |
| 6382 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6383 | try { |
| 6384 | try { |
| 6385 | mApp.enforceCallingOrSelfPermission( |
| 6386 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6387 | null); |
| 6388 | } catch (Exception e) { |
| 6389 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6390 | "isDataEnabled"); |
| 6391 | } |
| 6392 | } catch (Exception e) { |
| 6393 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6394 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6395 | |
| 6396 | final long identity = Binder.clearCallingIdentity(); |
| 6397 | try { |
| 6398 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6399 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6400 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6401 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6402 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6403 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6404 | return retVal; |
| 6405 | } else { |
| 6406 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6407 | return false; |
| 6408 | } |
| 6409 | } finally { |
| 6410 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6411 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6412 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6413 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6414 | /** |
| 6415 | * Check if data is enabled for a specific reason |
| 6416 | * @param subId Subscription index |
| 6417 | * @param reason the reason the data enable change is taking place |
| 6418 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6419 | */ |
| 6420 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6421 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6422 | @TelephonyManager.DataEnabledReason int reason) { |
| 6423 | try { |
| 6424 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6425 | null); |
| 6426 | } catch (Exception e) { |
| 6427 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6428 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | |
| 6432 | final long identity = Binder.clearCallingIdentity(); |
| 6433 | try { |
| 6434 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6435 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6436 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6437 | + " reason=" + reason); |
| 6438 | } |
| 6439 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6440 | if (phone != null) { |
| 6441 | boolean retVal; |
| 6442 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6443 | retVal = phone.isUserDataEnabled(); |
| 6444 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6445 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6446 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6447 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6448 | return retVal; |
| 6449 | } else { |
| 6450 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6451 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6452 | + subId + " retVal=false"); |
| 6453 | } |
| 6454 | return false; |
| 6455 | } |
| 6456 | } finally { |
| 6457 | Binder.restoreCallingIdentity(identity); |
| 6458 | } |
| 6459 | } |
| 6460 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6461 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6462 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6463 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6464 | // Skip the check if it's one of these special uids |
| 6465 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6466 | } |
| 6467 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6468 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6469 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6470 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6471 | || subController == null) return privilegeFromSim; |
| 6472 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6473 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6474 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6475 | |
| 6476 | final long identity = Binder.clearCallingIdentity(); |
| 6477 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6478 | int subId = phone.getSubId(); |
| 6479 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6480 | // A test override is in place for the privileges for this subId, so don't try to |
| 6481 | // read the subscription privileges. |
| 6482 | return privilegeFromSim; |
| 6483 | } |
| 6484 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6485 | SubscriptionManager subManager = (SubscriptionManager) |
| 6486 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6487 | for (String pkg : packages) { |
| 6488 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6489 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6490 | } |
| 6491 | } |
| 6492 | return privilegeFromSim; |
| 6493 | } finally { |
| 6494 | Binder.restoreCallingIdentity(identity); |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6499 | String pkgName) { |
| 6500 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6501 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6502 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6503 | || subController == null) return privilegeFromSim; |
| 6504 | |
| 6505 | final long identity = Binder.clearCallingIdentity(); |
| 6506 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6507 | int subId = phone.getSubId(); |
| 6508 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6509 | // A test override is in place for the privileges for this subId, so don't try to |
| 6510 | // read the subscription privileges. |
| 6511 | return privilegeFromSim; |
| 6512 | } |
| 6513 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6514 | SubscriptionManager subManager = (SubscriptionManager) |
| 6515 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6516 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6517 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6518 | } finally { |
| 6519 | Binder.restoreCallingIdentity(identity); |
| 6520 | } |
| 6521 | } |
| 6522 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6523 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6524 | public int getCarrierPrivilegeStatus(int subId) { |
| 6525 | final Phone phone = getPhone(subId); |
| 6526 | if (phone == null) { |
| 6527 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6528 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6529 | } |
| 6530 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6531 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6532 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6533 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6534 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6535 | |
| 6536 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6537 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6538 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6539 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6540 | |
| 6541 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6542 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6543 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6544 | final Phone phone = getPhone(subId); |
| 6545 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6546 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6547 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6548 | } |
| 6549 | UiccProfile profile = |
| 6550 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6551 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6552 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6553 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6554 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6555 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6556 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6557 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6561 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6562 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6563 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6564 | } |
| 6565 | |
| 6566 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6567 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6568 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6569 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6570 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6571 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6572 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6573 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6574 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6575 | } |
| 6576 | |
| 6577 | @Override |
| 6578 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6579 | if (TextUtils.isEmpty(pkgName)) |
| 6580 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6581 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6582 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6583 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6584 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6585 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6586 | continue; |
| 6587 | } |
| 6588 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6589 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6590 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6591 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6592 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6593 | break; |
| 6594 | } |
| 6595 | } |
| 6596 | |
| 6597 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6598 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6599 | |
| 6600 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6601 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6602 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6603 | loge("phoneId " + phoneId + " is not valid."); |
| 6604 | return null; |
| 6605 | } |
| 6606 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6607 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6608 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6609 | return null ; |
| 6610 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6611 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6612 | } |
| 6613 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6614 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6615 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6616 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6617 | List<String> privilegedPackages = new ArrayList<>(); |
| 6618 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6619 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6620 | // has UICC in that slot. |
| 6621 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6622 | if (card.hasCarrierPrivilegeRules()) { |
| 6623 | if (packages == null) { |
| 6624 | // Only check packages in user 0 for now |
| 6625 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6626 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6627 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6628 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6629 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6630 | } |
| 6631 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6632 | PackageInfo pkgInfo = packages.get(p); |
| 6633 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6634 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6635 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6636 | privilegedPackages.add(pkgInfo.packageName); |
| 6637 | } |
| 6638 | } |
| 6639 | } |
| 6640 | } |
| 6641 | return privilegedPackages; |
| 6642 | } |
| 6643 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6644 | @Override |
| 6645 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6646 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6647 | |
| 6648 | final long identity = Binder.clearCallingIdentity(); |
| 6649 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6650 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6651 | try { |
| 6652 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6653 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6654 | } |
| 6655 | } finally { |
| 6656 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6657 | } |
| 6658 | return privilegedPackages; |
| 6659 | } |
| 6660 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6661 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6662 | final Phone phone = getPhone(subId); |
| 6663 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6664 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6665 | return null; |
| 6666 | } |
| 6667 | String iccId = card.getIccId(); |
| 6668 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6669 | return null; |
| 6670 | } |
| 6671 | return iccId; |
| 6672 | } |
| 6673 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6674 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6675 | public void setCallComposerStatus(int subId, int status) { |
| 6676 | enforceModifyPermission(); |
| 6677 | |
| 6678 | final long identity = Binder.clearCallingIdentity(); |
| 6679 | try { |
| 6680 | Phone phone = getPhone(subId); |
| 6681 | if (phone != null) { |
| 6682 | Phone defaultPhone = phone.getImsPhone(); |
| 6683 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6684 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6685 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6686 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6687 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6688 | } |
| 6689 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6690 | } catch (ImsException e) { |
| 6691 | throw new ServiceSpecificException(e.getCode()); |
| 6692 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6693 | Binder.restoreCallingIdentity(identity); |
| 6694 | } |
| 6695 | } |
| 6696 | |
| 6697 | @Override |
| 6698 | public int getCallComposerStatus(int subId) { |
| 6699 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6700 | |
| 6701 | final long identity = Binder.clearCallingIdentity(); |
| 6702 | try { |
| 6703 | Phone phone = getPhone(subId); |
| 6704 | if (phone != null) { |
| 6705 | Phone defaultPhone = phone.getImsPhone(); |
| 6706 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6707 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6708 | return imsPhone.getCallComposerStatus(); |
| 6709 | } |
| 6710 | } |
| 6711 | } finally { |
| 6712 | Binder.restoreCallingIdentity(identity); |
| 6713 | } |
| 6714 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6715 | } |
| 6716 | |
| 6717 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6718 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6719 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6720 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6721 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | final long identity = Binder.clearCallingIdentity(); |
| 6724 | try { |
| 6725 | final String iccId = getIccId(subId); |
| 6726 | final Phone phone = getPhone(subId); |
| 6727 | if (phone == null) { |
| 6728 | return false; |
| 6729 | } |
| 6730 | final String subscriberId = phone.getSubscriberId(); |
| 6731 | |
| 6732 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6733 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6734 | + subscriberId + " to " + number); |
| 6735 | } |
| 6736 | |
| 6737 | if (TextUtils.isEmpty(iccId)) { |
| 6738 | return false; |
| 6739 | } |
| 6740 | |
| 6741 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6742 | |
| 6743 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6744 | if (alphaTag == null) { |
| 6745 | editor.remove(alphaTagPrefKey); |
| 6746 | } else { |
| 6747 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6748 | } |
| 6749 | |
| 6750 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6751 | // track all merged IMSIs based on line number |
| 6752 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6753 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6754 | if (number == null) { |
| 6755 | editor.remove(numberPrefKey); |
| 6756 | editor.remove(subscriberPrefKey); |
| 6757 | } else { |
| 6758 | editor.putString(numberPrefKey, number); |
| 6759 | editor.putString(subscriberPrefKey, subscriberId); |
| 6760 | } |
| 6761 | |
| 6762 | editor.commit(); |
| 6763 | return true; |
| 6764 | } finally { |
| 6765 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6766 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6770 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6771 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6772 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6773 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6774 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6775 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6776 | return null; |
| 6777 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
| 6781 | String iccId = getIccId(subId); |
| 6782 | if (iccId != null) { |
| 6783 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6784 | if (DBG_MERGE) { |
| 6785 | log("getLine1NumberForDisplay returning " |
| 6786 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6787 | } |
| 6788 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6791 | return null; |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6794 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6795 | } |
| 6796 | |
| 6797 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6798 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6799 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6800 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6801 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6802 | return null; |
| 6803 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6804 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | final long identity = Binder.clearCallingIdentity(); |
| 6806 | try { |
| 6807 | String iccId = getIccId(subId); |
| 6808 | if (iccId != null) { |
| 6809 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6810 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6811 | } |
| 6812 | return null; |
| 6813 | } finally { |
| 6814 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6815 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6816 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6817 | |
| 6818 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6819 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6820 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6821 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6822 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6823 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6824 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6825 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6826 | return null; |
| 6827 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6828 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6829 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6830 | // the process, where TelephonyManager was instantiated. |
| 6831 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6832 | final long identity = Binder.clearCallingIdentity(); |
| 6833 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6834 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6835 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6836 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6837 | |
| 6838 | // Figure out what subscribers are currently active |
| 6839 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6841 | // Only consider subs which match the current subId |
| 6842 | // This logic can be simplified. See b/131189269 for progress. |
| 6843 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6844 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6845 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6846 | |
| 6847 | // First pass, find a number override for an active subscriber |
| 6848 | String mergeNumber = null; |
| 6849 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6850 | for (String key : prefs.keySet()) { |
| 6851 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6852 | final String subscriberId = (String) prefs.get(key); |
| 6853 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6854 | final String iccId = key.substring( |
| 6855 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6856 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6857 | mergeNumber = (String) prefs.get(numberKey); |
| 6858 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6859 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | + " for active subscriber " + subscriberId); |
| 6861 | } |
| 6862 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6863 | break; |
| 6864 | } |
| 6865 | } |
| 6866 | } |
| 6867 | } |
| 6868 | |
| 6869 | // Shortcut when no active merged subscribers |
| 6870 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6871 | return null; |
| 6872 | } |
| 6873 | |
| 6874 | // Second pass, find all subscribers under that line override |
| 6875 | final ArraySet<String> result = new ArraySet<>(); |
| 6876 | for (String key : prefs.keySet()) { |
| 6877 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6878 | final String number = (String) prefs.get(key); |
| 6879 | if (mergeNumber.equals(number)) { |
| 6880 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6881 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6882 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6883 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6884 | result.add(subscriberId); |
| 6885 | } |
| 6886 | } |
| 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6891 | Arrays.sort(resultArray); |
| 6892 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6893 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6895 | } |
| 6896 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6897 | } finally { |
| 6898 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6899 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6903 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6904 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6905 | |
| 6906 | final long identity = Binder.clearCallingIdentity(); |
| 6907 | try { |
| 6908 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6909 | TelephonyManager.class); |
| 6910 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6911 | if (subscriberId == null) { |
| 6912 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6913 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6914 | + subId); |
| 6915 | } |
| 6916 | return null; |
| 6917 | } |
| 6918 | |
| 6919 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6920 | .getSubscriptionInfo(subId); |
| 6921 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6922 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6923 | if (groupUuid == null) { |
| 6924 | return new String[]{subscriberId}; |
| 6925 | } |
| 6926 | |
| 6927 | // Get all subscriberIds from the group. |
| 6928 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6929 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6930 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6931 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6932 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6933 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6934 | if (subscriberId != null) { |
| 6935 | mergedSubscriberIds.add(subscriberId); |
| 6936 | } |
| 6937 | } |
| 6938 | |
| 6939 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6940 | } finally { |
| 6941 | Binder.restoreCallingIdentity(identity); |
| 6942 | |
| 6943 | } |
| 6944 | } |
| 6945 | |
| 6946 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6947 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6948 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6949 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
| 6952 | try { |
| 6953 | final Phone phone = getPhone(subId); |
| 6954 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6955 | } finally { |
| 6956 | Binder.restoreCallingIdentity(identity); |
| 6957 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6958 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6959 | |
| 6960 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6961 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6962 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6963 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6964 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6965 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6966 | |
| 6967 | final long identity = Binder.clearCallingIdentity(); |
| 6968 | try { |
| 6969 | final Phone phone = getPhone(subId); |
| 6970 | if (phone == null) { |
| 6971 | return false; |
| 6972 | } |
| 6973 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6974 | cdmaNonRoamingList); |
| 6975 | } finally { |
| 6976 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6977 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6978 | } |
| 6979 | |
| 6980 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6981 | @Deprecated |
| 6982 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6983 | enforceModifyPermission(); |
| 6984 | |
| 6985 | int returnValue = 0; |
| 6986 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6987 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6988 | if(result.exception == null) { |
| 6989 | if (result.result != null) { |
| 6990 | byte[] responseData = (byte[])(result.result); |
| 6991 | if(responseData.length > oemResp.length) { |
| 6992 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6993 | responseData.length + "bytes. Buffer Size is " + |
| 6994 | oemResp.length + "bytes."); |
| 6995 | } |
| 6996 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6997 | returnValue = responseData.length; |
| 6998 | } |
| 6999 | } else { |
| 7000 | CommandException ex = (CommandException) result.exception; |
| 7001 | returnValue = ex.getCommandError().ordinal(); |
| 7002 | if(returnValue > 0) returnValue *= -1; |
| 7003 | } |
| 7004 | } catch (RuntimeException e) { |
| 7005 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7006 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7007 | if(returnValue > 0) returnValue *= -1; |
| 7008 | } |
| 7009 | |
| 7010 | return returnValue; |
| 7011 | } |
| 7012 | |
| 7013 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7014 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 7015 | try { |
| 7016 | ProxyController.getInstance().setRadioCapability(rafs); |
| 7017 | } catch (RuntimeException e) { |
| 7018 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 7019 | } |
| 7020 | } |
| 7021 | |
| 7022 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7023 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7024 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7025 | try { |
| 7026 | TelephonyPermissions |
| 7027 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7028 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7029 | } catch (SecurityException e) { |
| 7030 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7031 | throw e; |
| 7032 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7033 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7034 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7035 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | final long identity = Binder.clearCallingIdentity(); |
| 7038 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7039 | TelephonyPermissions |
| 7040 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 7041 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7042 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | } finally { |
| 7044 | Binder.restoreCallingIdentity(identity); |
| 7045 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7046 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7047 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7048 | |
| 7049 | @Override |
| 7050 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7051 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7052 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | |
| 7054 | final long identity = Binder.clearCallingIdentity(); |
| 7055 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7056 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7057 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | } finally { |
| 7059 | Binder.restoreCallingIdentity(identity); |
| 7060 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7064 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7065 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7067 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7068 | return false; |
| 7069 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7071 | final long identity = Binder.clearCallingIdentity(); |
| 7072 | try { |
| 7073 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7074 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7075 | // In the long run, we may instead need to check if there exists a connection service |
| 7076 | // which can support video calling. |
| 7077 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7078 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | return imsManager.isVtEnabledByPlatform() |
| 7080 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7081 | && imsManager.isVtEnabledByUser(); |
| 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
| 7084 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7085 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7086 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7087 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7088 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7089 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7091 | mApp, subId, callingPackage, callingFeatureId, |
| 7092 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7093 | return false; |
| 7094 | } |
| 7095 | |
| 7096 | final long identity = Binder.clearCallingIdentity(); |
| 7097 | try { |
| 7098 | CarrierConfigManager configManager = |
| 7099 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7100 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7101 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7102 | } finally { |
| 7103 | Binder.restoreCallingIdentity(identity); |
| 7104 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7108 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7110 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7111 | return false; |
| 7112 | } |
| 7113 | |
| 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
| 7116 | CarrierConfigManager configManager = |
| 7117 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7118 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7120 | } finally { |
| 7121 | Binder.restoreCallingIdentity(identity); |
| 7122 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7123 | } |
| 7124 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7125 | @Override |
| 7126 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7127 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7128 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | @Override |
| 7132 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7133 | final long identity = Binder.clearCallingIdentity(); |
| 7134 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7135 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | } finally { |
| 7137 | Binder.restoreCallingIdentity(identity); |
| 7138 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7141 | /** |
| 7142 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7143 | * support for the feature and device firmware support. |
| 7144 | * |
| 7145 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7146 | */ |
| 7147 | @Override |
| 7148 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7150 | final Phone phone = getPhone(subscriptionId); |
| 7151 | if (phone == null) { |
| 7152 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7153 | return false; |
| 7154 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7155 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7156 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7158 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7159 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | return isCarrierSupported && isDeviceSupported; |
| 7161 | } finally { |
| 7162 | Binder.restoreCallingIdentity(identity); |
| 7163 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7164 | } |
| 7165 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7166 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7167 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7168 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7169 | * 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] | 7170 | */ |
| 7171 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7172 | final long identity = Binder.clearCallingIdentity(); |
| 7173 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7174 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7175 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7176 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7177 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7178 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7179 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
| 7182 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7183 | } |
| 7184 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7185 | @Deprecated |
| 7186 | @Override |
| 7187 | public String getDeviceId(String callingPackage) { |
| 7188 | return getDeviceIdWithFeature(callingPackage, null); |
| 7189 | } |
| 7190 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7191 | /** |
| 7192 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7193 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7194 | * |
| 7195 | * <p>Requires Permission: |
| 7196 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7197 | */ |
| 7198 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7199 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7200 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7201 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7202 | return null; |
| 7203 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7204 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7205 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7206 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7207 | return null; |
| 7208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7209 | |
| 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
| 7212 | return phone.getDeviceId(); |
| 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
| 7215 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7216 | } |
| 7217 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7218 | /** |
| 7219 | * {@hide} |
| 7220 | * Returns the IMS Registration Status on a particular subid |
| 7221 | * |
| 7222 | * @param subId |
| 7223 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7224 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7225 | Phone phone = getPhone(subId); |
| 7226 | if (phone != null) { |
| 7227 | return phone.isImsRegistered(); |
| 7228 | } else { |
| 7229 | return false; |
| 7230 | } |
| 7231 | } |
| 7232 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7233 | @Override |
| 7234 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | final long identity = Binder.clearCallingIdentity(); |
| 7236 | try { |
| 7237 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7238 | } finally { |
| 7239 | Binder.restoreCallingIdentity(identity); |
| 7240 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7241 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7242 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7243 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7244 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7245 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7247 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7248 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7249 | } |
| 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7259 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7260 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7261 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
| 7264 | Phone phone = getPhone(subscriptionId); |
| 7265 | if (phone == null) { |
| 7266 | return null; |
| 7267 | } |
| 7268 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7269 | } finally { |
| 7270 | Binder.restoreCallingIdentity(identity); |
| 7271 | } |
| 7272 | } |
| 7273 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7274 | /** |
| 7275 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7276 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7277 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7278 | final long identity = Binder.clearCallingIdentity(); |
| 7279 | try { |
| 7280 | Phone phone = getPhone(subId); |
| 7281 | if (phone != null) { |
| 7282 | return phone.isWifiCallingEnabled(); |
| 7283 | } else { |
| 7284 | return false; |
| 7285 | } |
| 7286 | } finally { |
| 7287 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7288 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7289 | } |
| 7290 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7291 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7292 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7293 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7294 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7295 | final long identity = Binder.clearCallingIdentity(); |
| 7296 | try { |
| 7297 | Phone phone = getPhone(subId); |
| 7298 | if (phone != null) { |
| 7299 | return phone.isVideoEnabled(); |
| 7300 | } else { |
| 7301 | return false; |
| 7302 | } |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7305 | } |
| 7306 | } |
| 7307 | |
| 7308 | /** |
| 7309 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7310 | * defined in {@link ImsRegistrationImplBase}. |
| 7311 | */ |
| 7312 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | final long identity = Binder.clearCallingIdentity(); |
| 7314 | try { |
| 7315 | Phone phone = getPhone(subId); |
| 7316 | if (phone != null) { |
| 7317 | return phone.getImsRegistrationTech(); |
| 7318 | } else { |
| 7319 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7320 | } |
| 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7323 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7324 | } |
| 7325 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7326 | @Override |
| 7327 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7328 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7329 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7330 | return; |
| 7331 | } |
| 7332 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7334 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7335 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7336 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7337 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7338 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7339 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7340 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7341 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7342 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7343 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7344 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7345 | // There has been issues when Sms raw table somehow stores orphan |
| 7346 | // fragments. They lead to garbled message when new fragments come |
| 7347 | // in and combined with those stale ones. In case this happens again, |
| 7348 | // user can reset all network settings which will clean up this table. |
| 7349 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7350 | // Clean up IMS settings as well here. |
| 7351 | int slotId = getSlotIndex(subId); |
| 7352 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7353 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7354 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7355 | |
| 7356 | // Erase modem config if erase modem on network setting is enabled. |
| 7357 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7358 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7359 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7360 | sendEraseModemConfig(getDefaultPhone()); |
| 7361 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7362 | } finally { |
| 7363 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7364 | } |
| 7365 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7366 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7367 | private void cleanUpSmsRawTable(Context context) { |
| 7368 | ContentResolver resolver = context.getContentResolver(); |
| 7369 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7370 | resolver.delete(uri, null, null); |
| 7371 | } |
| 7372 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7373 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7374 | public String getSimLocaleForSubscriber(int subId) { |
| 7375 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7376 | final Phone phone = getPhone(subId); |
| 7377 | if (phone == null) { |
| 7378 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7379 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7380 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | final long identity = Binder.clearCallingIdentity(); |
| 7382 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7383 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7384 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7385 | if (info == null) { |
| 7386 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7387 | return null; |
| 7388 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7390 | // preferences (EF-PL and EF-LI)... |
| 7391 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7393 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7394 | if (localeFromDefaultSim != null) { |
| 7395 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7396 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7397 | + localeFromDefaultSim); |
| 7398 | return localeFromDefaultSim.toLanguageTag(); |
| 7399 | } else { |
| 7400 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7401 | } |
| 7402 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7405 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7406 | // the SIM and carrier preferences does not include a country we add the country |
| 7407 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7408 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7410 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7411 | return mccLocale.toLanguageTag(); |
| 7412 | } |
| 7413 | |
| 7414 | if (DBG) log("No locale found - returning null"); |
| 7415 | return null; |
| 7416 | } finally { |
| 7417 | Binder.restoreCallingIdentity(identity); |
| 7418 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7419 | } |
| 7420 | |
| 7421 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7422 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7423 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7424 | } |
| 7425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7426 | /** |
| 7427 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7428 | */ |
| 7429 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7430 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7431 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7432 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7433 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7434 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7435 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7436 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7437 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7438 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7439 | * representing the state of the modem. |
| 7440 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7441 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7442 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7443 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7444 | */ |
| 7445 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7446 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7447 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7448 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | |
| 7450 | final long identity = Binder.clearCallingIdentity(); |
| 7451 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7452 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7455 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7456 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7457 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7458 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7459 | // less than total activity duration. |
| 7460 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7461 | if (info == null) { |
| 7462 | return false; |
| 7463 | } |
| 7464 | int activityDurationMs = |
| 7465 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7466 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7467 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7468 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7469 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7470 | } |
| 7471 | return (info.isValid() |
| 7472 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7473 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7474 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7475 | && (totalTxTimeMs <= activityDurationMs)); |
| 7476 | } |
| 7477 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7478 | /** |
| 7479 | * {@hide} |
| 7480 | * Returns the service state information on specified subscription. |
| 7481 | */ |
| 7482 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7483 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7484 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7486 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7487 | return null; |
| 7488 | } |
| 7489 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7490 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7491 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7492 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7493 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7494 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7495 | .setCallingPid(Binder.getCallingPid()) |
| 7496 | .setCallingUid(Binder.getCallingUid()) |
| 7497 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7498 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7499 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7500 | .build()); |
| 7501 | |
| 7502 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7503 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7504 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7505 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7506 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7507 | .setCallingPid(Binder.getCallingPid()) |
| 7508 | .setCallingUid(Binder.getCallingUid()) |
| 7509 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7510 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7511 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7512 | .build()); |
| 7513 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7514 | boolean hasFinePermission = |
| 7515 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7516 | boolean hasCoarsePermission = |
| 7517 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7519 | final long identity = Binder.clearCallingIdentity(); |
| 7520 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7521 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7522 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7523 | Rlog.d(LOG_TAG, |
| 7524 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7525 | return null; |
| 7526 | } |
| 7527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | final Phone phone = getPhone(subId); |
| 7529 | if (phone == null) { |
| 7530 | return null; |
| 7531 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7532 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7533 | ServiceState ss = phone.getServiceState(); |
| 7534 | |
| 7535 | // Scrub out the location info in ServiceState depending on what level of access |
| 7536 | // the caller has. |
| 7537 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7538 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7539 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
| 7542 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7543 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7544 | |
| 7545 | /** |
| 7546 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7547 | * |
| 7548 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7549 | * voicemail ringtone. |
| 7550 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7551 | * PhoneAccount. |
| 7552 | */ |
| 7553 | @Override |
| 7554 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7555 | final long identity = Binder.clearCallingIdentity(); |
| 7556 | try { |
| 7557 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7558 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7559 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7563 | } finally { |
| 7564 | Binder.restoreCallingIdentity(identity); |
| 7565 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7566 | } |
| 7567 | |
| 7568 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7569 | * Sets the per-account voicemail ringtone. |
| 7570 | * |
| 7571 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7572 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7573 | * |
| 7574 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7575 | * voicemail ringtone. |
| 7576 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7577 | * PhoneAccount. |
| 7578 | */ |
| 7579 | @Override |
| 7580 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7581 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7582 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7584 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7585 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7587 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7588 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7589 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | |
| 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7594 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7595 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | } |
| 7597 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7598 | } finally { |
| 7599 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7600 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7601 | } |
| 7602 | |
| 7603 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7604 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7605 | * |
| 7606 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7607 | * voicemail vibration setting. |
| 7608 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7609 | */ |
| 7610 | @Override |
| 7611 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7612 | final long identity = Binder.clearCallingIdentity(); |
| 7613 | try { |
| 7614 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7615 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7616 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7617 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7618 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7619 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7623 | } |
| 7624 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7625 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7626 | * Sets the per-account voicemail vibration. |
| 7627 | * |
| 7628 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7629 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7630 | * |
| 7631 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7632 | * voicemail vibration setting. |
| 7633 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7634 | * specific PhoneAccount. |
| 7635 | */ |
| 7636 | @Override |
| 7637 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7638 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7639 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7640 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7641 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7642 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7644 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7645 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7646 | } |
| 7647 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7648 | final long identity = Binder.clearCallingIdentity(); |
| 7649 | try { |
| 7650 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7651 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7652 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7653 | } |
| 7654 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7657 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7661 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7662 | * |
| 7663 | * @throws SecurityException if the caller does not have the required permission |
| 7664 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7665 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7666 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7667 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7668 | } |
| 7669 | |
| 7670 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7671 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7672 | * permission. |
| 7673 | * |
| 7674 | * @throws SecurityException if the caller does not have the required permission |
| 7675 | */ |
| 7676 | private void enforceSendSmsPermission() { |
| 7677 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7678 | } |
| 7679 | |
| 7680 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7681 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7682 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7683 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7684 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7685 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7686 | final long identity = Binder.clearCallingIdentity(); |
| 7687 | try { |
| 7688 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7689 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | if (componentName == null) { |
| 7691 | throw new SecurityException( |
| 7692 | "Caller not current active visual voicemail package[null]"); |
| 7693 | } |
| 7694 | String vvmPackage = componentName.getPackageName(); |
| 7695 | if (!callingPackage.equals(vvmPackage)) { |
| 7696 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7697 | + vvmPackage + "]"); |
| 7698 | } |
| 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7701 | } |
| 7702 | } |
| 7703 | |
| 7704 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7705 | * Return the application ID for the app type. |
| 7706 | * |
| 7707 | * @param subId the subscription ID that this request applies to. |
| 7708 | * @param appType the uicc app type. |
| 7709 | * @return Application ID for specificied app type, or null if no uicc. |
| 7710 | */ |
| 7711 | @Override |
| 7712 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7713 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7714 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7715 | |
| 7716 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7717 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7718 | if (phone == null) { |
| 7719 | return null; |
| 7720 | } |
| 7721 | String aid = null; |
| 7722 | try { |
| 7723 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7724 | .getApplicationByType(appType).getAid(); |
| 7725 | } catch (Exception e) { |
| 7726 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7727 | } |
| 7728 | return aid; |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7731 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7732 | } |
| 7733 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7734 | /** |
| 7735 | * Return the Electronic Serial Number. |
| 7736 | * |
| 7737 | * @param subId the subscription ID that this request applies to. |
| 7738 | * @return ESN or null if error. |
| 7739 | */ |
| 7740 | @Override |
| 7741 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7742 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7743 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7744 | |
| 7745 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7746 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7747 | if (phone == null) { |
| 7748 | return null; |
| 7749 | } |
| 7750 | String esn = null; |
| 7751 | try { |
| 7752 | esn = phone.getEsn(); |
| 7753 | } catch (Exception e) { |
| 7754 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7755 | } |
| 7756 | return esn; |
| 7757 | } finally { |
| 7758 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7759 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7760 | } |
| 7761 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7762 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7763 | * Return the Preferred Roaming List Version. |
| 7764 | * |
| 7765 | * @param subId the subscription ID that this request applies to. |
| 7766 | * @return PRLVersion or null if error. |
| 7767 | */ |
| 7768 | @Override |
| 7769 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7770 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7771 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | |
| 7773 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7774 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7775 | if (phone == null) { |
| 7776 | return null; |
| 7777 | } |
| 7778 | String cdmaPrlVersion = null; |
| 7779 | try { |
| 7780 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7781 | } catch (Exception e) { |
| 7782 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7783 | } |
| 7784 | return cdmaPrlVersion; |
| 7785 | } finally { |
| 7786 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7787 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7788 | } |
| 7789 | |
| 7790 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7791 | * Get snapshot of Telephony histograms |
| 7792 | * @return List of Telephony histograms |
| 7793 | * @hide |
| 7794 | */ |
| 7795 | @Override |
| 7796 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7798 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
| 7802 | return RIL.getTelephonyRILTimingHistograms(); |
| 7803 | } finally { |
| 7804 | Binder.restoreCallingIdentity(identity); |
| 7805 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7806 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7807 | |
| 7808 | /** |
| 7809 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7810 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7811 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7812 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7813 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7814 | * @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] | 7815 | */ |
| 7816 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7817 | @TelephonyManager.SetCarrierRestrictionResult |
| 7818 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7819 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7820 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7821 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7822 | if (carrierRestrictionRules == null) { |
| 7823 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7824 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7828 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7829 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7830 | } finally { |
| 7831 | Binder.restoreCallingIdentity(identity); |
| 7832 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7833 | } |
| 7834 | |
| 7835 | /** |
| 7836 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7837 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7838 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7839 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7840 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7841 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7842 | */ |
| 7843 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7844 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7845 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7846 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7847 | |
| 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7850 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7851 | if (response instanceof CarrierRestrictionRules) { |
| 7852 | return (CarrierRestrictionRules) response; |
| 7853 | } |
| 7854 | // Response is an Exception of some kind, |
| 7855 | // which is signalled to the user as a NULL retval |
| 7856 | return null; |
| 7857 | } catch (Exception e) { |
| 7858 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7859 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7860 | } finally { |
| 7861 | Binder.restoreCallingIdentity(identity); |
| 7862 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7863 | } |
| 7864 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7865 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7866 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7867 | * @param subId the subscription ID that this action applies to. |
| 7868 | * @param enabled control enable or disable radio. |
| 7869 | * {@hide} |
| 7870 | */ |
| 7871 | @Override |
| 7872 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7873 | enforceModifyPermission(); |
| 7874 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | |
| 7876 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7877 | if (phone == null) { |
| 7878 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7879 | return; |
| 7880 | } |
| 7881 | try { |
| 7882 | phone.carrierActionSetRadioEnabled(enabled); |
| 7883 | } catch (Exception e) { |
| 7884 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7885 | } finally { |
| 7886 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7887 | } |
| 7888 | } |
| 7889 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7890 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7891 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7892 | * network status based on which carrier apps could apply actions accordingly, |
| 7893 | * enable/disable default url handler for example. |
| 7894 | * |
| 7895 | * @param subId the subscription ID that this action applies to. |
| 7896 | * @param report control start/stop reporting the default network status. |
| 7897 | * {@hide} |
| 7898 | */ |
| 7899 | @Override |
| 7900 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7901 | enforceModifyPermission(); |
| 7902 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7903 | |
| 7904 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7905 | if (phone == null) { |
| 7906 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7907 | return; |
| 7908 | } |
| 7909 | try { |
| 7910 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7911 | } catch (Exception e) { |
| 7912 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 | } finally { |
| 7914 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7915 | } |
| 7916 | } |
| 7917 | |
| 7918 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7919 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7920 | * @param subId the subscription ID that this action applies to. |
| 7921 | * {@hide} |
| 7922 | */ |
| 7923 | @Override |
| 7924 | public void carrierActionResetAll(int subId) { |
| 7925 | enforceModifyPermission(); |
| 7926 | final Phone phone = getPhone(subId); |
| 7927 | if (phone == null) { |
| 7928 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7929 | return; |
| 7930 | } |
| 7931 | try { |
| 7932 | phone.carrierActionResetAll(); |
| 7933 | } catch (Exception e) { |
| 7934 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7935 | } |
| 7936 | } |
| 7937 | |
| 7938 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7939 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7940 | * bug report is being generated. |
| 7941 | */ |
| 7942 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7943 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7944 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7945 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7946 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7947 | + Binder.getCallingPid() |
| 7948 | + ", uid=" + Binder.getCallingUid() |
| 7949 | + "without permission " |
| 7950 | + android.Manifest.permission.DUMP); |
| 7951 | return; |
| 7952 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7953 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7954 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7955 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7956 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7957 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7958 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7959 | @NonNull String[] args) { |
| 7960 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7961 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7962 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7963 | } |
| 7964 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7965 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7966 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7967 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7968 | * @param reason the reason the data enable change is taking place |
| 7969 | * @param enabled True if enabling the data, otherwise disabling. |
| 7970 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7971 | */ |
| 7972 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7973 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7974 | boolean enabled) { |
| 7975 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7976 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7977 | try { |
| 7978 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7979 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7980 | } catch (SecurityException se) { |
| 7981 | enforceModifyPermission(); |
| 7982 | } |
| 7983 | } else { |
| 7984 | enforceModifyPermission(); |
| 7985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7986 | |
| 7987 | final long identity = Binder.clearCallingIdentity(); |
| 7988 | try { |
| 7989 | Phone phone = getPhone(subId); |
| 7990 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7991 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7992 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7993 | } else { |
| 7994 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7995 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | } |
| 7997 | } finally { |
| 7998 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7999 | } |
| 8000 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8001 | |
| 8002 | /** |
| 8003 | * Get Client request stats |
| 8004 | * @return List of Client Request Stats |
| 8005 | * @hide |
| 8006 | */ |
| 8007 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8008 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8009 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8011 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8012 | return null; |
| 8013 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8014 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8016 | final long identity = Binder.clearCallingIdentity(); |
| 8017 | try { |
| 8018 | if (phone != null) { |
| 8019 | return phone.getClientRequestStats(); |
| 8020 | } |
| 8021 | |
| 8022 | return null; |
| 8023 | } finally { |
| 8024 | Binder.restoreCallingIdentity(identity); |
| 8025 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8026 | } |
| 8027 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8028 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8029 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8030 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8031 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8032 | |
| 8033 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8034 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8035 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8036 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8037 | * @param state State of SIM (power down, power up, pass through) |
| 8038 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8039 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8040 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8041 | * |
| 8042 | **/ |
| 8043 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8044 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8045 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8046 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8047 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8048 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | final long identity = Binder.clearCallingIdentity(); |
| 8051 | try { |
| 8052 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8053 | phone.setSimPowerState(state, null, workSource); |
| 8054 | } |
| 8055 | } finally { |
| 8056 | Binder.restoreCallingIdentity(identity); |
| 8057 | } |
| 8058 | } |
| 8059 | |
| 8060 | /** |
| 8061 | * Set SIM card power state. |
| 8062 | * |
| 8063 | * @param slotIndex SIM slot id. |
| 8064 | * @param state State of SIM (power down, power up, pass through) |
| 8065 | * @param callback callback to trigger after success or failure |
| 8066 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8067 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8068 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8069 | * |
| 8070 | **/ |
| 8071 | @Override |
| 8072 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8073 | IIntegerConsumer callback) { |
| 8074 | enforceModifyPermission(); |
| 8075 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8076 | |
| 8077 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8078 | |
| 8079 | final long identity = Binder.clearCallingIdentity(); |
| 8080 | try { |
| 8081 | if (phone != null) { |
| 8082 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8083 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | } |
| 8085 | } finally { |
| 8086 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8087 | } |
| 8088 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8089 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8090 | private boolean isUssdApiAllowed(int subId) { |
| 8091 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8092 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8093 | if (configManager == null) { |
| 8094 | return false; |
| 8095 | } |
| 8096 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8097 | if (pb == null) { |
| 8098 | return false; |
| 8099 | } |
| 8100 | return pb.getBoolean( |
| 8101 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8102 | } |
| 8103 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8104 | /** |
| 8105 | * Check if phone is in emergency callback mode |
| 8106 | * @return true if phone is in emergency callback mode |
| 8107 | * @param subId sub id |
| 8108 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8109 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8110 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8111 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8112 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | |
| 8114 | final long identity = Binder.clearCallingIdentity(); |
| 8115 | try { |
| 8116 | if (phone != null) { |
| 8117 | return phone.isInEcm(); |
| 8118 | } else { |
| 8119 | return false; |
| 8120 | } |
| 8121 | } finally { |
| 8122 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8123 | } |
| 8124 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8125 | |
| 8126 | /** |
| 8127 | * Get the current signal strength information for the given subscription. |
| 8128 | * Because this information is not updated when the device is in a low power state |
| 8129 | * it should not be relied-upon to be current. |
| 8130 | * @param subId Subscription index |
| 8131 | * @return the most recent cached signal strength info from the modem |
| 8132 | */ |
| 8133 | @Override |
| 8134 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | Phone p = getPhone(subId); |
| 8138 | if (p == null) { |
| 8139 | return null; |
| 8140 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8141 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | return p.getSignalStrength(); |
| 8143 | } finally { |
| 8144 | Binder.restoreCallingIdentity(identity); |
| 8145 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8146 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8147 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8148 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8149 | * Get the current modem radio state for the given slot. |
| 8150 | * @param slotIndex slot index. |
| 8151 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8152 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8153 | * @return the current radio power state from the modem |
| 8154 | */ |
| 8155 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8156 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8157 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8158 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8159 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8160 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8161 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8162 | } |
| 8163 | |
| 8164 | final long identity = Binder.clearCallingIdentity(); |
| 8165 | try { |
| 8166 | return phone.getRadioPowerState(); |
| 8167 | } finally { |
| 8168 | Binder.restoreCallingIdentity(identity); |
| 8169 | } |
| 8170 | } |
| 8171 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8172 | } |
| 8173 | |
| 8174 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8175 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8176 | * |
| 8177 | * <p>Requires one of the following permissions: |
| 8178 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8179 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8180 | * privileges. |
| 8181 | * |
| 8182 | * @param subId subscription id |
| 8183 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8184 | * {@code false}. |
| 8185 | */ |
| 8186 | @Override |
| 8187 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8188 | try { |
| 8189 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8190 | null); |
| 8191 | } catch (Exception e) { |
| 8192 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8193 | mApp, subId, "isDataRoamingEnabled"); |
| 8194 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8195 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8196 | boolean isEnabled = false; |
| 8197 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8198 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8199 | Phone phone = getPhone(subId); |
| 8200 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8201 | } finally { |
| 8202 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8203 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8204 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | |
| 8208 | /** |
| 8209 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8210 | * |
| 8211 | * <p> Requires permission: |
| 8212 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8213 | * privileges. |
| 8214 | * |
| 8215 | * @param subId subscription id |
| 8216 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8217 | */ |
| 8218 | @Override |
| 8219 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8221 | mApp, subId, "setDataRoamingEnabled"); |
| 8222 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8223 | final long identity = Binder.clearCallingIdentity(); |
| 8224 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8225 | Phone phone = getPhone(subId); |
| 8226 | if (phone != null) { |
| 8227 | phone.setDataRoamingEnabled(isEnabled); |
| 8228 | } |
| 8229 | } finally { |
| 8230 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8231 | } |
| 8232 | } |
| 8233 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8234 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8235 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8236 | TelephonyPermissions |
| 8237 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8238 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8239 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8240 | boolean isAllowed = true; |
| 8241 | final long identity = Binder.clearCallingIdentity(); |
| 8242 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8243 | Phone phone = getPhone(subId); |
| 8244 | if (phone != null) { |
| 8245 | isAllowed = phone.isCspPlmnEnabled(); |
| 8246 | } |
| 8247 | } finally { |
| 8248 | Binder.restoreCallingIdentity(identity); |
| 8249 | } |
| 8250 | return isAllowed; |
| 8251 | } |
| 8252 | |
| 8253 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8254 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8255 | // Verify that tha callingPackage belongs to the calling UID |
| 8256 | mApp.getSystemService(AppOpsManager.class) |
| 8257 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8258 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8259 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8260 | try { |
| 8261 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8262 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8263 | } catch (SecurityException e) { |
| 8264 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8265 | // has carrier privileges on an active UICC |
| 8266 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8267 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8268 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8269 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8270 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8271 | |
| 8272 | final long identity = Binder.clearCallingIdentity(); |
| 8273 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8274 | UiccController uiccController = UiccController.getInstance(); |
| 8275 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8276 | if (hasReadPermission) { |
| 8277 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8278 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8279 | |
| 8280 | // Remove private info if the caller doesn't have access |
| 8281 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8282 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8283 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8284 | // is available |
| 8285 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8286 | if (card == null || card.getUiccProfile() == null) { |
| 8287 | // assume no access if the card or profile is unavailable |
| 8288 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8289 | continue; |
| 8290 | } |
| 8291 | UiccProfile profile = card.getUiccProfile(); |
| 8292 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8293 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8294 | filteredInfos.add(cardInfo); |
| 8295 | } else { |
| 8296 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8297 | } |
| 8298 | } |
| 8299 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8300 | } finally { |
| 8301 | Binder.restoreCallingIdentity(identity); |
| 8302 | } |
| 8303 | } |
| 8304 | |
| 8305 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8306 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8307 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8308 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8309 | final long identity = Binder.clearCallingIdentity(); |
| 8310 | try { |
| 8311 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8312 | if (slots == null) { |
| 8313 | Rlog.i(LOG_TAG, "slots is null."); |
| 8314 | return null; |
| 8315 | } |
| 8316 | |
| 8317 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8318 | for (int i = 0; i < slots.length; i++) { |
| 8319 | UiccSlot slot = slots[i]; |
| 8320 | if (slot == null) { |
| 8321 | continue; |
| 8322 | } |
| 8323 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8324 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8325 | UiccCard card = slot.getUiccCard(); |
| 8326 | if (card != null) { |
| 8327 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8328 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8329 | cardId = slot.getEid(); |
| 8330 | if (TextUtils.isEmpty(cardId)) { |
| 8331 | cardId = slot.getIccId(); |
| 8332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | } |
| 8334 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8335 | if (cardId != null) { |
| 8336 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8337 | // if cardId is an EID, it's all digits so this is fine |
| 8338 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8339 | } |
| 8340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8341 | int cardState = 0; |
| 8342 | switch (slot.getCardState()) { |
| 8343 | case CARDSTATE_ABSENT: |
| 8344 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8345 | break; |
| 8346 | case CARDSTATE_PRESENT: |
| 8347 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8348 | break; |
| 8349 | case CARDSTATE_ERROR: |
| 8350 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8351 | break; |
| 8352 | case CARDSTATE_RESTRICTED: |
| 8353 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8354 | break; |
| 8355 | default: |
| 8356 | break; |
| 8357 | |
| 8358 | } |
| 8359 | |
| 8360 | infos[i] = new UiccSlotInfo( |
| 8361 | slot.isActive(), |
| 8362 | slot.isEuicc(), |
| 8363 | cardId, |
| 8364 | cardState, |
| 8365 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8366 | slot.isExtendedApduSupported(), |
| 8367 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8368 | } |
| 8369 | return infos; |
| 8370 | } finally { |
| 8371 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8372 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | @Override |
| 8376 | public boolean switchSlots(int[] physicalSlots) { |
| 8377 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8378 | |
| 8379 | final long identity = Binder.clearCallingIdentity(); |
| 8380 | try { |
| 8381 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8385 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8386 | |
| 8387 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8388 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8389 | final long identity = Binder.clearCallingIdentity(); |
| 8390 | try { |
| 8391 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8392 | } finally { |
| 8393 | Binder.restoreCallingIdentity(identity); |
| 8394 | } |
| 8395 | } |
| 8396 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8397 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8398 | * A test API to reload the UICC profile. |
| 8399 | * |
| 8400 | * <p>Requires that the calling app has permission |
| 8401 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8402 | * @hide |
| 8403 | */ |
| 8404 | @Override |
| 8405 | public void refreshUiccProfile(int subId) { |
| 8406 | enforceModifyPermission(); |
| 8407 | |
| 8408 | final long identity = Binder.clearCallingIdentity(); |
| 8409 | try { |
| 8410 | Phone phone = getPhone(subId); |
| 8411 | if (phone == null) { |
| 8412 | return; |
| 8413 | } |
| 8414 | UiccCard uiccCard = phone.getUiccCard(); |
| 8415 | if (uiccCard == null) { |
| 8416 | return; |
| 8417 | } |
| 8418 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8419 | if (uiccProfile == null) { |
| 8420 | return; |
| 8421 | } |
| 8422 | uiccProfile.refresh(); |
| 8423 | } finally { |
| 8424 | Binder.restoreCallingIdentity(identity); |
| 8425 | } |
| 8426 | } |
| 8427 | |
| 8428 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8429 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8430 | */ |
| 8431 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8432 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8433 | } |
| 8434 | |
| 8435 | /** |
| 8436 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8437 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8438 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8439 | */ |
| 8440 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8441 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8442 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8443 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8444 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8445 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8446 | return isDataRoamingEnabled; |
| 8447 | } |
| 8448 | |
| 8449 | /** |
| 8450 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8451 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8452 | */ |
| 8453 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8454 | List<Integer> list = TelephonyProperties.default_network(); |
| 8455 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8456 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8457 | return list.get(phoneId); |
| 8458 | } |
| 8459 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8460 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8461 | |
| 8462 | @Override |
| 8463 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8464 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8465 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8466 | |
| 8467 | final long identity = Binder.clearCallingIdentity(); |
| 8468 | try { |
| 8469 | final Phone phone = getPhone(subId); |
| 8470 | if (phone == null) { |
| 8471 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8472 | return; |
| 8473 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8474 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8475 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8476 | if (carrierPrivilegeRules == null) { |
| 8477 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8478 | } else { |
| 8479 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8480 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8483 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8484 | } |
| 8485 | |
| 8486 | @Override |
| 8487 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8488 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | final Phone phone = getPhone(subId); |
| 8493 | if (phone == null) { |
| 8494 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8495 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8496 | } |
| 8497 | return phone.getCarrierIdListVersion(); |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8500 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8501 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8502 | |
| 8503 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8504 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8505 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8506 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8507 | mApp, subId, callingPackage, callingFeatureId, |
| 8508 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8509 | return -1; |
| 8510 | } |
| 8511 | |
| 8512 | final long identity = Binder.clearCallingIdentity(); |
| 8513 | try { |
| 8514 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8515 | } finally { |
| 8516 | Binder.restoreCallingIdentity(identity); |
| 8517 | } |
| 8518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8519 | |
| 8520 | @Override |
| 8521 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8522 | TelephonyPermissions |
| 8523 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8524 | mApp, subId, "getCdmaRoamingMode"); |
| 8525 | |
| 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
| 8528 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
| 8532 | } |
| 8533 | |
| 8534 | @Override |
| 8535 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8537 | mApp, subId, "setCdmaRoamingMode"); |
| 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
| 8540 | try { |
| 8541 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
| 8545 | } |
| 8546 | |
| 8547 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8548 | public int getCdmaSubscriptionMode(int subId) { |
| 8549 | TelephonyPermissions |
| 8550 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8551 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8552 | |
| 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
| 8555 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8556 | } finally { |
| 8557 | Binder.restoreCallingIdentity(identity); |
| 8558 | } |
| 8559 | } |
| 8560 | |
| 8561 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8562 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8564 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
| 8571 | } |
| 8572 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8573 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8574 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8575 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8576 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8577 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8578 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8579 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8580 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8581 | } |
| 8582 | final long identity = Binder.clearCallingIdentity(); |
| 8583 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8584 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8585 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8586 | if (phone.getEmergencyNumberTracker() != null |
| 8587 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8588 | emergencyNumberListInternal.put( |
| 8589 | phone.getSubId(), |
| 8590 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8591 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8592 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8593 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8594 | } finally { |
| 8595 | Binder.restoreCallingIdentity(identity); |
| 8596 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8597 | } |
| 8598 | |
| 8599 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8600 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8601 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8602 | if (!exactMatch) { |
| 8603 | TelephonyPermissions |
| 8604 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8605 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8606 | } |
| 8607 | final long identity = Binder.clearCallingIdentity(); |
| 8608 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8609 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8610 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8611 | && phone.getEmergencyNumberTracker() |
| 8612 | .isEmergencyNumber(number, exactMatch)) { |
| 8613 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8614 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8615 | } |
| 8616 | return false; |
| 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
| 8619 | } |
| 8620 | } |
| 8621 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8622 | /** |
| 8623 | * Update emergency number list for test mode. |
| 8624 | */ |
| 8625 | @Override |
| 8626 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8627 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8628 | "updateEmergencyNumberListTestMode"); |
| 8629 | |
| 8630 | final long identity = Binder.clearCallingIdentity(); |
| 8631 | try { |
| 8632 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8633 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8634 | if (tracker != null) { |
| 8635 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8636 | } |
| 8637 | } |
| 8638 | } finally { |
| 8639 | Binder.restoreCallingIdentity(identity); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | /** |
| 8644 | * Get the full emergency number list for test mode. |
| 8645 | */ |
| 8646 | @Override |
| 8647 | public List<String> getEmergencyNumberListTestMode() { |
| 8648 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8649 | "getEmergencyNumberListTestMode"); |
| 8650 | |
| 8651 | final long identity = Binder.clearCallingIdentity(); |
| 8652 | try { |
| 8653 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8654 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8655 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8656 | if (tracker != null) { |
| 8657 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8658 | emergencyNumbers.add(num.getNumber()); |
| 8659 | } |
| 8660 | } |
| 8661 | } |
| 8662 | return new ArrayList<>(emergencyNumbers); |
| 8663 | } finally { |
| 8664 | Binder.restoreCallingIdentity(identity); |
| 8665 | } |
| 8666 | } |
| 8667 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8668 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8669 | public int getEmergencyNumberDbVersion(int subId) { |
| 8670 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8671 | |
| 8672 | final long identity = Binder.clearCallingIdentity(); |
| 8673 | try { |
| 8674 | final Phone phone = getPhone(subId); |
| 8675 | if (phone == null) { |
| 8676 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8677 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8678 | } |
| 8679 | return phone.getEmergencyNumberDbVersion(); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
| 8684 | |
| 8685 | @Override |
| 8686 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8687 | enforceModifyPermission(); |
| 8688 | |
| 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | try { |
| 8691 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8692 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8693 | if (tracker != null) { |
| 8694 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8695 | } |
| 8696 | } |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
| 8700 | } |
| 8701 | |
| 8702 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8703 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8704 | enforceActiveEmergencySessionPermission(); |
| 8705 | |
| 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8709 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8710 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8711 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8712 | } |
| 8713 | } |
| 8714 | } finally { |
| 8715 | Binder.restoreCallingIdentity(identity); |
| 8716 | } |
| 8717 | } |
| 8718 | |
| 8719 | @Override |
| 8720 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8721 | enforceActiveEmergencySessionPermission(); |
| 8722 | |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8726 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8727 | if (tracker != null) { |
| 8728 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8729 | } |
| 8730 | } |
| 8731 | } finally { |
| 8732 | Binder.restoreCallingIdentity(identity); |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8737 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8738 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8739 | Phone phone = getPhone(subId); |
| 8740 | if (phone == null) { |
| 8741 | return null; |
| 8742 | } |
| 8743 | final long identity = Binder.clearCallingIdentity(); |
| 8744 | try { |
| 8745 | UiccProfile profile = UiccController.getInstance() |
| 8746 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8747 | if (profile != null) { |
| 8748 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8749 | } |
| 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
| 8753 | return null; |
| 8754 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8755 | |
| 8756 | /** |
| 8757 | * Enable or disable a modem stack. |
| 8758 | */ |
| 8759 | @Override |
| 8760 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8761 | enforceModifyPermission(); |
| 8762 | |
| 8763 | final long identity = Binder.clearCallingIdentity(); |
| 8764 | try { |
| 8765 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8766 | if (phone == null) { |
| 8767 | return false; |
| 8768 | } else { |
| 8769 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8770 | } |
| 8771 | } finally { |
| 8772 | Binder.restoreCallingIdentity(identity); |
| 8773 | } |
| 8774 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8775 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8776 | /** |
| 8777 | * Whether a modem stack is enabled or not. |
| 8778 | */ |
| 8779 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8780 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8781 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8783 | if (phone == null) return false; |
| 8784 | |
| 8785 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8786 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8787 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8788 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8789 | } |
| 8790 | |
| 8791 | final long identity = Binder.clearCallingIdentity(); |
| 8792 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8793 | try { |
| 8794 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8795 | } catch (NoSuchElementException ex) { |
| 8796 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8797 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8798 | } finally { |
| 8799 | Binder.restoreCallingIdentity(identity); |
| 8800 | } |
| 8801 | } |
| 8802 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8803 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8804 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8805 | enforceModifyPermission(); |
| 8806 | |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8810 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8811 | .commit(); |
| 8812 | } finally { |
| 8813 | Binder.restoreCallingIdentity(identity); |
| 8814 | } |
| 8815 | } |
| 8816 | |
| 8817 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8818 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8819 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8820 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8821 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8822 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8823 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8824 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8825 | |
| 8826 | final long identity = Binder.clearCallingIdentity(); |
| 8827 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8828 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8829 | } finally { |
| 8830 | Binder.restoreCallingIdentity(identity); |
| 8831 | } |
| 8832 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8833 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8834 | @TelephonyManager.IsMultiSimSupportedResult |
| 8835 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8836 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8837 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8838 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8839 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8840 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8841 | } |
| 8842 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8843 | // supported by the modem, indicate that it is restricted. |
| 8844 | PhoneCapability staticCapability = |
| 8845 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8846 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8847 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8848 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8849 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8850 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8851 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8852 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8853 | } |
| 8854 | // Check if support of multiple SIMs is restricted by carrier |
| 8855 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8856 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8857 | } |
| 8858 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8859 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8860 | } |
| 8861 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8862 | /** |
| 8863 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8864 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8865 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8866 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8867 | * @param numOfSims number of active sims we want to switch to |
| 8868 | */ |
| 8869 | @Override |
| 8870 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8871 | if (numOfSims == 1) { |
| 8872 | enforceModifyPermission(); |
| 8873 | } else { |
| 8874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8875 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8876 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8877 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8878 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8879 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8880 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8881 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8882 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8883 | return; |
| 8884 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8885 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8886 | } finally { |
| 8887 | Binder.restoreCallingIdentity(identity); |
| 8888 | } |
| 8889 | } |
| 8890 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8891 | @Override |
| 8892 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8893 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8894 | Phone phone = getPhone(subId); |
| 8895 | if (phone == null) { |
| 8896 | return false; |
| 8897 | } |
| 8898 | final long identity = Binder.clearCallingIdentity(); |
| 8899 | try { |
| 8900 | UiccCard uiccCard = phone.getUiccCard(); |
| 8901 | if (uiccCard == null) { |
| 8902 | return false; |
| 8903 | } |
| 8904 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8905 | if (uiccProfile == null) { |
| 8906 | return false; |
| 8907 | } |
| 8908 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8909 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8910 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8911 | } |
| 8912 | return false; |
| 8913 | } finally { |
| 8914 | Binder.restoreCallingIdentity(identity); |
| 8915 | } |
| 8916 | } |
| 8917 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8918 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8919 | * Get whether making changes to modem configurations will trigger reboot. |
| 8920 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8921 | */ |
| 8922 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8923 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8924 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8926 | mApp, subId, callingPackage, callingFeatureId, |
| 8927 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8928 | return false; |
| 8929 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8930 | final long identity = Binder.clearCallingIdentity(); |
| 8931 | try { |
| 8932 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8933 | } finally { |
| 8934 | Binder.restoreCallingIdentity(identity); |
| 8935 | } |
| 8936 | } |
| 8937 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8938 | private void updateModemStateMetrics() { |
| 8939 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8940 | // TODO: check the state for each modem if the api is ready. |
| 8941 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8942 | } |
| 8943 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8944 | @Override |
| 8945 | public int[] getSlotsMapping() { |
| 8946 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8947 | |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8951 | // All logical slots should have a mapping to a physical slot. |
| 8952 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8953 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8954 | for (int i = 0; i < slotInfos.length; i++) { |
| 8955 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8956 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8957 | } |
| 8958 | } |
| 8959 | return logicalSlotsMapping; |
| 8960 | } finally { |
| 8961 | Binder.restoreCallingIdentity(identity); |
| 8962 | } |
| 8963 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8964 | |
| 8965 | /** |
| 8966 | * Get the IRadio HAL Version |
| 8967 | */ |
| 8968 | @Override |
| 8969 | public int getRadioHalVersion() { |
| 8970 | Phone phone = getDefaultPhone(); |
| 8971 | if (phone == null) return -1; |
| 8972 | HalVersion hv = phone.getHalVersion(); |
| 8973 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8974 | return hv.major * 100 + hv.minor; |
| 8975 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8976 | |
| 8977 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8978 | * Get the current calling package name. |
| 8979 | * @return the current calling package name |
| 8980 | */ |
| 8981 | @Override |
| 8982 | public String getCurrentPackageName() { |
| 8983 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8984 | } |
| 8985 | |
| 8986 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8987 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8988 | * corresponding network requests on a subId. |
| 8989 | * |
| 8990 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8991 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8992 | * 2) APN is un-metered for this subscription, or |
| 8993 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8994 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8995 | * |
| 8996 | * @return whether data is allowed for a apn type. |
| 8997 | * |
| 8998 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8999 | */ |
| 9000 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9001 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9002 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9003 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9004 | |
| 9005 | // Now that all security checks passes, perform the operation as ourselves. |
| 9006 | final long identity = Binder.clearCallingIdentity(); |
| 9007 | try { |
| 9008 | Phone phone = getPhone(subId); |
| 9009 | if (phone == null) return false; |
| 9010 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9011 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9012 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9013 | } finally { |
| 9014 | Binder.restoreCallingIdentity(identity); |
| 9015 | } |
| 9016 | } |
| 9017 | |
| 9018 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9019 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9020 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9021 | |
| 9022 | // Now that all security checks passes, perform the operation as ourselves. |
| 9023 | final long identity = Binder.clearCallingIdentity(); |
| 9024 | try { |
| 9025 | Phone phone = getPhone(subId); |
| 9026 | if (phone == null) return true; // By default return true. |
| 9027 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9028 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9029 | } finally { |
| 9030 | Binder.restoreCallingIdentity(identity); |
| 9031 | } |
| 9032 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9033 | |
| 9034 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9035 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9036 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9037 | enforceModifyPermission(); |
| 9038 | long token = Binder.clearCallingIdentity(); |
| 9039 | try { |
| 9040 | Phone phone = getPhone(subscriptionId); |
| 9041 | if (phone == null) { |
| 9042 | try { |
| 9043 | if (resultCallback != null) { |
| 9044 | resultCallback.accept(false); |
| 9045 | } |
| 9046 | } catch (RemoteException e) { |
| 9047 | // ignore |
| 9048 | } |
| 9049 | return; |
| 9050 | } |
| 9051 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9052 | Pair.create(specifiers, (x) -> { |
| 9053 | try { |
| 9054 | if (resultCallback != null) { |
| 9055 | resultCallback.accept(x); |
| 9056 | } |
| 9057 | } catch (RemoteException e) { |
| 9058 | // ignore |
| 9059 | } |
| 9060 | }); |
| 9061 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9062 | } finally { |
| 9063 | Binder.restoreCallingIdentity(token); |
| 9064 | } |
| 9065 | } |
| 9066 | |
| 9067 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9068 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9069 | TelephonyPermissions |
| 9070 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9071 | mApp, subId, "getSystemSelectionChannels"); |
| 9072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9073 | final long identity = Binder.clearCallingIdentity(); |
| 9074 | try { |
| 9075 | List<RadioAccessSpecifier> specifiers = |
| 9076 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9077 | null, subId, workSource); |
| 9078 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9079 | return specifiers; |
| 9080 | } finally { |
| 9081 | Binder.restoreCallingIdentity(identity); |
| 9082 | } |
| 9083 | } |
| 9084 | |
| 9085 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9086 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9087 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9088 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9089 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9090 | if (iccRecords == null) { |
| 9091 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9092 | return false; |
| 9093 | } |
| 9094 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9095 | } |
| 9096 | |
| 9097 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9098 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9099 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9100 | if (callingPackage == null) { |
| 9101 | callingPackage = getCurrentPackageName(); |
| 9102 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9103 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9104 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9105 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9106 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9107 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9108 | } |
| 9109 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9110 | Intent intent = new Intent(); |
| 9111 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9112 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9113 | // Bring up choose default SMS subscription dialog right now |
| 9114 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9115 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9116 | mApp.startActivity(intent); |
| 9117 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9118 | |
| 9119 | @Override |
| 9120 | public String getMmsUAProfUrl(int subId) { |
| 9121 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9122 | final long identity = Binder.clearCallingIdentity(); |
| 9123 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9124 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9125 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9126 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9127 | return carrierUAProfUrl; |
| 9128 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9129 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9130 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9131 | } finally { |
| 9132 | Binder.restoreCallingIdentity(identity); |
| 9133 | } |
| 9134 | } |
| 9135 | |
| 9136 | @Override |
| 9137 | public String getMmsUserAgent(int subId) { |
| 9138 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9139 | final long identity = Binder.clearCallingIdentity(); |
| 9140 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9141 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9142 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9143 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9144 | return carrierUserAgent; |
| 9145 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9146 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9147 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9148 | } finally { |
| 9149 | Binder.restoreCallingIdentity(identity); |
| 9150 | } |
| 9151 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9152 | |
| 9153 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9154 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9155 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9156 | |
| 9157 | final long identity = Binder.clearCallingIdentity(); |
| 9158 | try { |
| 9159 | Phone phone = getPhone(subscriptionId); |
| 9160 | if (phone == null) return false; |
| 9161 | |
| 9162 | switch (policy) { |
| 9163 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9164 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9165 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9166 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9167 | default: |
| 9168 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9169 | } |
| 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
| 9172 | } |
| 9173 | } |
| 9174 | |
| 9175 | @Override |
| 9176 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9177 | boolean enabled) { |
| 9178 | enforceModifyPermission(); |
| 9179 | |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
| 9182 | Phone phone = getPhone(subscriptionId); |
| 9183 | if (phone == null) return; |
| 9184 | |
| 9185 | switch (policy) { |
| 9186 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9187 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9188 | break; |
| 9189 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9190 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9191 | break; |
| 9192 | default: |
| 9193 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9194 | } |
| 9195 | } finally { |
| 9196 | Binder.restoreCallingIdentity(identity); |
| 9197 | } |
| 9198 | } |
| 9199 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9200 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9201 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9202 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9203 | * otherwise. |
| 9204 | */ |
| 9205 | @Override |
| 9206 | public void setCepEnabled(boolean isCepEnabled) { |
| 9207 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9208 | |
| 9209 | final long identity = Binder.clearCallingIdentity(); |
| 9210 | try { |
| 9211 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9212 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9213 | Phone defaultPhone = phone.getImsPhone(); |
| 9214 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9215 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9216 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9217 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9218 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9219 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9220 | + imsPhone.getMsisdn()); |
| 9221 | } |
| 9222 | } |
| 9223 | } finally { |
| 9224 | Binder.restoreCallingIdentity(identity); |
| 9225 | } |
| 9226 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9227 | |
| 9228 | /** |
| 9229 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9230 | * |
| 9231 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9232 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9233 | * before being read. |
| 9234 | */ |
| 9235 | @Override |
| 9236 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9237 | isCompressed) { |
| 9238 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9239 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9240 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9241 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9242 | } |
| 9243 | if (!isImsAvailableOnDevice()) { |
| 9244 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9245 | "IMS not available on device."); |
| 9246 | } |
| 9247 | |
| 9248 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9249 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9250 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9251 | } finally { |
| 9252 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9253 | } |
| 9254 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9255 | |
| 9256 | @Override |
| 9257 | public boolean isIccLockEnabled(int subId) { |
| 9258 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9259 | |
| 9260 | // Now that all security checks passes, perform the operation as ourselves. |
| 9261 | final long identity = Binder.clearCallingIdentity(); |
| 9262 | try { |
| 9263 | Phone phone = getPhone(subId); |
| 9264 | if (phone != null && phone.getIccCard() != null) { |
| 9265 | return phone.getIccCard().getIccLockEnabled(); |
| 9266 | } else { |
| 9267 | return false; |
| 9268 | } |
| 9269 | } finally { |
| 9270 | Binder.restoreCallingIdentity(identity); |
| 9271 | } |
| 9272 | } |
| 9273 | |
| 9274 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9275 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9276 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9277 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9278 | * three cases: |
| 9279 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9280 | * successfully. |
| 9281 | * - Positive number and zero for remaining password attempts. |
| 9282 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9283 | * |
| 9284 | */ |
| 9285 | @Override |
| 9286 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9287 | enforceModifyPermission(); |
| 9288 | |
| 9289 | Phone phone = getPhone(subId); |
| 9290 | if (phone == null) { |
| 9291 | return 0; |
| 9292 | } |
| 9293 | // Now that all security checks passes, perform the operation as ourselves. |
| 9294 | final long identity = Binder.clearCallingIdentity(); |
| 9295 | try { |
| 9296 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9297 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9298 | return attemptsRemaining; |
| 9299 | |
| 9300 | } catch (Exception e) { |
| 9301 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | return 0; |
| 9306 | } |
| 9307 | |
| 9308 | /** |
| 9309 | * Change the ICC password used in ICC pin lock. |
| 9310 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9311 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9312 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9313 | * - Positive number and zero for remaining password attempts. |
| 9314 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9315 | * |
| 9316 | */ |
| 9317 | @Override |
| 9318 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9319 | enforceModifyPermission(); |
| 9320 | |
| 9321 | Phone phone = getPhone(subId); |
| 9322 | if (phone == null) { |
| 9323 | return 0; |
| 9324 | } |
| 9325 | // Now that all security checks passes, perform the operation as ourselves. |
| 9326 | final long identity = Binder.clearCallingIdentity(); |
| 9327 | try { |
| 9328 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9329 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9330 | return attemptsRemaining; |
| 9331 | |
| 9332 | } catch (Exception e) { |
| 9333 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9334 | } finally { |
| 9335 | Binder.restoreCallingIdentity(identity); |
| 9336 | } |
| 9337 | return 0; |
| 9338 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9339 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9340 | /** |
| 9341 | * Request for receiving user activity notification |
| 9342 | */ |
| 9343 | @Override |
| 9344 | public void requestUserActivityNotification() { |
| 9345 | if (!mNotifyUserActivity.get() |
| 9346 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9347 | mNotifyUserActivity.set(true); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | /** |
| 9352 | * Called when userActivity is signalled in the power manager. |
| 9353 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9354 | */ |
| 9355 | @Override |
| 9356 | public void userActivity() { |
| 9357 | // *************************************** |
| 9358 | // * Inherited from PhoneWindowManager * |
| 9359 | // *************************************** |
| 9360 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9361 | // WITH ITS LOCKS HELD. |
| 9362 | // |
| 9363 | // This code must be VERY careful about the locks |
| 9364 | // it acquires. |
| 9365 | // In fact, the current code acquires way too many, |
| 9366 | // and probably has lurking deadlocks. |
| 9367 | |
| 9368 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9369 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9370 | } |
| 9371 | |
| 9372 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9373 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9374 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9375 | } |
| 9376 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9377 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9378 | @Override |
| 9379 | public boolean canConnectTo5GInDsdsMode() { |
| 9380 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9381 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9382 | |
| 9383 | @Override |
| 9384 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9385 | String callingFeatureId) { |
| 9386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9387 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9388 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9389 | } |
| 9390 | |
| 9391 | Phone phone = getPhone(subId); |
| 9392 | if (phone == null) { |
| 9393 | throw new RuntimeException("phone is not available"); |
| 9394 | } |
| 9395 | // Now that all security checks passes, perform the operation as ourselves. |
| 9396 | final long identity = Binder.clearCallingIdentity(); |
| 9397 | try { |
| 9398 | return phone.getEquivalentHomePlmns(); |
| 9399 | } finally { |
| 9400 | Binder.restoreCallingIdentity(identity); |
| 9401 | } |
| 9402 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9403 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9404 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9405 | public boolean isRadioInterfaceCapabilitySupported( |
| 9406 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9407 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9408 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9409 | if (radioInterfaceCapabilities == null) { |
| 9410 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9411 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9412 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9413 | } |
| 9414 | } |
| 9415 | |
| 9416 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9417 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9418 | UaSecurityProtocolIdentifier securityProtocol, |
| 9419 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9420 | throws RemoteException { |
| 9421 | enforceModifyPermission(); |
| 9422 | if (DBG) { |
| 9423 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9424 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9425 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9426 | } |
| 9427 | |
| 9428 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9429 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9430 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9431 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9432 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9433 | if (callback != null) { |
| 9434 | try { |
| 9435 | callback.onAuthenticationFailure( |
| 9436 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9437 | } catch (RemoteException exception) { |
| 9438 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9439 | } |
| 9440 | return; |
| 9441 | } |
| 9442 | } |
| 9443 | |
| 9444 | final long token = Binder.clearCallingIdentity(); |
| 9445 | try { |
| 9446 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9447 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9448 | forceBootStrapping, callback)); |
| 9449 | } finally { |
| 9450 | Binder.restoreCallingIdentity(token); |
| 9451 | } |
| 9452 | } |
| 9453 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9454 | /** |
| 9455 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9456 | * requested radio power state will actually be set. See {@link |
| 9457 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9458 | * |
| 9459 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9460 | * @param enable {@code true} if trying to turn radio on. |
| 9461 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9462 | * false}. |
| 9463 | */ |
| 9464 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9465 | Phone phone = getPhone(subId); |
| 9466 | if (phone != null) { |
| 9467 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9468 | return true; |
| 9469 | } |
| 9470 | return false; |
| 9471 | } |
| 9472 | |
| 9473 | private int handleDataThrottlingRequest(int subId, |
| 9474 | DataThrottlingRequest dataThrottlingRequest) { |
| 9475 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9476 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9477 | if (!setRadioPowerForThermal(subId, true)) { |
| 9478 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9479 | } |
| 9480 | |
| 9481 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9482 | |
| 9483 | int thermalMitigationResult = |
| 9484 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9485 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9486 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9487 | } |
| 9488 | return thermalMitigationResult; |
| 9489 | } |
| 9490 | |
| 9491 | /** |
| 9492 | * Thermal mitigation request to control functionalities at modem. |
| 9493 | * |
| 9494 | * @param subId the id of the subscription. |
| 9495 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9496 | * |
| 9497 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9498 | */ |
| 9499 | @Override |
| 9500 | @ThermalMitigationResult |
| 9501 | public int sendThermalMitigationRequest( |
| 9502 | int subId, |
| 9503 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9504 | enforceModifyPermission(); |
| 9505 | |
| 9506 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9507 | final long identity = Binder.clearCallingIdentity(); |
| 9508 | |
| 9509 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9510 | try { |
| 9511 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9512 | switch (thermalMitigationAction) { |
| 9513 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9514 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9515 | handleDataThrottlingRequest(subId, |
| 9516 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9517 | break; |
| 9518 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9519 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9520 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9521 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9522 | } |
| 9523 | |
| 9524 | // Ensure that radio is on. If not able to power on due to phone being |
| 9525 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9526 | if (!setRadioPowerForThermal(subId, true)) { |
| 9527 | thermalMitigationResult = |
| 9528 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9529 | break; |
| 9530 | } |
| 9531 | |
| 9532 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9533 | false); |
| 9534 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9535 | break; |
| 9536 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9537 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9538 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9539 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9540 | } |
| 9541 | |
| 9542 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9543 | if (registry != null) { |
| 9544 | TelephonyConnectionService service = |
| 9545 | registry.getTelephonyConnectionService(); |
| 9546 | Phone phone = getPhone(subId); |
| 9547 | if (phone == null) { |
| 9548 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9549 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9550 | break; |
| 9551 | } |
| 9552 | |
| 9553 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9554 | != TelephonyManager.CALL_STATE_IDLE |
| 9555 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9556 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9557 | String errorMessage = "Phone state is not valid. call state = " |
| 9558 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9559 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9560 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9561 | errorMessage += service == null |
| 9562 | ? " TelephonyConnectionService is null" |
| 9563 | : " isEmergencyCallPending = " |
| 9564 | + service.isEmergencyCallPending(); |
| 9565 | Log.e(LOG_TAG, errorMessage); |
| 9566 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9567 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9568 | break; |
| 9569 | } |
| 9570 | } else { |
| 9571 | thermalMitigationResult = |
| 9572 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9573 | break; |
| 9574 | } |
| 9575 | |
| 9576 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9577 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9578 | if (!setRadioPowerForThermal(subId, false)) { |
| 9579 | thermalMitigationResult = |
| 9580 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9581 | break; |
| 9582 | } |
| 9583 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9584 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9585 | break; |
| 9586 | default: |
| 9587 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9588 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9589 | } |
| 9590 | } catch (IllegalArgumentException e) { |
| 9591 | throw e; |
| 9592 | } catch (Exception e) { |
| 9593 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9594 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9595 | } finally { |
| 9596 | Binder.restoreCallingIdentity(identity); |
| 9597 | } |
| 9598 | |
| 9599 | if (DBG) { |
| 9600 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9601 | + thermalMitigationResult); |
| 9602 | } |
| 9603 | |
| 9604 | return thermalMitigationResult; |
| 9605 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9606 | |
| 9607 | /** |
| 9608 | * Set the GbaService Package Name that Telephony will bind to. |
| 9609 | * |
| 9610 | * @param subId The sim that the GbaService is associated with. |
| 9611 | * @param packageName The name of the package to be replaced with. |
| 9612 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9613 | */ |
| 9614 | @Override |
| 9615 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9616 | enforceModifyPermission(); |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9621 | } finally { |
| 9622 | Binder.restoreCallingIdentity(identity); |
| 9623 | } |
| 9624 | } |
| 9625 | |
| 9626 | /** |
| 9627 | * Return the package name of the currently bound GbaService. |
| 9628 | * |
| 9629 | * @param subId The sim that the GbaService is associated with. |
| 9630 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9631 | */ |
| 9632 | @Override |
| 9633 | public String getBoundGbaService(int subId) { |
| 9634 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9635 | |
| 9636 | final long identity = Binder.clearCallingIdentity(); |
| 9637 | try { |
| 9638 | return getGbaManager(subId).getServicePackage(); |
| 9639 | } finally { |
| 9640 | Binder.restoreCallingIdentity(identity); |
| 9641 | } |
| 9642 | } |
| 9643 | |
| 9644 | /** |
| 9645 | * Set the release time for telephony to unbind GbaService. |
| 9646 | * |
| 9647 | * @param subId The sim that the GbaService is associated with. |
| 9648 | * @param interval The release time to unbind GbaService by millisecond. |
| 9649 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9650 | */ |
| 9651 | @Override |
| 9652 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9653 | enforceModifyPermission(); |
| 9654 | |
| 9655 | final long identity = Binder.clearCallingIdentity(); |
| 9656 | try { |
| 9657 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9658 | } finally { |
| 9659 | Binder.restoreCallingIdentity(identity); |
| 9660 | } |
| 9661 | } |
| 9662 | |
| 9663 | /** |
| 9664 | * Return the release time for telephony to unbind GbaService. |
| 9665 | * |
| 9666 | * @param subId The sim that the GbaService is associated with. |
| 9667 | * @return The release time to unbind GbaService by millisecond. |
| 9668 | */ |
| 9669 | @Override |
| 9670 | public int getGbaReleaseTime(int subId) { |
| 9671 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9672 | |
| 9673 | final long identity = Binder.clearCallingIdentity(); |
| 9674 | try { |
| 9675 | return getGbaManager(subId).getReleaseTime(); |
| 9676 | } finally { |
| 9677 | Binder.restoreCallingIdentity(identity); |
| 9678 | } |
| 9679 | } |
| 9680 | |
| 9681 | private GbaManager getGbaManager(int subId) { |
| 9682 | GbaManager instance = GbaManager.getInstance(subId); |
| 9683 | if (instance == null) { |
| 9684 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9685 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9686 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9687 | } |
| 9688 | return instance; |
| 9689 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9690 | |
| 9691 | /** |
| 9692 | * indicate whether the device and the carrier can support |
| 9693 | * RCS VoLTE single registration. |
| 9694 | */ |
| 9695 | @Override |
| 9696 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9697 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9698 | |
| 9699 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9700 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9701 | } |
| 9702 | |
| 9703 | final long identity = Binder.clearCallingIdentity(); |
| 9704 | try { |
| 9705 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9706 | if (rpm != null) { |
| 9707 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9708 | } |
| 9709 | return false; |
| 9710 | } finally { |
| 9711 | Binder.restoreCallingIdentity(identity); |
| 9712 | } |
| 9713 | } |
| 9714 | |
| 9715 | /** |
| 9716 | * Register RCS provisioning callback. |
| 9717 | */ |
| 9718 | @Override |
| 9719 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9720 | IRcsConfigCallback callback) { |
| 9721 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9722 | |
| 9723 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9724 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9725 | } |
| 9726 | if (!isImsAvailableOnDevice()) { |
| 9727 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9728 | "IMS not available on device."); |
| 9729 | } |
| 9730 | |
| 9731 | final long identity = Binder.clearCallingIdentity(); |
| 9732 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9733 | if (!RcsProvisioningMonitor.getInstance() |
| 9734 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9735 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9736 | "Service not available for the subscription."); |
| 9737 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9738 | } finally { |
| 9739 | Binder.restoreCallingIdentity(identity); |
| 9740 | } |
| 9741 | } |
| 9742 | |
| 9743 | /** |
| 9744 | * Unregister RCS provisioning callback. |
| 9745 | */ |
| 9746 | @Override |
| 9747 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9748 | IRcsConfigCallback callback) { |
| 9749 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9750 | |
| 9751 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9752 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9753 | } |
| 9754 | if (!isImsAvailableOnDevice()) { |
| 9755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9756 | "IMS not available on device."); |
| 9757 | } |
| 9758 | |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
| 9760 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9761 | RcsProvisioningMonitor.getInstance() |
| 9762 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9763 | } finally { |
| 9764 | Binder.restoreCallingIdentity(identity); |
| 9765 | } |
| 9766 | } |
| 9767 | |
| 9768 | /** |
| 9769 | * trigger RCS reconfiguration. |
| 9770 | */ |
| 9771 | public void triggerRcsReconfiguration(int subId) { |
| 9772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9773 | mApp, subId, "triggerRcsReconfiguration"); |
| 9774 | |
| 9775 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9776 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9777 | } |
| 9778 | if (!isImsAvailableOnDevice()) { |
| 9779 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9780 | "IMS not available on device."); |
| 9781 | } |
| 9782 | |
| 9783 | final long identity = Binder.clearCallingIdentity(); |
| 9784 | try { |
| 9785 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9786 | } finally { |
| 9787 | Binder.restoreCallingIdentity(identity); |
| 9788 | } |
| 9789 | } |
| 9790 | |
| 9791 | /** |
| 9792 | * Provide the client configuration parameters of the RCS application. |
| 9793 | */ |
| 9794 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9796 | mApp, subId, "setRcsClientConfiguration"); |
| 9797 | |
| 9798 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9799 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9800 | } |
| 9801 | if (!isImsAvailableOnDevice()) { |
| 9802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9803 | "IMS not available on device."); |
| 9804 | } |
| 9805 | |
| 9806 | final long identity = Binder.clearCallingIdentity(); |
| 9807 | |
| 9808 | try { |
| 9809 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9810 | if (configBinder == null) { |
| 9811 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9812 | } else { |
| 9813 | configBinder.setRcsClientConfiguration(rcc); |
| 9814 | } |
| 9815 | } catch (RemoteException e) { |
| 9816 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9817 | } finally { |
| 9818 | Binder.restoreCallingIdentity(identity); |
| 9819 | } |
| 9820 | } |
| 9821 | |
| 9822 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9823 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9827 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9828 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9829 | |
| 9830 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9831 | } |
| 9832 | |
| 9833 | /** |
| 9834 | * Gets the test mode for RCS VoLTE single registration. |
| 9835 | */ |
| 9836 | @Override |
| 9837 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9838 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9839 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9840 | |
| 9841 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9842 | } |
| 9843 | |
| 9844 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9845 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9846 | */ |
| 9847 | @Override |
| 9848 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9849 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9850 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9851 | enforceModifyPermission(); |
| 9852 | |
| 9853 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9854 | : Boolean.parseBoolean(enabledStr); |
| 9855 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9856 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9857 | } |
| 9858 | |
| 9859 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9860 | * Sends a device to device communication message. Only usable via shell. |
| 9861 | * @param message message to send. |
| 9862 | * @param value message value. |
| 9863 | */ |
| 9864 | @Override |
| 9865 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9866 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9867 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9868 | enforceModifyPermission(); |
| 9869 | |
| 9870 | final long identity = Binder.clearCallingIdentity(); |
| 9871 | try { |
| 9872 | TelephonyConnectionService service = |
| 9873 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9874 | if (service == null) { |
| 9875 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9876 | return; |
| 9877 | } |
| 9878 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9879 | } finally { |
| 9880 | Binder.restoreCallingIdentity(identity); |
| 9881 | } |
| 9882 | } |
| 9883 | |
| 9884 | |
| 9885 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9886 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9887 | */ |
| 9888 | @Override |
| 9889 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9890 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9891 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9892 | } |
| 9893 | |
| 9894 | /** |
| 9895 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9896 | */ |
| 9897 | @Override |
| 9898 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9899 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9900 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9901 | enforceModifyPermission(); |
| 9902 | |
| 9903 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9904 | : Boolean.parseBoolean(enabledStr); |
| 9905 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9906 | subId, enabled); |
| 9907 | } |
| 9908 | |
| 9909 | /** |
| 9910 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9911 | */ |
| 9912 | @Override |
| 9913 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9914 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9915 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9916 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9917 | |
| 9918 | /** |
| 9919 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9920 | * their mobile plan. |
| 9921 | */ |
| 9922 | @Override |
| 9923 | public String getMobileProvisioningUrl() { |
| 9924 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9925 | final long identity = Binder.clearCallingIdentity(); |
| 9926 | try { |
| 9927 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9928 | } finally { |
| 9929 | Binder.restoreCallingIdentity(identity); |
| 9930 | } |
| 9931 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9932 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9933 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9934 | * Get the EAB contact from the EAB database. |
| 9935 | */ |
| 9936 | @Override |
| 9937 | public String getContactFromEab(String contact) { |
| 9938 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9939 | enforceModifyPermission(); |
| 9940 | final long identity = Binder.clearCallingIdentity(); |
| 9941 | try { |
| 9942 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9943 | } finally { |
| 9944 | Binder.restoreCallingIdentity(identity); |
| 9945 | } |
| 9946 | } |
| 9947 | |
| 9948 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9949 | * Remove the EAB contacts from the EAB database. |
| 9950 | */ |
| 9951 | @Override |
| 9952 | public int removeContactFromEab(int subId, String contacts) { |
| 9953 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9954 | enforceModifyPermission(); |
| 9955 | final long identity = Binder.clearCallingIdentity(); |
| 9956 | try { |
| 9957 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9958 | } finally { |
| 9959 | Binder.restoreCallingIdentity(identity); |
| 9960 | } |
| 9961 | } |
| 9962 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9963 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9964 | public boolean getDeviceUceEnabled() { |
| 9965 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9966 | final long identity = Binder.clearCallingIdentity(); |
| 9967 | try { |
| 9968 | return mApp.getDeviceUceEnabled(); |
| 9969 | } finally { |
| 9970 | Binder.restoreCallingIdentity(identity); |
| 9971 | } |
| 9972 | } |
| 9973 | |
| 9974 | @Override |
| 9975 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9976 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9977 | final long identity = Binder.clearCallingIdentity(); |
| 9978 | try { |
| 9979 | mApp.setDeviceUceEnabled(isEnabled); |
| 9980 | } finally { |
| 9981 | Binder.restoreCallingIdentity(identity); |
| 9982 | } |
| 9983 | } |
| 9984 | |
| 9985 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9986 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9987 | String callingPackage) { |
| 9988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9989 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9990 | |
| 9991 | final int callingUid = Binder.getCallingUid(); |
| 9992 | // Verify that tha callingPackage belongs to the calling UID |
| 9993 | mApp.getSystemService(AppOpsManager.class) |
| 9994 | .checkPackage(callingUid, callingPackage); |
| 9995 | |
| 9996 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9997 | |
| 9998 | final long identity = Binder.clearCallingIdentity(); |
| 9999 | try { |
| 10000 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10001 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10002 | |
| 10003 | if (result instanceof IllegalStateException) { |
| 10004 | throw (IllegalStateException) result; |
| 10005 | } |
| 10006 | } finally { |
| 10007 | Binder.restoreCallingIdentity(identity); |
| 10008 | } |
| 10009 | } |
| 10010 | |
| 10011 | @Override |
| 10012 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10013 | String callingPackage) { |
| 10014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10015 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10016 | |
| 10017 | final int callingUid = Binder.getCallingUid(); |
| 10018 | // Verify that tha callingPackage belongs to the calling UID |
| 10019 | mApp.getSystemService(AppOpsManager.class) |
| 10020 | .checkPackage(callingUid, callingPackage); |
| 10021 | |
| 10022 | final long identity = Binder.clearCallingIdentity(); |
| 10023 | try { |
| 10024 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10025 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10026 | |
| 10027 | if (result instanceof IllegalStateException) { |
| 10028 | throw (IllegalStateException) result; |
| 10029 | } |
| 10030 | } finally { |
| 10031 | Binder.restoreCallingIdentity(identity); |
| 10032 | } |
| 10033 | } |
| 10034 | |
| 10035 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10036 | int callingUid) { |
| 10037 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10038 | // phone/system process do not have further restriction on request |
| 10039 | return; |
| 10040 | } |
| 10041 | |
| 10042 | // Applications has restrictions on how to use the request: |
| 10043 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10044 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10045 | // This is not system caller which has been checked above |
| 10046 | throw new IllegalArgumentException( |
| 10047 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10048 | } |
| 10049 | |
| 10050 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10051 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10052 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10053 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10054 | || info.isEnabled()) { |
| 10055 | throw new IllegalArgumentException( |
| 10056 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10057 | } |
| 10058 | |
| 10059 | // Thresholds length for each RAN need in range. This has been validated in |
| 10060 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10061 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10062 | final int[] thresholds = info.getThresholds(); |
| 10063 | Objects.requireNonNull(thresholds); |
| 10064 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10065 | || thresholds.length |
| 10066 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10067 | throw new IllegalArgumentException( |
| 10068 | "thresholds length is out of range: " + thresholds.length); |
| 10069 | } |
| 10070 | } |
| 10071 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10072 | |
| 10073 | /** |
| 10074 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10075 | * required to be done shortly after the API is invoked. |
| 10076 | */ |
| 10077 | @Override |
| 10078 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10079 | public int prepareForUnattendedReboot() { |
| 10080 | enforceRebootPermission(); |
| 10081 | |
| 10082 | final long identity = Binder.clearCallingIdentity(); |
| 10083 | try { |
| 10084 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10085 | } finally { |
| 10086 | Binder.restoreCallingIdentity(identity); |
| 10087 | } |
| 10088 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10089 | } |